Annotation of embedaddon/hping2/hping2.h, revision 1.1

1.1     ! misho       1: /* 
        !             2:  * $smu-mark$ 
        !             3:  * $name: hping2.h$ 
        !             4:  * $author: Salvatore Sanfilippo <antirez@invece.org>$ 
        !             5:  * $copyright: Copyright (C) 1999 by Salvatore Sanfilippo$ 
        !             6:  * $license: This software is under GPL version 2 of license$ 
        !             7:  * $date: Fri Nov  5 11:55:48 MET 1999$ 
        !             8:  * $rev: 9$ 
        !             9:  */ 
        !            10: 
        !            11: /* $Id: hping2.h,v 1.19 2003/08/07 23:55:55 antirez Exp $ */
        !            12: 
        !            13: #ifndef _HPING2_H
        !            14: #define _HPING2_H
        !            15: 
        !            16: #include <sys/types.h>
        !            17: #include <sys/socket.h>
        !            18: #include <netinet/in.h>
        !            19: #include "byteorder.h"
        !            20: #include "systype.h"
        !            21: 
        !            22: #ifdef __sun__
        !            23: typedef char                   int_8_t;
        !            24: typedef unsigned char          u_int8_t;
        !            25: typedef short                  int_16_t;
        !            26: typedef unsigned short         u_int16_t;
        !            27: typedef int                    int_32_t;
        !            28: typedef unsigned int           u_int32_t;
        !            29: #endif
        !            30: 
        !            31: /* types */
        !            32: #ifndef __u8
        !            33: #define __u8           u_int8_t
        !            34: #endif /* __u8 */
        !            35: #ifndef __u16
        !            36: #define __u16          u_int16_t
        !            37: #endif /* __u16 */
        !            38: #ifndef __u32
        !            39: #define __u32          u_int32_t
        !            40: #endif /* __u32 */
        !            41: 
        !            42: #ifndef __uint8_t
        !            43: #define __uint8_t      u_int8_t
        !            44: #endif /* __uint8_t */
        !            45: #ifndef __uint16_t
        !            46: #define __uint16_t     u_int16_t
        !            47: #endif /* __uint16_t */
        !            48: #ifndef __uint32_t
        !            49: #define __uint32_t     u_int32_t
        !            50: #endif /* __uint32_t */
        !            51: 
        !            52: #include "hcmp.h" /* Hping Control Message Protocol */
        !            53: 
        !            54: /* protocols header size */
        !            55: #ifndef ICMPHDR_SIZE
        !            56: #define ICMPHDR_SIZE   sizeof(struct myicmphdr)
        !            57: #endif
        !            58: #ifndef UDPHDR_SIZE
        !            59: #define UDPHDR_SIZE    sizeof(struct myudphdr)
        !            60: #endif
        !            61: #ifndef TCPHDR_SIZE
        !            62: #define TCPHDR_SIZE    sizeof(struct mytcphdr)
        !            63: #endif
        !            64: #ifndef IPHDR_SIZE
        !            65: #define IPHDR_SIZE     sizeof(struct myiphdr)
        !            66: #endif
        !            67: 
        !            68: /* wait X seconds after reached to sent packets in oreder to display replies */
        !            69: #define COUNTREACHED_TIMEOUT 1
        !            70: 
        !            71: /* requests status table stuffs */
        !            72: /* Warning, TABLESIZE 0 == floating point exception */
        !            73: #define TABLESIZE      400
        !            74: #define S_SENT         0
        !            75: #define S_RECV         1
        !            76: 
        !            77: /* usefull defines */
        !            78: #ifndef TRUE
        !            79: #define TRUE   1
        !            80: #define FALSE  0
        !            81: #endif
        !            82: #ifndef IFNAMSIZ
        !            83: #define IFNAMSIZ 16
        !            84: #endif
        !            85: #ifndef PF_PACKET
        !            86: #define PF_PACKET 17           /* kernel 2.[12].* with 2.0.* kernel headers? */
        !            87: #endif
        !            88: #ifndef ETH_P_IP
        !            89: #define ETH_P_IP  0x0800       /* Internet Protocol packet     */
        !            90: #endif
        !            91: #ifndef ABS
        !            92: #define ABS(x) (((x)>0) ? (x) : -(x))
        !            93: #endif
        !            94: 
        !            95: /* header size of some physical layer type */
        !            96: #define PPPHDR_SIZE_LINUX      0
        !            97: #define PPPHDR_SIZE_FREEBSD    4
        !            98: #define PPPHDR_SIZE_OPENBSD    4
        !            99: #define PPPHDR_SIZE_NETBSD     4
        !           100: #define PPPHDR_SIZE_BSDI       4
        !           101: #define ETHHDR_SIZE            14
        !           102: #define LOHDR_SIZE             14
        !           103: #define WLANHDR_SIZE           14
        !           104: #define TRHDR_SIZE             20
        !           105: 
        !           106: /* packet size (physical header size + ip header + tcp header + 0 data bytes) */
        !           107: #ifndef IP_MAX_SIZE
        !           108: #define IP_MAX_SIZE    65535
        !           109: #endif 
        !           110: 
        !           111: /* absolute offsets */
        !           112: #define ABS_OFFSETIP   linkhdr_size
        !           113: #define ABS_OFFSETTCP  ( linkhdr_size + IPHDR_SIZE )
        !           114: #define ABS_OFFSETICMP ( linkhdr_size + IPHDR_SIZE )
        !           115: #define ABS_OFFSETUDP  ( linkhdr_size + IPHDR_SIZE )
        !           116: 
        !           117: /* defaults and misc */
        !           118: #define DEFAULT_SENDINGWAIT 1  /* wait 1 sec. between sending each packets */
        !           119: #define DEFAULT_DPORT      0   /* default dest. port */
        !           120: #define DEFAULT_INITSPORT  -1  /* default initial source port: -1 means random */
        !           121: #define DEFAULT_COUNT      -1  /* default packets count: -1 means forever */
        !           122: #define DEFAULT_TTL       64   /* default ip->ttl value */
        !           123: #define DEFAULT_SRCWINSIZE 512 /* default tcp windows size */
        !           124: #define DEFAULT_VIRTUAL_MTU 16  /* tiny fragments */
        !           125: #define DEFAULT_ICMP_TYPE   8  /* echo request */
        !           126: #define DEFAULT_ICMP_CODE   0  /* icmp-type relative */
        !           127: #define DEFAULT_ICMP_IP_VERSION                4
        !           128: #define DEFAULT_ICMP_IP_IHL            (IPHDR_SIZE >> 2)
        !           129: #define        DEFAULT_ICMP_IP_TOS             0
        !           130: #define DEFAULT_ICMP_IP_TOT_LEN                0 /* computed by send_icmp_*() */
        !           131: #define DEFAULT_ICMP_IP_ID             0 /* rand */
        !           132: #define DEFAULT_ICMP_CKSUM             -1 /* -1 means compute the cksum */
        !           133: #define DEFAULT_ICMP_IP_PROTOCOL       6 /* TCP */
        !           134: #define DEFAULT_RAW_IP_PROTOCOL                6 /* TCP */
        !           135: #define DEFAULT_TRACEROUTE_TTL         1
        !           136: 
        !           137: #define BIND_NONE      0               /* no bind */
        !           138: #define BIND_DPORT     1               /* bind destination port */
        !           139: #define BIND_TTL       2               /* bind ip->ttl */
        !           140: #define DEFAULT_BIND   BIND_DPORT
        !           141:        
        !           142: /* fragmentation defines */
        !           143: #define MF ((unsigned short)0x2000)    /* more fragments */
        !           144: #define DF ((unsigned short)0x4000)    /* dont fragment */
        !           145: #define NF ((unsigned short)0x0000)    /* no more fragments */
        !           146: 
        !           147: /* ip options defines */
        !           148: #define IPOPT_COPY             0x80
        !           149: #define IPOPT_CLASS_MASK       0x60
        !           150: #define IPOPT_NUMBER_MASK      0x1f
        !           151: 
        !           152: #define        IPOPT_COPIED(o)         ((o)&IPOPT_COPY)
        !           153: #define        IPOPT_CLASS(o)          ((o)&IPOPT_CLASS_MASK)
        !           154: #define        IPOPT_NUMBER(o)         ((o)&IPOPT_NUMBER_MASK)
        !           155: 
        !           156: #define        IPOPT_CONTROL           0x00
        !           157: #define        IPOPT_RESERVED1         0x20
        !           158: #define        IPOPT_MEASUREMENT       0x40
        !           159: #define        IPOPT_RESERVED2         0x60
        !           160: 
        !           161: #define IPOPT_END      (0 |IPOPT_CONTROL)
        !           162: #define IPOPT_NOOP     (1 |IPOPT_CONTROL)
        !           163: #define IPOPT_SEC      (2 |IPOPT_CONTROL|IPOPT_COPY)
        !           164: #define IPOPT_LSRR     (3 |IPOPT_CONTROL|IPOPT_COPY)
        !           165: #define IPOPT_TIMESTAMP        (4 |IPOPT_MEASUREMENT)
        !           166: #define IPOPT_RR       (7 |IPOPT_CONTROL)
        !           167: #define IPOPT_SID      (8 |IPOPT_CONTROL|IPOPT_COPY)
        !           168: #define IPOPT_SSRR     (9 |IPOPT_CONTROL|IPOPT_COPY)
        !           169: #define IPOPT_RA       (20|IPOPT_CONTROL|IPOPT_COPY)
        !           170: 
        !           171: #define IPOPT_OPTVAL 0
        !           172: #define IPOPT_OLEN   1
        !           173: #define IPOPT_OFFSET 2
        !           174: #define IPOPT_MINOFF 4
        !           175: #define MAX_IPOPTLEN 40
        !           176: #define IPOPT_NOP IPOPT_NOOP
        !           177: #define IPOPT_EOL IPOPT_END
        !           178: #define IPOPT_TS  IPOPT_TIMESTAMP
        !           179: 
        !           180: #define        IPOPT_TS_TSONLY         0               /* timestamps only */
        !           181: #define        IPOPT_TS_TSANDADDR      1               /* timestamps and addresses */
        !           182: #define        IPOPT_TS_PRESPEC        3               /* specified modules only */
        !           183: 
        !           184: /* tcp flags */
        !           185: #ifndef        TH_FIN
        !           186: #define TH_FIN  0x01
        !           187: #endif
        !           188: #ifndef TH_SYN
        !           189: #define TH_SYN  0x02
        !           190: #endif
        !           191: #ifndef TH_RST
        !           192: #define TH_RST  0x04
        !           193: #endif
        !           194: #ifndef TH_PUSH
        !           195: #define TH_PUSH 0x08
        !           196: #endif
        !           197: #ifndef TH_ACK
        !           198: #define TH_ACK  0x10
        !           199: #endif
        !           200: #ifndef TH_URG
        !           201: #define TH_URG  0x20
        !           202: #endif
        !           203: #ifndef TH_X
        !           204: #define        TH_X 0x40       /* X tcp flag */
        !           205: #endif
        !           206: #ifndef TH_Y
        !           207: #define TH_Y 0x80      /* Y tcp flag */
        !           208: #endif
        !           209: 
        !           210: /* ICMP TYPE */
        !           211: #define ICMP_ECHOREPLY          0       /* Echo Reply                   */
        !           212: #define ICMP_DEST_UNREACH       3       /* Destination Unreachable      */
        !           213: #define ICMP_SOURCE_QUENCH      4       /* Source Quench                */
        !           214: #define ICMP_REDIRECT           5       /* Redirect (change route)      */
        !           215: #define ICMP_ECHO               8       /* Echo Request                 */
        !           216: #define ICMP_TIME_EXCEEDED      11      /* Time Exceeded                */
        !           217: #define ICMP_PARAMETERPROB      12      /* Parameter Problem            */
        !           218: #define ICMP_TIMESTAMP          13      /* Timestamp Request            */
        !           219: #define ICMP_TIMESTAMPREPLY     14      /* Timestamp Reply              */
        !           220: #define ICMP_INFO_REQUEST       15      /* Information Request          */
        !           221: #define ICMP_INFO_REPLY         16      /* Information Reply            */
        !           222: #define ICMP_ADDRESS            17      /* Address Mask Request         */
        !           223: #define ICMP_ADDRESSREPLY       18      /* Address Mask Reply           */
        !           224: 
        !           225: /* Codes for UNREACHABLE */
        !           226: #define ICMP_NET_UNREACH        0       /* Network Unreachable          */
        !           227: #define ICMP_HOST_UNREACH       1       /* Host Unreachable             */
        !           228: #define ICMP_PROT_UNREACH       2       /* Protocol Unreachable         */
        !           229: #define ICMP_PORT_UNREACH       3       /* Port Unreachable             */
        !           230: #define ICMP_FRAG_NEEDED        4       /* Fragmentation Needed/DF set  */
        !           231: #define ICMP_SR_FAILED          5       /* Source Route failed          */
        !           232: #define ICMP_NET_UNKNOWN        6
        !           233: #define ICMP_HOST_UNKNOWN       7
        !           234: #define ICMP_HOST_ISOLATED      8
        !           235: #define ICMP_NET_ANO            9
        !           236: #define ICMP_HOST_ANO           10
        !           237: #define ICMP_NET_UNR_TOS        11
        !           238: #define ICMP_HOST_UNR_TOS       12
        !           239: #define ICMP_PKT_FILTERED       13      /* Packet filtered */
        !           240: #define ICMP_PREC_VIOLATION     14      /* Precedence violation */
        !           241: #define ICMP_PREC_CUTOFF        15      /* Precedence cut off */
        !           242: #define NR_ICMP_UNREACH 15        /* instead of hardcoding immediate value */
        !           243: 
        !           244: /* Codes for REDIRECT */
        !           245: #define ICMP_REDIR_NET          0       /* Redirect Net                 */
        !           246: #define ICMP_REDIR_HOST         1       /* Redirect Host                */
        !           247: #define ICMP_REDIR_NETTOS       2       /* Redirect Net for TOS         */
        !           248: #define ICMP_REDIR_HOSTTOS      3       /* Redirect Host for TOS        */
        !           249: 
        !           250: /* Codes for TIME_EXCEEDED */
        !           251: #define ICMP_EXC_TTL            0       /* TTL count exceeded           */
        !           252: #define ICMP_EXC_FRAGTIME       1       /* Fragment Reass time exceeded */
        !           253: 
        !           254: /*
        !           255:  * IP header
        !           256:  */
        !           257: struct myiphdr {
        !           258: #if defined(__LITTLE_ENDIAN_BITFIELD)
        !           259:         __u8    ihl:4,
        !           260:                 version:4;
        !           261: #elif defined (__BIG_ENDIAN_BITFIELD)
        !           262:         __u8    version:4,
        !           263:                 ihl:4;
        !           264: #else
        !           265: #error  "Please, edit Makefile and add -D__(LITTLE|BIG)_ENDIAN_BITFIEND"
        !           266: #endif
        !           267:         __u8    tos;
        !           268:         __u16   tot_len;
        !           269:         __u16   id;
        !           270:         __u16   frag_off;
        !           271:         __u8    ttl;
        !           272:         __u8    protocol;
        !           273:         __u16   check;
        !           274:         __u32   saddr;
        !           275:         __u32   daddr;
        !           276: };
        !           277: 
        !           278: /*
        !           279:  * UDP header
        !           280:  */
        !           281: struct myudphdr { 
        !           282:        __u16 uh_sport;     /* source port */
        !           283:        __u16 uh_dport;     /* destination port */
        !           284:        __u16 uh_ulen;      /* udp length */
        !           285:        __u16 uh_sum;       /* udp checksum */
        !           286: };
        !           287: 
        !           288: /*
        !           289:  * TCP header.
        !           290:  * Per RFC 793, September, 1981.
        !           291:  */
        !           292: struct mytcphdr {
        !           293:        __u16   th_sport;               /* source port */
        !           294:        __u16   th_dport;               /* destination port */
        !           295:        __u32   th_seq;                 /* sequence number */
        !           296:        __u32   th_ack;                 /* acknowledgement number */
        !           297: #if defined (__LITTLE_ENDIAN_BITFIELD)
        !           298:        __u8    th_x2:4,                /* (unused) */
        !           299:                th_off:4;               /* data offset */
        !           300: #elif defined (__BIG_ENDIAN_BITFIELD)
        !           301:        __u8    th_off:4,               /* data offset */
        !           302:                th_x2:4;                /* (unused) */
        !           303: #else
        !           304: #error  "Please, edit Makefile and add -D__(LITTLE|BIG)_ENDIAN_BITFIEND"
        !           305: #endif
        !           306:        __u8    th_flags;
        !           307:        __u16   th_win;                 /* window */
        !           308:        __u16   th_sum;                 /* checksum */
        !           309:        __u16   th_urp;                 /* urgent pointer */
        !           310: };
        !           311: 
        !           312: /*
        !           313:  * ICMP header
        !           314:  */
        !           315: struct myicmphdr
        !           316: {
        !           317:        __u8          type;
        !           318:        __u8          code;
        !           319:        __u16         checksum;
        !           320:        union
        !           321:        {
        !           322:                struct
        !           323:                {
        !           324:                        __u16   id;
        !           325:                        __u16   sequence;
        !           326:                } echo;
        !           327:                __u32   gateway;
        !           328:        } un;
        !           329: };
        !           330: 
        !           331: struct icmp_tstamp_data {
        !           332:        __u32 orig;
        !           333:        __u32 recv;
        !           334:        __u32 tran;
        !           335: };
        !           336: 
        !           337: /*
        !           338:  * UDP/TCP pseudo header
        !           339:  * for cksum computing
        !           340:  */
        !           341: struct pseudohdr
        !           342: {
        !           343:        __u32 saddr;
        !           344:        __u32 daddr;
        !           345:        __u8  zero;
        !           346:        __u8  protocol;
        !           347:        __u16 lenght;
        !           348: };
        !           349: 
        !           350: #define PSEUDOHDR_SIZE sizeof(struct pseudohdr)
        !           351: 
        !           352: /*
        !           353:  * hping replies delay table
        !           354:  */
        !           355: struct delaytable_element {
        !           356:        int seq;
        !           357:        int src;
        !           358:        time_t sec;
        !           359:        time_t usec;
        !           360:        int status;
        !           361: };
        !           362: 
        !           363: volatile struct delaytable_element delaytable[TABLESIZE];
        !           364: 
        !           365: /* protos */
        !           366: void   nop(void);                              /* nop */
        !           367: int    parse_options(int, char**);             /* option parser */
        !           368: int    get_if_name(void);                      /* get interface (see source) */
        !           369: int    get_linkhdr_size(char*);                /* get link layer hdr size */
        !           370: int    open_sockpacket(void);                  /* open SOCK_PACKET socket */
        !           371: int    close_sockpacket(int);                  /* close SOCK_PACKET socket */
        !           372: int    open_sockraw(void);                     /* open raw socket */
        !           373: void   send_packet (int signal_id);
        !           374: void   send_rawip (void);
        !           375: void   send_tcp(void);
        !           376: void   send_udp(void);
        !           377: void   send_icmp(void);
        !           378: void   send_hcmp(__u8 type, __u32 arg);        /* send hcmp packets */
        !           379: void   send_ip (char*, char*, char*, unsigned int, int, unsigned short,
        !           380:                 char*, char);
        !           381: void   send_ip_handler(char *packet, unsigned int size); /* fragmentation
        !           382:                                                              handler */
        !           383: void   wait_packet(void);                      /* handle incoming packets */
        !           384: void   print_statistics(int);
        !           385: void   show_usage(void);
        !           386: void   show_version(void);
        !           387: void   resolve(struct sockaddr*, char*);       /* resolver */
        !           388: void   log_icmp_unreach(char*, unsigned short);/* ICMP unreachable logger */
        !           389: void   log_icmp_timeexc(char*, unsigned short);/* ICMP time exceeded logger */
        !           390: time_t get_usec(void);                         /* return current usec */
        !           391: time_t get_midnight_ut_ms(void);               /* ms from UT midnight */
        !           392: __u16  cksum(__u16 *buf, int nwords);          /* compute 16bit checksum */
        !           393: void   inc_destparm(int sid);                  /* inc dst port or ttl */
        !           394: char   *get_hostname(char*);                   /* get host from addr */
        !           395: void   datafiller(char *p, int size);          /* fill data from file */
        !           396: void   data_handler(char *data, int data_size);/* handle data filling */
        !           397: void   socket_broadcast(int sd);               /* set SO_BROADCAST option */
        !           398: void   socket_iphdrincl(int sd);               /* set SO_IPHDRINCL option */
        !           399: void   listenmain(void);                       /* main for listen mode */
        !           400: char   *memstr(char *haystack, char *needle, int size); /* memstr */
        !           401: void   tos_help(void);                         /* show the TOS help */
        !           402: int    rtt(int *seqp, int recvport, float *ms_delay);  /* compute round trip time */
        !           403: int    relativize_id(int seqnum, int *ip_id);  /* compute relative id */
        !           404: int    if_promisc_on(int s);                   /* promisc. mode ON */
        !           405: int    if_promisc_off(int s);                  /* promisc. mode OFF */
        !           406: int    open_pcap(void);                        /* open libpcap socket */
        !           407: int    close_pcap(void);                       /* close libpcap socket */
        !           408: int    pcap_recv(char *, unsigned int);        /* libpcap api wrapper */
        !           409: int    memlock(char *addr, size_t size);       /* disable paging */
        !           410: int    memunlock(char *addr, size_t size);     /* enable paging */
        !           411: int    memlockall(void);                       /* disable paging (all pages) */
        !           412: int    memunlockall(void);                     /* enable paging (all pages) */
        !           413: unsigned char ip_opt_build(char *ip_opt);              /* build ip options */
        !           414: void   display_ipopt(char* buf);               /* display ip options */
        !           415: void   icmp_help(void);                        /* show the ICMP help */
        !           416: void   route_help(void);                       /* show the route help */
        !           417: void   (*Signal(int signo, void (*func)(int)))(int);
        !           418: void   delaytable_add(int seq, int src, time_t sec, time_t usec, int status);
        !           419: int    read_packet(void *packet, int size);
        !           420: void   scanmain(void);
        !           421: u_int32_t hp_rand(void);
        !           422: #if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && \
        !           423:     !defined(__bsdi__) && !defined(__APPLE__)
        !           424: size_t strlcpy(char *dst, const char *src, size_t siz);
        !           425: #endif
        !           426: 
        !           427: /* ARS glue */
        !           428: void hping_ars_send(char *s);
        !           429: 
        !           430: #endif /* _HPING2_H */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>