-
Notifications
You must be signed in to change notification settings - Fork 44
/
decode_sniffer.c
51 lines (40 loc) · 981 Bytes
/
decode_sniffer.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
* decode_sniffer.c
*
* Network Associates Sniffer.
*
* Copyright (c) 2000 Anonymous <nobody@localhost>
* Copyright (c) 2000 Dug Song <[email protected]>
*
* $Id: decode_sniffer.c,v 1.4 2001/03/15 08:33:02 dugsong Exp $
*/
#include "config.h"
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include "base64.h"
#include "decode.h"
int
decode_sniffer(u_char *buf, int len, u_char *obuf, int olen)
{
u_int i, opcode;
if (len < 36 || buf[0] != 5)
return (0);
opcode = pletohs(&buf[6]);
if (opcode == 260) {
if (buf[32] == 0)
return (strlcpy(obuf, "[]\n", olen));
}
else if (opcode == 261) {
if (pletohl(&buf[32]) == -1)
return (strlcpy(obuf, "[]\n", olen));
}
else return (0);
buf[len - 3]= '\0'; strtok(&buf[32], "\r\n");
snprintf(obuf, olen, "%s [", &buf[32]);
len = strlen(obuf);
i = base64_pton(&buf[32], &obuf[len], olen - len - 3);
obuf[len + i] = '\0';
strlcat(obuf, "]\n", olen);
return (strlen(obuf));
}