dsniff  2.4b2
About: A collection of tools for network auditing
  Fossies Dox: dsniff-2.4b2.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

decode_socks.c
Go to the documentation of this file.
1 /*
2  * decode_socks.c
3  *
4  * NEC SOCKS.
5  *
6  * Copyright (c) 2000 Dug Song <dugsong@monkey.org>
7  *
8  * $Id: decode_socks.c,v 1.4 2001/03/15 08:33:02 dugsong Exp $
9  */
10 
11 #include "config.h"
12 
13 #include <sys/types.h>
14 
15 #include <stdio.h>
16 #include <string.h>
17 
18 #include "decode.h"
19 
20 int
21 decode_socks(u_char *buf, int len, u_char *obuf, int olen)
22 {
23  u_char *p;
24  int i, n;
25 
26  p = buf;
27 
28  if (len < 4 || *p++ != 5) /* SOCKS version */
29  return (0);
30 
31  if ((n = *p++) > len - 5) /* nmethods */
32  return (0);
33 
34  for (i = 0; i < n; i++) /* USERNAME/PASSWORD method? */
35  if (p[i] == 2) break;
36 
37  if (i == n) return (0);
38 
39  p += n;
40  if (*p++ != 1) return (0); /* USERNAME/PASSWORD version */
41 
42  n = *p++;
43  if (n > len - (p - buf))
44  return (0);
45 
46  memmove(p - 1, p, n); p[n - 1] = '\0';
47  snprintf(obuf, olen, "%s ", p - 1);
48  p += n;
49 
50  n = *p++;
51  if (n > len - (p - buf))
52  return (0);
53 
54  memmove(p - 1, p, n); p[n - 1] = '\0';
55  strlcat(obuf, p - 1, olen);
56  strlcat(obuf, "\n", olen);
57 
58  return (strlen(obuf));
59 }
60 
buf
static u_char buf[BUFSIZ]
Definition: filenamesnarf.c:29
decode.h
decode_socks
int decode_socks(u_char *buf, int len, u_char *obuf, int olen)
Definition: decode_socks.c:21
buf
Definition: buf.h:14
config.h
obuf
static char obuf[4096]
Definition: trigger.c:43
strlcat
size_t strlcat(char *dst, const char *src, size_t siz)
Definition: strlcat.c:44