File: decode_napster.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 (50 lines) | stat: -rw-r--r-- 831 bytes parent folder | download | duplicates (7)
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_napster.c
 *
 * Napster. w00w00!
 *
 * Copyright (c) 2000 Dug Song <dugsong@monkey.org>
 *
 * $Id: decode_napster.c,v 1.6 2001/03/15 08:33:01 dugsong Exp $
 */

#include "config.h"

#include <sys/types.h>

#include <stdio.h>
#include <string.h>

#include "buf.h"
#include "decode.h"

int
decode_napster(u_char *buf, int len, u_char *obuf, int olen)
{
	struct buf inbuf, outbuf;
	u_short i, type;

	buf_init(&inbuf, buf, len);
	buf_init(&outbuf, obuf, olen);

	if (buf_get(&inbuf, &i, sizeof(i)) != sizeof(i))
		return (0);

	i = pletohs(&i);

	if (buf_get(&inbuf, &type, sizeof(type)) != sizeof(type))
		return (0);

	type = pletohs(&type);

	if (type != 2 || i > buf_len(&inbuf))
		return (0);
	
	buf_put(&outbuf, buf_ptr(&inbuf), i);
	buf_put(&outbuf, "\n", 1);
	
	buf_end(&outbuf);
	
	return (buf_len(&outbuf));
}