File: decode_sniffer.c

package info (click to toggle)
dsniff 2.4b1+debian-29
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 2,020 kB
  • sloc: ansic: 10,803; sh: 152; makefile: 126
file content (53 lines) | stat: -rw-r--r-- 1,023 bytes parent folder | download | duplicates (4)
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
51
52
53
/*
 * decode_sniffer.c
 *
 * Network Associates Sniffer.
 * 
 * Copyright (c) 2000 Anonymous <nobody@localhost>
 * Copyright (c) 2000 Dug Song <dugsong@monkey.org>
 *
 * $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 <strlcat.h>
#include <strlcpy.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));
}