Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

packet_types.h

Go to the documentation of this file.
00001 
00002 // IP packet structures...
00003 // -----------------------
00004 // Note: All of this is hard coded little endian!
00005 
00006 
00007 typedef long n_long;
00008 typedef short n_short;
00009 typedef long n_time;
00010 
00011 
00012 struct ip
00013   {
00014     unsigned int ip_hl:4;               /* header length */
00015     unsigned int ip_v:4;                /* version */
00016     u_char ip_tos;                    /* type of service */
00017     u_short ip_len;                     /* total length */
00018     u_short ip_id;                      /* identification */
00019     u_short ip_off;                     /* fragment offset field */
00020 #define IP_RF 0x8000                    /* reserved fragment flag */
00021 #define IP_DF 0x4000                    /* dont fragment flag */
00022 #define IP_MF 0x2000                    /* more fragments flag */
00023 #define IP_OFFMASK 0x1fff               /* mask for fragmenting bits */
00024     u_char ip_ttl;                    /* time to live */
00025     u_char ip_p;                      /* protocol */
00026     u_short ip_sum;                     /* checksum */
00027     struct in_addr ip_src, ip_dst;      /* source and dest address */
00028   };
00029 
00030 #define    MAX_IPOPTLEN            40
00031 
00032 /*
00033  *      IEEE 802.3 Ethernet magic constants.  The frame sizes omit the preamble
00034  *      and FCS/CRC (frame check sequence). 
00035  */
00036 
00037 #define ETH_ALEN        6               /* Octets in one ethernet addr   */
00038 #define ETH_HLEN        14              /* Total octets in header.       */
00039 #define ETH_ZLEN        60              /* Min. octets in frame sans FCS */
00040 #define ETH_DATA_LEN    1500            /* Max. octets in payload        */
00041 #define ETH_FRAME_LEN   1514            /* Max. octets in frame sans FCS */
00042 
00043 /*
00044  *      These are the defined Ethernet Protocol ID's.
00045  */
00046 
00047 #define ETH_P_LOOP      0x0060          /* Ethernet Loopback packet     */
00048 #define ETH_P_ECHO      0x0200          /* Ethernet Echo packet         */
00049 #define ETH_P_PUP       0x0400          /* Xerox PUP packet             */
00050 #define ETH_P_IP        0x0800          /* Internet Protocol packet     */
00051 #define ETH_P_X25       0x0805          /* CCITT X.25                   */
00052 #define ETH_P_ARP       0x0806          /* Address Resolution packet    */
00053 #define ETH_P_BPQ       0x08FF          /* G8BPQ AX.25 Ethernet Packet  [ NOT AN OFFICIALLY REGISTERED ID ] */
00054 #define ETH_P_DEC       0x6000          /* DEC Assigned proto           */
00055 #define ETH_P_DNA_DL    0x6001          /* DEC DNA Dump/Load            */
00056 #define ETH_P_DNA_RC    0x6002          /* DEC DNA Remote Console       */
00057 #define ETH_P_DNA_RT    0x6003          /* DEC DNA Routing              */
00058 #define ETH_P_LAT       0x6004          /* DEC LAT                      */
00059 #define ETH_P_DIAG      0x6005          /* DEC Diagnostics              */
00060 #define ETH_P_CUST      0x6006          /* DEC Customer use             */
00061 #define ETH_P_SCA       0x6007          /* DEC Systems Comms Arch       */
00062 #define ETH_P_RARP      0x8035          /* Reverse Addr Res packet      */
00063 #define ETH_P_ATALK     0x809B          /* Appletalk DDP                */
00064 #define ETH_P_AARP      0x80F3          /* Appletalk AARP               */
00065 #define ETH_P_IPX       0x8137          /* IPX over DIX                 */
00066 #define ETH_P_IPV6      0x86DD          /* IPv6 over bluebook           */
00067 
00068 /*
00069  *      Non DIX types. Won't clash for 1500 types.
00070  */
00071  
00072 #define ETH_P_802_3     0x0001          /* Dummy type for 802.3 frames  */
00073 #define ETH_P_AX25      0x0002          /* Dummy protocol id for AX.25  */
00074 #define ETH_P_ALL       0x0003          /* Every packet (be careful!!!) */
00075 #define ETH_P_802_2     0x0004          /* 802.2 frames                 */
00076 #define ETH_P_SNAP      0x0005          /* Internal only                */
00077 #define ETH_P_DDCMP     0x0006          /* DEC DDCMP: Internal only     */
00078 #define ETH_P_WAN_PPP   0x0007          /* Dummy type for WAN PPP frames*/
00079 #define ETH_P_PPP_MP    0x0008          /* Dummy type for PPP MP frames */
00080 #define ETH_P_LOCALTALK 0x0009          /* Localtalk pseudo type        */
00081 #define ETH_P_PPPTALK   0x0010          /* Dummy type for Atalk over PPP*/
00082 #define ETH_P_TR_802_2  0x0011          /* 802.2 frames                 */
00083 
00084 struct etherproto {
00085         char *s;
00086         u_short p;
00087 };
00088 extern struct etherproto etherproto_db[];
00089 
00090 // Ethernet Header
00091 struct ether_header 
00092 {
00093         unsigned char   h_dest[ETH_ALEN];       /* destination eth addr */
00094         unsigned char   h_source[ETH_ALEN];     /* source ether addr    */
00095         unsigned short  h_proto;                /* packet type ID field */
00096 };
00097 
00098 // ARP/RARP
00099 ///////////////////////////////////////////////////////////////////////
00100 static u_char bcastaddr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
00101 
00102 /*
00103  *      This structure defines an ethernet arp header.
00104  */
00105 
00106 struct arphdr
00107 {
00108         unsigned short  ar_hrd;         /* format of hardware address   */
00109         unsigned short  ar_pro;         /* format of protocol address   */
00110         unsigned char   ar_hln;         /* length of hardware address   */
00111         unsigned char   ar_pln;         /* length of protocol address   */
00112         unsigned short  ar_op;          /* ARP opcode (command)         */
00113 };
00114 
00115 #define ARPD_UPDATE     0x01
00116 #define ARPD_LOOKUP     0x02
00117 #define ARPD_FLUSH      0x03
00118 
00119 /*#define ARPHRD_ETHER  0x01
00120 
00121 #define ARPOP_REQUEST   0x01
00122 #define ARPOP_REPLY             0x02
00123 #define ARPOP_REVREQUEST        0x03
00124 #define ARPOP_REVREPLY          0x04
00125 */
00126 /*
00127  * Ethernet Address Resolution Protocol.
00128  *
00129  * See RFC 826 for protocol description.  Structure below is adapted
00130  * to resolving internet addresses.  Field names used correspond to
00131  * RFC 826.
00132  */
00133 struct  ether_arp {
00134         struct  arphdr ea_hdr;  /* fixed-size header */
00135         u_char  arp_sha[ETH_ALEN];      /* sender hardware address */
00136         u_char  arp_spa[4];     /* sender protocol address */
00137         u_char  arp_tha[ETH_ALEN];      /* target hardware address */
00138         u_char  arp_tpa[4];     /* target protocol address */
00139 };
00140 #define arp_hrd ea_hdr.ar_hrd
00141 #define arp_pro ea_hdr.ar_pro
00142 #define arp_hln ea_hdr.ar_hln
00143 #define arp_pln ea_hdr.ar_pln
00144 #define arp_op  ea_hdr.ar_op
00145 
00146 // IP Header in Little Endian
00147 //////////////////////////////
00148 struct iphdr {
00149         u_char  ip_hl:4,                /* header length */
00150                         ip_v:4;                 /* version */
00151         u_char  ip_tos;                 /* type of service */
00152         short   ip_len;                 /* total length */
00153         u_short ip_id;                  /* identification */
00154         short   ip_off;                 /* fragment offset field */
00155 #define IP_DF 0x4000            /* dont fragment flag */
00156 #define IP_MF 0x2000            /* more fragments flag */
00157         u_char  ip_ttl;                 /* time to live */
00158         u_char  ip_p;                   /* protocol */
00159         u_short ip_sum;                 /* checksum */
00160         struct  in_addr ip_src,ip_dst;  /* source and dest address */
00161 };
00162 
00163 #define IP_MAXPACKET    65535           /* maximum packet size */
00164 
00165 // Definitions for options.
00166 #define IPOPT_COPIED(o)         ((o)&0x80)
00167 #define IPOPT_CLASS(o)          ((o)&0x60)
00168 #define IPOPT_NUMBER(o)         ((o)&0x1f)
00169 
00170 #define IPOPT_CONTROL           0x00
00171 #define IPOPT_RESERVED1         0x20
00172 #define IPOPT_DEBMEAS           0x40
00173 #define IPOPT_RESERVED2         0x60
00174 
00175 #define IPOPT_EOL       0x00        /* end of option list */
00176 #define IPOPT_NOP       0x01        /* no operation */
00177 
00178 #define IPOPT_RR        0x07        /* record packet route */
00179 #define IPOPT_TS        0x44        /* timestamp */
00180 #define IPOPT_SECURITY  0x82        /* provide s,c,h,tcc */
00181 #define IPOPT_LSRR      0x83        /* loose source route */
00182 #define IPOPT_SATID     0x88        /* satnet id */
00183 #define IPOPT_SSRR      0x89     /* strict source route */
00184 
00185 
00186 // Time stamp option structure.
00187 struct  ip_timestamp {
00188         u_char  ipt_code;               /* IPOPT_TS */
00189         u_char  ipt_len;                /* size of structure (variable) */
00190         u_char  ipt_ptr;                /* index of current entry */
00191         u_char  ipt_flg:4,              /* flags, see below */
00192                 ipt_oflw:4;                     /* overflow counter */
00193         union ipt_timestamp {
00194                 n_long  ipt_time[1];
00195                 struct  ipt_ta {
00196                         struct in_addr ipt_addr;
00197                         n_long ipt_time;
00198                 } ipt_ta[1];
00199         } ipt_timestamp;
00200 };
00201 
00202 /* flag bits for ipt_flg */
00203 #define IPOPT_TS_TSONLY         0               /* timestamps only */
00204 #define IPOPT_TS_TSANDADDR      1               /* timestamps and addresses */
00205 #define IPOPT_TS_PRESPEC        2               /* specified modules only */
00206 
00207 /* bits for security (not byte swapped) */
00208 #define IPOPT_SECUR_UNCLASS     0x0000
00209 #define IPOPT_SECUR_CONFID      0xf135
00210 #define IPOPT_SECUR_EFTO        0x789a
00211 #define IPOPT_SECUR_MMMM        0xbc4d
00212 #define IPOPT_SECUR_RESTR       0xaf13
00213 #define IPOPT_SECUR_SECRET      0xd788
00214 #define IPOPT_SECUR_TOPSECRET   0x6bc5
00215 
00216 // ICMP Header
00217 ////////////////////////////////////////////////////////////////////////
00218 struct icmphdr {
00219         u_char  icmp_type;              /* type of message, see below */
00220         u_char  icmp_code;              /* type sub code */
00221         u_short icmp_cksum;             /* ones complement cksum of struct */
00222         union {
00223                 u_char ih_pptr;                 /* ICMP_PARAMPROB */
00224                 struct in_addr ih_gwaddr;       /* ICMP_REDIRECT */
00225                 struct ih_idseq {
00226                         n_short icd_id;
00227                         n_short icd_seq;
00228                 } ih_idseq;
00229                 int ih_void;
00230         } icmp_hun;
00231 #define icmp_pptr       icmp_hun.ih_pptr
00232 #define icmp_gwaddr     icmp_hun.ih_gwaddr
00233 #define icmp_id         icmp_hun.ih_idseq.icd_id
00234 #define icmp_seq        icmp_hun.ih_idseq.icd_seq
00235 #define icmp_void       icmp_hun.ih_void
00236         union {
00237                 struct id_ts {
00238                         n_time its_otime;
00239                         n_time its_rtime;
00240                         n_time its_ttime;
00241                 } id_ts;
00242                 struct id_ip  {
00243                         struct iphdr idi_ip;
00244                         /* options and then 64 bits of data */
00245                 } id_ip;
00246                 u_long  id_mask;
00247                 char    id_data[1];
00248         } icmp_dun;
00249 #define icmp_otime      icmp_dun.id_ts.its_otime
00250 #define icmp_rtime      icmp_dun.id_ts.its_rtime
00251 #define icmp_ttime      icmp_dun.id_ts.its_ttime
00252 #define icmp_ip         icmp_dun.id_ip.idi_ip
00253 #define icmp_mask       icmp_dun.id_mask
00254 #define icmp_data       icmp_dun.id_data
00255 };
00256 
00257 /*
00258  * Lower bounds on packet lengths for various types.
00259  * For the error advice packets must first insure that the
00260  * packet is large enought to contain the returned ip header.
00261  * Only then can we do the check to see if 64 bits of packet
00262  * data have been returned, since we need to check the returned
00263  * ip header length.
00264  */
00265 #define ICMP_MINLEN     8                               /* abs minimum */
00266 #define ICMP_TSLEN      (8 + 3 * sizeof (n_time))       /* timestamp */
00267 #define ICMP_MASKLEN    12                              /* address mask */
00268 #define ICMP_ADVLENMIN  (8 + sizeof (struct ip) + 8)    /* min */
00269 #define ICMP_ADVLEN(p)  (8 + ((p)->icmp_ip.ip_hl << 2) + 8)
00270         /* N.B.: must separately check that ip_hl >= 5 */
00271 
00272 /*
00273  * Definition of type and code field values.
00274  */
00275 #define ICMP_ECHOREPLY          0               /* echo reply */
00276 
00277 /* UNREACH codes */
00278 #define ICMP_UNREACH                                    3       /* dest unreachable, codes: */ 
00279 #define ICMP_UNREACH_NET                0       /* bad net */
00280 #define ICMP_UNREACH_HOST               1       /* bad host */
00281 #define ICMP_UNREACH_PROTOCOL           2       /* bad protocol */
00282 #define ICMP_UNREACH_PORT               3       /* bad port */
00283 #define ICMP_UNREACH_NEEDFRAG           4       /* IP_DF caused drop */
00284 #define ICMP_UNREACH_SRCFAIL            5       /* src route failed */
00285 #define ICMP_UNREACH_NET_UNKNOWN        6       /* unknown net */
00286 #define ICMP_UNREACH_HOST_UNKNOWN       7       /* unknown host */
00287 #define ICMP_UNREACH_ISOLATED           8       /* src host isolated */
00288 #define ICMP_UNREACH_NET_PROHIB         9       /* net denied */
00289 #define ICMP_UNREACH_HOST_PROHIB        10      /* host denied */
00290 #define ICMP_UNREACH_TOSNET             11      /* bad tos for net */
00291 #define ICMP_UNREACH_TOSHOST            12      /* bad tos for host */
00292 #define ICMP_UNREACH_FILTER_PROHIB      13      /* admin prohib */
00293 #define ICMP_UNREACH_HOST_PRECEDENCE    14      /* host prec vio. */
00294 #define ICMP_UNREACH_PRECEDENCE_CUTOFF  15      /* prec cutoff */
00295    
00296 
00297 #define ICMP_SOURCEQUENCH                               4               /* packet lost, slow down */
00298 #define ICMP_ROUTERADVERT                               9       /* router advertisement */
00299 #define ICMP_ROUTERSOLICIT                              10      /* router solicitation */    
00300 #define ICMP_REDIRECT                                   5               /* shorter route, codes: */
00301 #define ICMP_REDIRECT_NET                               0               /* for network */
00302 #define ICMP_REDIRECT_HOST                              1               /* for host */
00303 #define ICMP_REDIRECT_TOSNET                    2               /* for tos and net */
00304 #define ICMP_REDIRECT_TOSHOST                   3               /* for tos and host */
00305 #define ICMP_ECHO                                               8               /* echo service */
00306 #define ICMP_TIMXCEED                                   11              /* time exceeded, code: */
00307 #define ICMP_TIMXCEED_INTRANS                   0               /* ttl==0 in transit */
00308 #define ICMP_TIMXCEED_REASS                             1               /* ttl==0 in reass */
00309 #define ICMP_PARAMPROB                                  12              /* ip header bad */
00310 #define ICMP_TSTAMP                                             13              /* timestamp request */
00311 #define ICMP_TSTAMPREPLY                                14              /* timestamp reply */
00312 #define ICMP_IREQ                                               15              /* information request */
00313 #define ICMP_IREQREPLY                                  16              /* information reply */
00314 #define ICMP_MASKREQ                                    17              /* address mask request */
00315 #define ICMP_MASKREPLY                                  18              /* address mask reply */
00316 
00317 #define ICMP_MAXTYPE            18
00318 
00319 #define ICMP_INFOTYPE(type) \
00320         ((type) == ICMP_ECHOREPLY || (type) == ICMP_ECHO || \
00321         (type) == ICMP_TSTAMP || (type) == ICMP_TSTAMPREPLY || \
00322         (type) == ICMP_IREQ || (type) == ICMP_IREQREPLY || \
00323         (type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY)
00324 
00325 /*** ICMP types ********************************************************/
00326 #define ICMP_TYPE_0     "Echo reply"
00327 #define ICMP_TYPE_3     "Destination unreachable"
00328 #define ICMP_TYPE_4     "Source quench"
00329 #define ICMP_TYPE_5     "Redirect"
00330 #define ICMP_TYPE_8     "Echo"
00331 #define ICMP_TYPE_11    "Time exceeded"
00332 #define ICMP_TYPE_12    "Parameter problem"
00333 #define ICMP_TYPE_13    "Timestamp"
00334 #define ICMP_TYPE_14    "Timestamp reply"
00335 #define ICMP_TYPE_15    "Information request"
00336 #define ICMP_TYPE_16    "Information reply"
00337 #define ICMP_TYPE_17    "Address mask request"
00338 #define ICMP_TYPE_18    "Adress mask reply"
00339 
00340 /* pulled token stuff from tcpdump */
00341 struct tok {
00342         int v;                  /* value */
00343         char *s;                /* string */
00344 };
00345 
00346 // TCP
00347 /////////////////////////////////////////////////////////////////////////
00348 typedef u_long  tcp_seq;
00349 
00350 // TCP header. Per RFC 793, September, 1981. In Little Endian
00351 struct tcphdr {
00352         u_short th_sport;               /* source port */
00353         u_short th_dport;               /* destination port */
00354         tcp_seq th_seq;                 /* sequence number */
00355         tcp_seq th_ack;                 /* acknowledgement number */
00356         u_char  th_x2:4,                /* (unused) */
00357                     th_off:4;           /* data offset */
00358         u_char  th_flags;
00359 #define TH_FIN  0x01
00360 #define TH_SYN  0x02
00361 #define TH_RST  0x04
00362 #define TH_PSH  0x08
00363 #define TH_ACK  0x10
00364 #define TH_URG  0x20
00365         u_short th_win;                 /* window */
00366         u_short th_sum;                 /* checksum */
00367         u_short th_urp;                 /* urgent pointer */
00368 };
00369 
00370 #define TCPOPT_EOL      0
00371 #define TCPOPT_NOP      1
00372 #define TCPOPT_MAXSEG   2
00373 
00374 enum {
00375   TCP_ESTABLISHED = 1,
00376   TCP_SYN_SENT,
00377   TCP_SYN_RECV,
00378   TCP_FIN_WAIT1,
00379   TCP_FIN_WAIT2,
00380   TCP_TIME_WAIT,
00381   TCP_CLOSE,
00382   TCP_CLOSE_WAIT,
00383   TCP_LAST_ACK,
00384   TCP_LISTEN,
00385   TCP_CLOSING   /* now a valid state */
00386 };
00387 
00388 // UDP Header
00389 //////////////////////////////////////////////////////////////////////////////
00390 struct udphdr {
00391   unsigned short        source;
00392   unsigned short        dest;
00393   unsigned short        len;
00394   unsigned short        check;
00395 };
00396 
00397 
00398 // Netbios/SAMBA
00399 //////////////////////////////////////////////////////////////////////////////
00400 /* the basic packet size, assuming no words or bytes */
00401 #define smb_size 39
00402 
00403 /* offsets into message for common items */
00404 #define smb_com 8
00405 #define smb_rcls 9
00406 #define smb_reh 10
00407 #define smb_err 11
00408 #define smb_flg 13
00409 #define smb_flg2 14
00410 #define smb_reb 13
00411 #define smb_tid 28
00412 #define smb_pid 30
00413 #define smb_uid 32
00414 #define smb_mid 34
00415 #define smb_wct 36
00416 #define smb_vwv 37
00417 #define smb_vwv0 37
00418 #define smb_vwv1 39
00419 #define smb_vwv2 41
00420 #define smb_vwv3 43
00421 #define smb_vwv4 45
00422 #define smb_vwv5 47
00423 #define smb_vwv6 49
00424 #define smb_vwv7 51
00425 #define smb_vwv8 53
00426 #define smb_vwv9 55
00427 #define smb_vwv10 57
00428 #define smb_vwv11 59
00429 #define smb_vwv12 61
00430 #define smb_vwv13 63
00431 #define smb_vwv14 65
00432 #define smb_vwv15 67
00433 #define smb_vwv16 69
00434 #define smb_vwv17 71
00435 
00436 /* the complete */
00437 #define SMBmkdir      0x00   /* create directory */
00438 #define SMBrmdir      0x01   /* delete directory */
00439 #define SMBopen       0x02   /* open file */
00440 #define SMBcreate     0x03   /* create file */
00441 #define SMBclose      0x04   /* close file */
00442 #define SMBflush      0x05   /* flush file */
00443 #define SMBunlink     0x06   /* delete file */
00444 #define SMBmv         0x07   /* rename file */
00445 #define SMBgetatr     0x08   /* get file attributes */
00446 #define SMBsetatr     0x09   /* set file attributes */
00447 #define SMBread       0x0A   /* read from file */
00448 #define SMBwrite      0x0B   /* write to file */
00449 #define SMBlock       0x0C   /* lock byte range */
00450 #define SMBunlock     0x0D   /* unlock byte range */
00451 #define SMBctemp      0x0E   /* create temporary file */
00452 #define SMBmknew      0x0F   /* make new file */
00453 #define SMBchkpth     0x10   /* check directory path */
00454 #define SMBexit       0x11   /* process exit */
00455 #define SMBlseek      0x12   /* seek */
00456 #define SMBtcon       0x70   /* tree connect */
00457 #define SMBtconX      0x75   /* tree connect and X*/
00458 #define SMBtdis       0x71   /* tree disconnect */
00459 #define SMBnegprot    0x72   /* negotiate protocol */
00460 #define SMBdskattr    0x80   /* get disk attributes */
00461 #define SMBsearch     0x81   /* search directory */
00462 #define SMBsplopen    0xC0   /* open print spool file */
00463 #define SMBsplwr      0xC1   /* write to print spool file */
00464 #define SMBsplclose   0xC2   /* close print spool file */
00465 #define SMBsplretq    0xC3   /* return print queue */
00466 #define SMBsends      0xD0   /* send single block message */
00467 #define SMBsendb      0xD1   /* send broadcast message */
00468 #define SMBfwdname    0xD2   /* forward user name */
00469 #define SMBcancelf    0xD3   /* cancel forward */
00470 #define SMBgetmac     0xD4   /* get machine name */
00471 #define SMBsendstrt   0xD5   /* send start of multi-block message */
00472 #define SMBsendend    0xD6   /* send end of multi-block message */
00473 #define SMBsendtxt    0xD7   /* send text of multi-block message */
00474 
00475 /* Core+ protocol */
00476 #define SMBlockread       0x13   /* Lock a range and read */
00477 #define SMBwriteunlock 0x14 /* Unlock a range then write */
00478 #define SMBreadbraw   0x1a  /* read a block of data with no smb header */
00479 #define SMBwritebraw  0x1d  /* write a block of data with no smb header */
00480 #define SMBwritec     0x20  /* secondary write request */
00481 #define SMBwriteclose 0x2c  /* write a file then close it */
00482 
00483 /* dos extended protocol */
00484 #define SMBreadBraw      0x1A   /* read block raw */
00485 #define SMBreadBmpx      0x1B   /* read block multiplexed */
00486 #define SMBreadBs        0x1C   /* read block (secondary response) */
00487 #define SMBwriteBraw     0x1D   /* write block raw */
00488 #define SMBwriteBmpx     0x1E   /* write block multiplexed */
00489 #define SMBwriteBs       0x1F   /* write block (secondary request) */
00490 #define SMBwriteC        0x20   /* write complete response */
00491 #define SMBsetattrE      0x22   /* set file attributes expanded */
00492 #define SMBgetattrE      0x23   /* get file attributes expanded */
00493 #define SMBlockingX      0x24   /* lock/unlock byte ranges and X */
00494 #define SMBtrans         0x25   /* transaction - name, bytes in/out */
00495 #define SMBtranss        0x26   /* transaction (secondary request/response) */
00496 #define SMBioctl         0x27   /* IOCTL */
00497 #define SMBioctls        0x28   /* IOCTL  (secondary request/response) */
00498 #define SMBcopy          0x29   /* copy */
00499 #define SMBmove          0x2A   /* move */
00500 #define SMBecho          0x2B   /* echo */
00501 #define SMBopenX         0x2D   /* open and X */
00502 #define SMBreadX         0x2E   /* read and X */
00503 #define SMBwriteX        0x2F   /* write and X */
00504 #define SMBsesssetupX    0x73   /* Session Set Up & X (including User Logon) */
00505 #define SMBffirst        0x82   /* find first */
00506 #define SMBfunique       0x83   /* find unique */
00507 #define SMBfclose        0x84   /* find close */
00508 #define SMBinvalid       0xFE   /* invalid command */
00509 
00510 /* Extended 2.0 protocol */
00511 #define SMBtrans2        0x32   /* TRANS2 protocol set */
00512 #define SMBtranss2       0x33   /* TRANS2 protocol set, secondary command */
00513 #define SMBfindclose     0x34   /* Terminate a TRANSACT2_FINDFIRST */
00514 #define SMBfindnclose    0x35   /* Terminate a TRANSACT2_FINDNOTIFYFIRST */
00515 #define SMBulogoffX      0x74   /* user logoff */
00516 
00517 
00518 /* these are the TRANS2 sub commands */
00519 #define TRANSACT2_OPEN          0
00520 #define TRANSACT2_FINDFIRST     1
00521 #define TRANSACT2_FINDNEXT      2
00522 #define TRANSACT2_QFSINFO       3
00523 #define TRANSACT2_SETFSINFO     4
00524 #define TRANSACT2_QPATHINFO     5
00525 #define TRANSACT2_SETPATHINFO   6
00526 #define TRANSACT2_QFILEINFO     7
00527 #define TRANSACT2_SETFILEINFO   8
00528 #define TRANSACT2_FSCTL         9
00529 #define TRANSACT2_IOCTL           10
00530 #define TRANSACT2_FINDNOTIFYFIRST 11
00531 #define TRANSACT2_FINDNOTIFYNEXT  12
00532 #define TRANSACT2_MKDIR           13
00533 
00534 
00535 /* these are the trans2 sub fields for primary requests */
00536 #define smb_tpscnt smb_vwv0
00537 #define smb_tdscnt smb_vwv1
00538 #define smb_mprcnt smb_vwv2
00539 #define smb_mdrcnt smb_vwv3
00540 #define smb_msrcnt smb_vwv4
00541 #define smb_flags smb_vwv5
00542 #define smb_timeout smb_vwv6
00543 #define smb_pscnt smb_vwv9
00544 #define smb_psoff smb_vwv10
00545 #define smb_dscnt smb_vwv11
00546 #define smb_dsoff smb_vwv12
00547 #define smb_suwcnt smb_vwv13
00548 #define smb_setup smb_vwv14
00549 #define smb_setup0 smb_setup
00550 #define smb_setup1 (smb_setup+2)
00551 #define smb_setup2 (smb_setup+4)
00552 
00553 /* these are for the secondary requests */
00554 #define smb_spscnt smb_vwv2
00555 #define smb_spsoff smb_vwv3
00556 #define smb_spsdisp smb_vwv4
00557 #define smb_sdscnt smb_vwv5
00558 #define smb_sdsoff smb_vwv6
00559 #define smb_sdsdisp smb_vwv7
00560 #define smb_sfid smb_vwv8
00561 
00562 /* and these for responses */
00563 #define smb_tprcnt smb_vwv0
00564 #define smb_tdrcnt smb_vwv1
00565 #define smb_prcnt smb_vwv3
00566 #define smb_proff smb_vwv4
00567 #define smb_prdisp smb_vwv5
00568 #define smb_drcnt smb_vwv6
00569 #define smb_droff smb_vwv7
00570 #define smb_drdisp smb_vwv8
00571 
00572 /* where to find the base of the SMB packet proper */
00573 #define smb_base(buf) (((char *)(buf))+4)
00574 
00575 
00576 #define ERRDOS 0x01  /*  Error is from the core DOS operating system set. */
00577 #define ERRSRV 0x02  /* Error is generated by the server network file manager.*/
00578 #define ERRHRD 0x03  /* Error is an hardware error. */
00579 #define ERRCMD 0xFF  /* Command was not in the "SMB" format. */
00580 
00581 /* structure used to hold the incoming hosts info */
00582 struct from_host {
00583     char   *name;                       /* host name */
00584     char   *addr;                       /* host address */
00585     struct sockaddr_in *sin;            /* their side of the link */
00586 };
00587 
00588 #define MAX_DGRAM_SIZE 576
00589 #define MIN_DGRAM_SIZE 12
00590 
00591 #define NMB_PORT 137
00592 #define DGRAM_PORT 138
00593 #define SMB_PORT 139
00594 
00595 enum name_source {LMHOSTS, REGISTER, SELF, DNS, DNSFAIL};
00596 enum node_type {B_NODE=0, P_NODE=1, M_NODE=2, NBDD_NODE=3};
00597 enum packet_type {NMB_PACKET, DGRAM_PACKET};
00598 
00599 /* a netbios name structure */
00600 struct nmb_name {
00601   char name[17];
00602   char scope[64];
00603   int name_type;
00604 };
00605 
00606 /* a resource record */
00607 struct res_rec {
00608   struct nmb_name rr_name;
00609   int rr_type;
00610   int rr_class;
00611   int ttl;
00612   int rdlength;
00613   char rdata[MAX_DGRAM_SIZE];
00614 };
00615 
00616 /* define a nmb packet. */
00617 struct nmb_packet
00618 {
00619   struct {
00620     int name_trn_id;
00621     int opcode;
00622     BOOL response;
00623     struct {
00624       BOOL bcast;
00625       BOOL recursion_available;
00626       BOOL recursion_desired;
00627       BOOL trunc;
00628       BOOL authoritative;
00629     } nm_flags;
00630     int rcode;
00631     int qdcount;
00632     int ancount;
00633     int nscount;
00634     int arcount;
00635   } header;
00636 
00637   struct {
00638     struct nmb_name question_name;
00639     int question_type;
00640     int question_class;
00641   } question;
00642 
00643   struct res_rec *answers;
00644   struct res_rec *nsrecs;
00645   struct res_rec *additional;
00646 };
00647 
00648 /* rfc1191 */
00649 struct mtu_discovery {
00650         short unused;
00651         short nexthopmtu;
00652 };
00653 
00654 #define EXTRACT_SHORT(p)        ((u_short)ntohs(*(u_short *)p))
00655 #define EXTRACT_LONG(p)         (ntohl(*(u_int32 *)p))
00656 
00657 
00658 /* pulled from tcpdump */
00659 /* XXX probably should use getservbyname() and cache answers */
00660 #define TFTP_PORT 69            /*XXX*/
00661 #define NAMESERVER_PORT 53
00662 #define KERBEROS_PORT 88        /*XXX*/
00663 #define SUNRPC_PORT 111         /*XXX*/
00664 #define SNMP_PORT 161           /*XXX*/
00665 #define NTP_PORT 123            /*XXX*/
00666 #define SNMPTRAP_PORT 162       /*XXX*/
00667 #define RIP_PORT 520            /*XXX*/
00668 #define KERBEROS_SEC_PORT 750   /*XXX*/
00669 
00670 
00671 /* TICK_TIME in ms
00672  * time to wait between Read Requests
00673  * if no packet has been sniffed..
00674  */
00675 #define TICK_TIME 10
00676 #define OUR_IP  (gOurIP ? gOurIP : rkGetOurIP())
00677 #define OUR_MAC (gOurMAC ? gOurMAC : rkGetOurMAC())
00678 #define MAXHOSTNAMELEN  64      /* max length of hostname */
00679 
00680 typedef struct _RIPDERM { 
00681         char *mBuf;
00682         int mLen;
00683 } RIPDERM, *PRIPDERM;
00684 
00685 
00686 
00687 //typedef list<PRIPDERM> VRIP;
00688 //typedef list<char *> NAMELIST;
00689 //typedef map<unsigned long, NAMELIST *> LMHOSTLIST;
00690 //typedef map<unsigned long, __int64> MACMAP; /* note that masking is required */
00691 
00692 //void SendThruFilterRaw(const char * p, int len);
00693 //void SendHex(char *theAsciiString);
00694 //void SendRaw(const char * theData, int theLen);

Generated on Sun May 14 14:51:19 2006 by  doxygen 1.4.2