home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / w00w00 / sectools / dsniff / decode_socks.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-16  |  961 b   |  57 lines

  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.1 2000/05/16 17:31:14 dugsong Exp $
  9. */
  10.  
  11. #include <sys/types.h>
  12. #include <stdio.h>
  13. #include <string.h>
  14. #include "decode.h"
  15.  
  16. int
  17. decode_socks(u_char *buf, int len)
  18. {
  19.     u_char *p;
  20.     int i, n;
  21.     
  22.     p = buf;
  23.     
  24.     if (len < 4 || *p++ != 5)        /* SOCKS version */
  25.         return (0);
  26.     
  27.     if ((n = *p++) > len - 5)        /* nmethods */
  28.         return (0);
  29.     
  30.     for (i = 0; i < n; i++)            /* USERNAME/PASSWORD method? */
  31.         if (p[i] == 2) break;
  32.     
  33.     if (i == n) return (0);
  34.     
  35.     p += n;
  36.     if (*p++ != 1) return (0);        /* USERNAME/PASSWORD version */
  37.     
  38.     n = *p++;
  39.     if (n > len - (p - buf))
  40.         return (0);
  41.     
  42.     memmove(p - 1, p, n); p[n - 1] = '\0';
  43.     snprintf(Buf, sizeof(Buf), "%s ", p - 1);
  44.     p += n;
  45.     
  46.     n = *p++;
  47.     if (n > len - (p - buf))
  48.         return (0);
  49.     
  50.     memmove(p - 1, p, n); p[n - 1] = '\0';
  51.     strlcat(Buf, p - 1, sizeof(Buf));
  52.     strlcat(Buf, "\n", sizeof(Buf));
  53.     
  54.     return (strlen(Buf));
  55. }
  56.  
  57.