00001
00002
00003
00004
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;
00015 unsigned int ip_v:4;
00016 u_char ip_tos;
00017 u_short ip_len;
00018 u_short ip_id;
00019 u_short ip_off;
00020 #define IP_RF 0x8000
00021 #define IP_DF 0x4000
00022 #define IP_MF 0x2000
00023 #define IP_OFFMASK 0x1fff
00024 u_char ip_ttl;
00025 u_char ip_p;
00026 u_short ip_sum;
00027 struct in_addr ip_src, ip_dst;
00028 };
00029
00030 #define MAX_IPOPTLEN 40
00031
00032
00033
00034
00035
00036
00037 #define ETH_ALEN 6
00038 #define ETH_HLEN 14
00039 #define ETH_ZLEN 60
00040 #define ETH_DATA_LEN 1500
00041 #define ETH_FRAME_LEN 1514
00042
00043
00044
00045
00046
00047 #define ETH_P_LOOP 0x0060
00048 #define ETH_P_ECHO 0x0200
00049 #define ETH_P_PUP 0x0400
00050 #define ETH_P_IP 0x0800
00051 #define ETH_P_X25 0x0805
00052 #define ETH_P_ARP 0x0806
00053 #define ETH_P_BPQ 0x08FF
00054 #define ETH_P_DEC 0x6000
00055 #define ETH_P_DNA_DL 0x6001
00056 #define ETH_P_DNA_RC 0x6002
00057 #define ETH_P_DNA_RT 0x6003
00058 #define ETH_P_LAT 0x6004
00059 #define ETH_P_DIAG 0x6005
00060 #define ETH_P_CUST 0x6006
00061 #define ETH_P_SCA 0x6007
00062 #define ETH_P_RARP 0x8035
00063 #define ETH_P_ATALK 0x809B
00064 #define ETH_P_AARP 0x80F3
00065 #define ETH_P_IPX 0x8137
00066 #define ETH_P_IPV6 0x86DD
00067
00068
00069
00070
00071
00072 #define ETH_P_802_3 0x0001
00073 #define ETH_P_AX25 0x0002
00074 #define ETH_P_ALL 0x0003
00075 #define ETH_P_802_2 0x0004
00076 #define ETH_P_SNAP 0x0005
00077 #define ETH_P_DDCMP 0x0006
00078 #define ETH_P_WAN_PPP 0x0007
00079 #define ETH_P_PPP_MP 0x0008
00080 #define ETH_P_LOCALTALK 0x0009
00081 #define ETH_P_PPPTALK 0x0010
00082 #define ETH_P_TR_802_2 0x0011
00083
00084 struct etherproto {
00085 char *s;
00086 u_short p;
00087 };
00088 extern struct etherproto etherproto_db[];
00089
00090
00091 struct ether_header
00092 {
00093 unsigned char h_dest[ETH_ALEN];
00094 unsigned char h_source[ETH_ALEN];
00095 unsigned short h_proto;
00096 };
00097
00098
00099
00100 static u_char bcastaddr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
00101
00102
00103
00104
00105
00106 struct arphdr
00107 {
00108 unsigned short ar_hrd;
00109 unsigned short ar_pro;
00110 unsigned char ar_hln;
00111 unsigned char ar_pln;
00112 unsigned short ar_op;
00113 };
00114
00115 #define ARPD_UPDATE 0x01
00116 #define ARPD_LOOKUP 0x02
00117 #define ARPD_FLUSH 0x03
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133 struct ether_arp {
00134 struct arphdr ea_hdr;
00135 u_char arp_sha[ETH_ALEN];
00136 u_char arp_spa[4];
00137 u_char arp_tha[ETH_ALEN];
00138 u_char arp_tpa[4];
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
00147
00148 struct iphdr {
00149 u_char ip_hl:4,
00150 ip_v:4;
00151 u_char ip_tos;
00152 short ip_len;
00153 u_short ip_id;
00154 short ip_off;
00155 #define IP_DF 0x4000
00156 #define IP_MF 0x2000
00157 u_char ip_ttl;
00158 u_char ip_p;
00159 u_short ip_sum;
00160 struct in_addr ip_src,ip_dst;
00161 };
00162
00163 #define IP_MAXPACKET 65535
00164
00165
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
00176 #define IPOPT_NOP 0x01
00177
00178 #define IPOPT_RR 0x07
00179 #define IPOPT_TS 0x44
00180 #define IPOPT_SECURITY 0x82
00181 #define IPOPT_LSRR 0x83
00182 #define IPOPT_SATID 0x88
00183 #define IPOPT_SSRR 0x89
00184
00185
00186
00187 struct ip_timestamp {
00188 u_char ipt_code;
00189 u_char ipt_len;
00190 u_char ipt_ptr;
00191 u_char ipt_flg:4,
00192 ipt_oflw:4;
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
00203 #define IPOPT_TS_TSONLY 0
00204 #define IPOPT_TS_TSANDADDR 1
00205 #define IPOPT_TS_PRESPEC 2
00206
00207
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
00217
00218 struct icmphdr {
00219 u_char icmp_type;
00220 u_char icmp_code;
00221 u_short icmp_cksum;
00222 union {
00223 u_char ih_pptr;
00224 struct in_addr ih_gwaddr;
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
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
00259
00260
00261
00262
00263
00264
00265 #define ICMP_MINLEN 8
00266 #define ICMP_TSLEN (8 + 3 * sizeof (n_time))
00267 #define ICMP_MASKLEN 12
00268 #define ICMP_ADVLENMIN (8 + sizeof (struct ip) + 8)
00269 #define ICMP_ADVLEN(p) (8 + ((p)->icmp_ip.ip_hl << 2) + 8)
00270
00271
00272
00273
00274
00275 #define ICMP_ECHOREPLY 0
00276
00277
00278 #define ICMP_UNREACH 3
00279 #define ICMP_UNREACH_NET 0
00280 #define ICMP_UNREACH_HOST 1
00281 #define ICMP_UNREACH_PROTOCOL 2
00282 #define ICMP_UNREACH_PORT 3
00283 #define ICMP_UNREACH_NEEDFRAG 4
00284 #define ICMP_UNREACH_SRCFAIL 5
00285 #define ICMP_UNREACH_NET_UNKNOWN 6
00286 #define ICMP_UNREACH_HOST_UNKNOWN 7
00287 #define ICMP_UNREACH_ISOLATED 8
00288 #define ICMP_UNREACH_NET_PROHIB 9
00289 #define ICMP_UNREACH_HOST_PROHIB 10
00290 #define ICMP_UNREACH_TOSNET 11
00291 #define ICMP_UNREACH_TOSHOST 12
00292 #define ICMP_UNREACH_FILTER_PROHIB 13
00293 #define ICMP_UNREACH_HOST_PRECEDENCE 14
00294 #define ICMP_UNREACH_PRECEDENCE_CUTOFF 15
00295
00296
00297 #define ICMP_SOURCEQUENCH 4
00298 #define ICMP_ROUTERADVERT 9
00299 #define ICMP_ROUTERSOLICIT 10
00300 #define ICMP_REDIRECT 5
00301 #define ICMP_REDIRECT_NET 0
00302 #define ICMP_REDIRECT_HOST 1
00303 #define ICMP_REDIRECT_TOSNET 2
00304 #define ICMP_REDIRECT_TOSHOST 3
00305 #define ICMP_ECHO 8
00306 #define ICMP_TIMXCEED 11
00307 #define ICMP_TIMXCEED_INTRANS 0
00308 #define ICMP_TIMXCEED_REASS 1
00309 #define ICMP_PARAMPROB 12
00310 #define ICMP_TSTAMP 13
00311 #define ICMP_TSTAMPREPLY 14
00312 #define ICMP_IREQ 15
00313 #define ICMP_IREQREPLY 16
00314 #define ICMP_MASKREQ 17
00315 #define ICMP_MASKREPLY 18
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
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
00341 struct tok {
00342 int v;
00343 char *s;
00344 };
00345
00346
00347
00348 typedef u_long tcp_seq;
00349
00350
00351 struct tcphdr {
00352 u_short th_sport;
00353 u_short th_dport;
00354 tcp_seq th_seq;
00355 tcp_seq th_ack;
00356 u_char th_x2:4,
00357 th_off:4;
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;
00366 u_short th_sum;
00367 u_short th_urp;
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
00386 };
00387
00388
00389
00390 struct udphdr {
00391 unsigned short source;
00392 unsigned short dest;
00393 unsigned short len;
00394 unsigned short check;
00395 };
00396
00397
00398
00399
00400
00401 #define smb_size 39
00402
00403
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
00437 #define SMBmkdir 0x00
00438 #define SMBrmdir 0x01
00439 #define SMBopen 0x02
00440 #define SMBcreate 0x03
00441 #define SMBclose 0x04
00442 #define SMBflush 0x05
00443 #define SMBunlink 0x06
00444 #define SMBmv 0x07
00445 #define SMBgetatr 0x08
00446 #define SMBsetatr 0x09
00447 #define SMBread 0x0A
00448 #define SMBwrite 0x0B
00449 #define SMBlock 0x0C
00450 #define SMBunlock 0x0D
00451 #define SMBctemp 0x0E
00452 #define SMBmknew 0x0F
00453 #define SMBchkpth 0x10
00454 #define SMBexit 0x11
00455 #define SMBlseek 0x12
00456 #define SMBtcon 0x70
00457 #define SMBtconX 0x75
00458 #define SMBtdis 0x71
00459 #define SMBnegprot 0x72
00460 #define SMBdskattr 0x80
00461 #define SMBsearch 0x81
00462 #define SMBsplopen 0xC0
00463 #define SMBsplwr 0xC1
00464 #define SMBsplclose 0xC2
00465 #define SMBsplretq 0xC3
00466 #define SMBsends 0xD0
00467 #define SMBsendb 0xD1
00468 #define SMBfwdname 0xD2
00469 #define SMBcancelf 0xD3
00470 #define SMBgetmac 0xD4
00471 #define SMBsendstrt 0xD5
00472 #define SMBsendend 0xD6
00473 #define SMBsendtxt 0xD7
00474
00475
00476 #define SMBlockread 0x13
00477 #define SMBwriteunlock 0x14
00478 #define SMBreadbraw 0x1a
00479 #define SMBwritebraw 0x1d
00480 #define SMBwritec 0x20
00481 #define SMBwriteclose 0x2c
00482
00483
00484 #define SMBreadBraw 0x1A
00485 #define SMBreadBmpx 0x1B
00486 #define SMBreadBs 0x1C
00487 #define SMBwriteBraw 0x1D
00488 #define SMBwriteBmpx 0x1E
00489 #define SMBwriteBs 0x1F
00490 #define SMBwriteC 0x20
00491 #define SMBsetattrE 0x22
00492 #define SMBgetattrE 0x23
00493 #define SMBlockingX 0x24
00494 #define SMBtrans 0x25
00495 #define SMBtranss 0x26
00496 #define SMBioctl 0x27
00497 #define SMBioctls 0x28
00498 #define SMBcopy 0x29
00499 #define SMBmove 0x2A
00500 #define SMBecho 0x2B
00501 #define SMBopenX 0x2D
00502 #define SMBreadX 0x2E
00503 #define SMBwriteX 0x2F
00504 #define SMBsesssetupX 0x73
00505 #define SMBffirst 0x82
00506 #define SMBfunique 0x83
00507 #define SMBfclose 0x84
00508 #define SMBinvalid 0xFE
00509
00510
00511 #define SMBtrans2 0x32
00512 #define SMBtranss2 0x33
00513 #define SMBfindclose 0x34
00514 #define SMBfindnclose 0x35
00515 #define SMBulogoffX 0x74
00516
00517
00518
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
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
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
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
00573 #define smb_base(buf) (((char *)(buf))+4)
00574
00575
00576 #define ERRDOS 0x01
00577 #define ERRSRV 0x02
00578 #define ERRHRD 0x03
00579 #define ERRCMD 0xFF
00580
00581
00582 struct from_host {
00583 char *name;
00584 char *addr;
00585 struct sockaddr_in *sin;
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
00600 struct nmb_name {
00601 char name[17];
00602 char scope[64];
00603 int name_type;
00604 };
00605
00606
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
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
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
00659
00660 #define TFTP_PORT 69
00661 #define NAMESERVER_PORT 53
00662 #define KERBEROS_PORT 88
00663 #define SUNRPC_PORT 111
00664 #define SNMP_PORT 161
00665 #define NTP_PORT 123
00666 #define SNMPTRAP_PORT 162
00667 #define RIP_PORT 520
00668 #define KERBEROS_SEC_PORT 750
00669
00670
00671
00672
00673
00674
00675 #define TICK_TIME 10
00676 #define OUR_IP (gOurIP ? gOurIP : rkGetOurIP())
00677 #define OUR_MAC (gOurMAC ? gOurMAC : rkGetOurMAC())
00678 #define MAXHOSTNAMELEN 64
00679
00680 typedef struct _RIPDERM {
00681 char *mBuf;
00682 int mLen;
00683 } RIPDERM, *PRIPDERM;
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694