Changeset 68667ee


Ignore:
Timestamp:
02/23/05 11:45:44 (16 years ago)
Author:
Perry Lorier <perry@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
b06e535
Parents:
cb8c1b9
Message:

Merged in a whole heap of useful features

Location:
lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lib/libtrace.h

    r488432b r68667ee  
    248248struct libtrace_tcp *trace_get_tcp(struct libtrace_packet_t *packet);
    249249
     250/** get a pointer to the TCP header (if any) given a pointer to the IP header
     251 * @param ip            The IP header
     252 * @param[out] skipped  An output variable of the number of bytes skipped
     253 *
     254 * @returns a pointer to the TCP header, or NULL if this is not a TCP packet
     255 *
     256 * Skipped can be NULL, in which case it will be ignored by the program.
     257 *
     258 * @author Perry Lorier
     259 */
     260struct libtrace_tcp *trace_get_tcp_from_ip(struct libtrace_ip *ip,int *skipped);
     261
    250262/** get a pointer to the UDP header (if any)
    251263 * @param packet        the packet opaque pointer
     
    255267struct libtrace_udp *trace_get_udp(struct libtrace_packet_t *packet);
    256268
     269/** get a pointer to the UDP header (if any) given a pointer to the IP header
     270 * @param       ip      The IP header
     271 * @param[out]  skipped An output variable of the number of bytes skipped
     272 *
     273 * @returns a pointer to the UDP header, or NULL if this is not an UDP packet
     274 *
     275 * Skipped may be NULL, in which case it will be ignored by this function.
     276 */
     277struct libtrace_udp *trace_get_udp_from_ip(struct libtrace_ip *ip,int *skipped);
     278
    257279/** get a pointer to the ICMP header (if any)
    258280 * @param packet        the packet opaque pointer
     
    261283 */
    262284struct libtrace_icmp *trace_get_icmp(struct libtrace_packet_t *packet);
     285
     286/** get a pointer to the ICMP header (if any) given a pointer to the IP header
     287 * @param ip            The IP header
     288 * @param[out] skipped  An output variable of the number of bytes skipped
     289 *
     290 * @returns a pointer to the ICMP header, or NULL if this is not an ICMP packet
     291 *
     292 * Skipped may be NULL, in which case it will be ignored by this function
     293 */
     294struct libtrace_icmp *trace_get_icmp_from_ip(struct libtrace_ip *ip,int *skipped);
     295
     296/** parse an ip or tcp option
     297 * @param[in,out] ptr   the pointer to the current option
     298 * @param[in,out] len   the length of the remaining buffer
     299 * @param[out] type     the type of the option
     300 * @param[out] optlen   the length of the option
     301 * @param[out] data     the data of the option
     302 *
     303 * @returns bool true if there is another option (and the fields are filled in)
     304 *               or false if this was the last option.
     305 *
     306 * This updates ptr to point to the next option after this one, and updates
     307 * len to be the number of bytes remaining in the options area.  Type is updated
     308 * to be the code of this option, and data points to the data of this option,
     309 * with optlen saying how many bytes there are.
     310 *
     311 * @note Beware of fragmented packets.
     312 */
     313int trace_get_next_option(unsigned char **ptr,int *len,
     314                        unsigned char *type,
     315                        unsigned char *optlen,
     316                        unsigned char **data);
     317
    263318
    264319/** Get the current time in DAG time format
     
    269324 * @author Daniel Lawson
    270325 */
    271 uint64_t trace_get_erf_timestamp(struct libtrace_packet_t *packet);
     326uint64_t trace_get_erf_timestamp(const struct libtrace_packet_t *packet);
    272327
    273328/** Get the current time in struct timeval
     
    278333 * @author Perry Lorier
    279334 */
    280 struct timeval trace_get_timeval(struct libtrace_packet_t *packet);
     335struct timeval trace_get_timeval(const struct libtrace_packet_t *packet);
    281336
    282337/** Get the current time in floating point seconds
     
    286341 * @author Perry Lorier
    287342 */
    288 double trace_get_seconds(struct libtrace_packet_t *packet);
     343double trace_get_seconds(const struct libtrace_packet_t *packet);
    289344
    290345/** Get the size of the packet in the trace
     
    300355 */
    301356
    302 int trace_get_capture_length(struct libtrace_packet_t *packet);
     357int trace_get_capture_length(const struct libtrace_packet_t *packet);
    303358
    304359/** Get the size of the packet as it was seen on the wire.
     
    311366 */
    312367
    313 int trace_get_wire_length(struct libtrace_packet_t *packet);
     368int trace_get_wire_length(const struct libtrace_packet_t *packet);
    314369
    315370/** Link layer types
     
    330385 */
    331386
    332 inline libtrace_linktype_t trace_get_link_type(struct libtrace_packet_t *packet);
     387inline libtrace_linktype_t trace_get_link_type(const struct libtrace_packet_t *packet);
    333388
    334389/** Get the destination MAC addres
     
    338393 * @author Perry Lorier
    339394 */
    340 uint8_t *trace_get_destination_mac(struct libtrace_packet_t *packet);
     395uint8_t *trace_get_destination_mac(const struct libtrace_packet_t *packet);
    341396
    342397/** Get the source MAC addres
     
    345400 * @author Perry Lorier
    346401 */
    347 uint8_t *trace_get_source_mac(struct libtrace_packet_t *packet);
     402uint8_t *trace_get_source_mac(const, struct libtrace_packet_t *packet);
    348403
    349404/** Truncate the packet at the suggested length
     
    369424 * @author Daniel Lawson
    370425 */
    371 int8_t trace_get_direction(struct libtrace_packet_t *packet);
     426int8_t trace_get_direction(const struct libtrace_packet_t *packet);
    372427
    373428/** Event types */
     
    378433} libtrace_event_t;
    379434
     435/** structure returned by libtrace_event explaining what the current event is */
    380436struct libtrace_eventobj_t {
    381         libtrace_event_t type;
    382         int fd;
    383         double seconds;
     437        libtrace_event_t type; /**< event type (iowait,sleep,packet */
     438        int fd;                /**< if IOWAIT, the fd to sleep on */
     439        double seconds;        /**< if SLEEP, the amount of time to sleep for */
    384440};
    385441
  • lib/trace.c

    r850630f r68667ee  
    3737 * @author Perry Lorier
    3838 *
     39 * @internal
    3940 */
    4041#define _GNU_SOURCE
     
    129130
    130131#if HAVE_BPF
     132/** A type encapsulating a bpf filter
     133 * This type covers the compiled bpf filter, as well as the original filter
     134 * string
     135 *
     136 */
    131137struct libtrace_filter_t {
    132138        struct bpf_insn *filter;
     
    135141#endif
    136142
     143/** The information about traces that are open
     144 * @internal
     145 */
    137146struct libtrace_t {
    138         format_t format;
    139         source_t sourcetype;
     147        format_t format;        /**< The format that this trace is in */
     148        source_t sourcetype;    /**< The type (device,file, etc */
    140149        union {
     150                /** Information about rtclients */
    141151                struct {
    142152                        char *hostname;
    143153                        short port;
    144154                } rt;
    145                 char *path;
    146                 char *interface;
     155                char *path;             /**< information for local sockets */
     156                char *interface;        /**< intormation for reading of network
     157                                             interfaces */
    147158        } conn_info;
     159        /** Information about the current state of the input device */
    148160        union {
    149161                int fd;
     
    925937}
    926938
     939/** get a pointer to the TCP header (if any) given a pointer to the IP header
     940 * @param ip            The IP header
     941 * @param[out] skipped  An output variable of the number of bytes skipped
     942 *
     943 * @returns a pointer to the TCP header, or NULL if this is not a TCP packet
     944 *
     945 * Skipped can be NULL, in which case it will be ignored by the program.
     946 */
     947struct libtrace_tcp *get_tcp_from_ip(struct libtrace_ip *ip, int *skipped)
     948{
     949#define SW_IP_OFFMASK 0xff1f
     950        struct libtrace_tcp *tcpptr = 0;
     951
     952        if ((ip->ip_p == 6) && ((ip->ip_off & SW_IP_OFFMASK) == 0))  {
     953                tcpptr = (struct libtrace_tcp *)((ptrdiff_t)ip+ (ip->ip_hl * 4));
     954        }
     955
     956        if (skipped)
     957                *skipped=(ip->ip_hl*4);
     958
     959        return tcpptr;
     960}
     961
    927962/** get a pointer to the UDP header (if any)
    928963 * @param packet        a pointer to a libtrace_packet structure
     
    940975                udpptr = (struct libtrace_udp *)((ptrdiff_t)ipptr + (ipptr->ip_hl * 4));
    941976        }
     977
    942978        return udpptr;
    943979}
     980
     981/** get a pointer to the UDP header (if any) given a pointer to the IP header
     982 * @param ip            The IP header
     983 * @param[out] skipped  An output variable of the number of bytes skipped
     984 *
     985 * @returns a pointer to the UDP header, or NULL if this is not a UDP packet
     986 *
     987 * Skipped can be NULL, in which case it will be ignored by the program.
     988 */
     989struct libtrace_udp *get_udp_from_ip(struct libtrace_ip *ip, int *skipped)
     990{
     991        struct libtrace_udp *udpptr = 0;
     992
     993        if ((ip->ip_p == 6) && ((ip->ip_off & SW_IP_OFFMASK) == 0))  {
     994                udpptr = (struct libtrace_udp *)((ptrdiff_t)ip+ (ip->ip_hl * 4));
     995        }
     996
     997        if (skipped)
     998                *skipped=(ip->ip_hl*4);
     999
     1000        return udpptr;
     1001}
     1002
    9441003
    9451004/** get a pointer to the ICMP header (if any)
     
    9601019        return icmpptr;
    9611020}
     1021
     1022/** get a pointer to the ICMP header (if any) given a pointer to the IP header
     1023 * @param ip            The IP header
     1024 * @param[out] skipped  An output variable of the number of bytes skipped
     1025 *
     1026 * @returns a pointer to the ICMP header, or NULL if this is not a ICMP packet
     1027 *
     1028 * Skipped can be NULL, in which case it will be ignored by the program.
     1029 */
     1030struct libtrace_icmp *get_icmp_from_ip(struct libtrace_ip *ip, int *skipped)
     1031{
     1032        struct libtrace_icmp *icmpptr = 0;
     1033
     1034        if ((ip->ip_p == 6) && ((ip->ip_off & SW_IP_OFFMASK) == 0))  {
     1035                icmpptr = (struct libtrace_icmp *)((ptrdiff_t)ip+ (ip->ip_hl * 4));
     1036        }
     1037
     1038        if (skipped)
     1039                *skipped=(ip->ip_hl*4);
     1040
     1041        return icmpptr;
     1042}
     1043/** parse an ip or tcp option
     1044 * @param[in,out] ptr   the pointer to the current option
     1045 * @param[in,out] len   the length of the remaining buffer
     1046 * @param[out] type     the type of the option
     1047 * @param[out] optlen   the length of the option
     1048 * @param[out] data     the data of the option
     1049 *
     1050 * @returns bool true if there is another option (and the fields are filled in)
     1051 *               or false if this was the last option.
     1052 *
     1053 * This updates ptr to point to the next option after this one, and updates
     1054 * len to be the number of bytes remaining in the options area.  Type is updated
     1055 * to be the code of this option, and data points to the data of this option,
     1056 * with optlen saying how many bytes there are.
     1057 *
     1058 * @note Beware of fragmented packets.
     1059 * @author Perry Lorier
     1060 */
     1061int trace_get_next_option(unsigned char **ptr,int *len,
     1062                        unsigned char *type,
     1063                        unsigned char *optlen,
     1064                        unsigned char **data)
     1065{
     1066        if (*len<=0)
     1067                return 0;
     1068        *type=**ptr;
     1069        switch(*type) {
     1070                case 0: /* End of options */
     1071                        return 0;
     1072                case 1: /* Pad */
     1073                        (*ptr)++;
     1074                        (*len)--;
     1075                        return 1;
     1076                default:
     1077                        *optlen = *(*ptr+1);
     1078                        if (*optlen<2)
     1079                                return 0; // I have no idea wtf is going on
     1080                                          // with these packets
     1081                        (*len)-=*optlen;
     1082                        (*data)=(*ptr+2);
     1083                        (*ptr)+=*optlen;
     1084                        if (*len<0)
     1085                                return 0;
     1086                        return 1;
     1087        }
     1088        assert(0);
     1089}
     1090
    9621091
    9631092/** Get the current time in DAG time format
     
    12441373 * @param packet the libtrace_packet opaque pointer
    12451374 * @returns
    1246  *  TRACE_EVENT_IOWAIT  Waiting on I/O on <fd>
    1247  *  TRACE_EVENT_SLEEP   Next event in <seconds>
    1248  *  TRACE_EVENT_PACKET  Packet arrived in <buffer> with size <size>
     1375 *  TRACE_EVENT_IOWAIT  Waiting on I/O on fd
     1376 *  TRACE_EVENT_SLEEP   Next event in seconds
     1377 *  TRACE_EVENT_PACKET  Packet arrived in buffer with size size
    12491378 * FIXME currently keeps a copy of the packet inside the trace pointer,
    12501379 * which in turn is stored inside the new packet object...
Note: See TracChangeset for help on using the changeset viewer.