Annotation of embedaddon/trafshow/netstat.h, revision 1.1.1.1

1.1       misho       1: /*
                      2:  *     Copyright (c) 2004 Rinet Corp., Novosibirsk, Russia
                      3:  *
                      4:  * Redistribution and use in source forms, with and without modification,
                      5:  * are permitted provided that this entire comment appears intact.
                      6:  *
                      7:  * THIS SOURCE CODE IS PROVIDED ``AS IS'' WITHOUT ANY WARRANTIES OF ANY KIND.
                      8:  */
                      9: 
                     10: #ifndef        _NETSTAT_H_
                     11: #define        _NETSTAT_H_
                     12: 
                     13: #include <sys/types.h>
                     14: #include <sys/time.h>
                     15: #ifdef linux
                     16: #include <linux/if.h>
                     17: #else
                     18: #include <net/if.h>
                     19: #endif
                     20: #include <netinet/in.h>
                     21: #include <netinet/if_ether.h>
                     22: 
                     23: #ifndef        IPPORT_RESERVED
                     24: #define        IPPORT_RESERVED 1024
                     25: #endif
                     26: #ifndef        IPPORT_DYNAMIC
                     27: #define        IPPORT_DYNAMIC  49152
                     28: #endif
                     29: 
                     30: /*
                     31:  * Any struct defined here is a storage contained all data.
                     32:  */
                     33: 
                     34: /*
                     35:  * Internet flow record address.
                     36:  */
                     37: struct ip_address {
                     38:        union {
                     39:                struct in_addr ipa4;
                     40: #ifdef INET6
                     41:                struct in6_addr ipa6;
                     42: #endif
                     43:        } ipaddr;
                     44:        u_int16_t ip_port;
                     45: };
                     46: 
                     47: #define        ip_addr         ipaddr.ipa4
                     48: #ifdef INET6
                     49: #define        ip6_addr        ipaddr.ipa6
                     50: #endif
                     51: 
                     52: /*
                     53:  * Internet flow record header.
                     54:  */
                     55: struct internet_header {
                     56:        u_int8_t ver;                   /* ip version */
                     57:        u_int8_t proto;                 /* ip protocol */
                     58:        struct ip_address src;          /* source ip address */
                     59:        struct ip_address dst;          /* destination ip address */
                     60: };
                     61: 
                     62: #ifndef        ETHER_ADDR_LEN
                     63: #ifdef HAVE_ETHER_ADDR
                     64: #define        ETHER_ADDR_LEN  sizeof(struct ether_addr)
                     65: #else
                     66: #define        ETHER_ADDR_LEN  6
                     67: #endif
                     68: #endif
                     69: 
                     70: /*
                     71:  * Ethernet flow record header.
                     72:  */
                     73: struct ethernet_header {
                     74:        u_char src[ETHER_ADDR_LEN];     /* source ether address */
                     75:        u_char dst[ETHER_ADDR_LEN];     /* destination ether address */
                     76:        u_int16_t type;                 /* ether type */
                     77:        union {
                     78:                u_int16_t tag;          /* ether dot1q tag */
                     79:                struct {                /* IEEE 802.3 LLC header */
                     80:                        u_char ssap;    /* source SAP ID */
                     81:                        u_char dsap;    /* destination SAP ID */
                     82:                } llc;
                     83:        } param;
                     84: };
                     85: 
                     86: #define        ETH_VIDOFTAG(tag)       ((tag) & 0xfff)
                     87: #define        ETH_PRIOFTAG(tag)       (((tag) >> 13) & 7)
                     88: #define        ETH_CFIOFTAG(tag)       (((tag) >> 12) & 1)
                     89: 
                     90: struct netstat_header {
                     91:        struct ethernet_header en_hdr;  /* ether flow record header */
                     92:        struct internet_header in_hdr;  /* inet flow record header */
                     93: };
                     94: 
                     95: typedef        struct netstat {
                     96:        /* all header fields in network byte order */
                     97:        struct netstat_header ns_hdr; /* must be first in struct netstat! */
                     98: 
                     99: #define        eth_src_addr    ns_hdr.en_hdr.src
                    100: #define        eth_dst_addr    ns_hdr.en_hdr.dst
                    101: #define        eth_type        ns_hdr.en_hdr.type
                    102: #define        eth_tag         ns_hdr.en_hdr.param.tag
                    103: #define        eth_ssap        ns_hdr.en_hdr.param.llc.ssap
                    104: #define        eth_dsap        ns_hdr.en_hdr.param.llc.dsap
                    105: 
                    106: #define        ip_ver          ns_hdr.in_hdr.ver
                    107: #define        ip_proto        ns_hdr.in_hdr.proto
                    108: #define        ip_src_addr     ns_hdr.in_hdr.src
                    109: #define        ip_dst_addr     ns_hdr.in_hdr.dst
                    110: 
                    111:        /* all data fields in host byte order */
                    112:        struct timeval mtime;           /* last modification time */
                    113: 
                    114:        u_int32_t pkt_cnt;              /* packet counter */
                    115:        u_int32_t pkt_len;              /* length of ip packet */
                    116:        u_int32_t data_len;             /* length of ip data */
                    117: 
                    118:        u_int32_t gain_pkt_cnt;
                    119:        u_int32_t gain_pkt_len;
                    120:        u_int32_t gain_data_len;
                    121: 
                    122:        u_int32_t pkt_cnt_rate;         /* rate of packet counter */
                    123:        u_int32_t pkt_len_rate;         /* rate of packet length */
                    124:        u_int32_t data_len_rate;        /* rate of data length */
                    125: 
                    126:        int attr;                       /* curses video attributes */
                    127: 
                    128: } NETSTAT;
                    129: 
                    130: 
                    131: struct pcap_handler;
                    132: void netstat_aggregate(struct netstat_header *nh, int bits);
                    133: int netstat_count(const struct pcap_handler *ph);
                    134: int netstat_insert(struct pcap_handler *ph, const NETSTAT *ns);
                    135: int netstat_find(struct pcap_handler *ph, NETSTAT *ns);
                    136: int netstat_purge(struct pcap_handler *ph, const struct timeval *at);
                    137: void netstat_free(struct pcap_handler *ph);
                    138: int netstat_match(const NETSTAT *ns1, const NETSTAT *ns2);
                    139: int netstat_bidir(const NETSTAT *ns1, const NETSTAT *ns2);
                    140: int netstat_fetch(NETSTAT **list[], struct pcap_handler *ph);
                    141: 
                    142: #endif /* !_NETSTAT_H_ */

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