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