Changeset 9c87732 for lib/trace.c


Ignore:
Timestamp:
12/15/05 15:37:19 (16 years ago)
Author:
Shane Alcock <salcock@…>
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:
5baec88
Parents:
d56089a
Message:

Added trace_get_transport and trace_get_transport_from_ip functions to
do generic transport layer header grabbing.
Changed all the various get_tcp, get_udp and get_icmp functions to
act as wrappers around trace_get_transport_from_ip.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/trace.c

    r7c9b99b r9c87732  
    720720#define SW_IP_OFFMASK 0xff1f
    721721
     722/* Gets a pointer to the transport layer header (if any)
     723 * @param packet        a pointer to a libtrace_packet structure
     724 *
     725 * @returns a pointer to the transport layer header, or NULL if there is no header
     726 */
     727void *trace_get_transport(const struct libtrace_packet_t *packet) {
     728        void *trans_ptr = 0;
     729        struct libtrace_ip *ipptr = 0;
     730
     731        if (!(ipptr = trace_get_ip(packet))) {
     732                return 0;
     733        }
     734
     735        if ((ipptr->ip_off & SW_IP_OFFMASK) == 0) {
     736                trans_ptr = (void *)((ptrdiff_t)ipptr + (ipptr->ip_hl * 4));
     737        }
     738        return trans_ptr;
     739}
     740
     741/* Gets a pointer to the transport layer header (if any) given a pointer to the
     742 * IP header
     743 * @param ip            The IP Header
     744 * @param[out] skipped  An output variable of the number of bytes skipped
     745 *
     746 * @returns a pointer to the transport layer header, or NULL if there is no header
     747 *
     748 * Skipped can be NULL, in which case it will be ignored
     749 */
     750void *trace_get_transport_from_ip(const struct libtrace_ip *ip, int *skipped) {
     751        void *trans_ptr = 0;   
     752
     753        if ((ip->ip_off & SW_IP_OFFMASK) == 0) {
     754                trans_ptr = (void *)((ptrdiff_t)ip + (ip->ip_hl * 4));
     755        }
     756
     757        if (skipped)
     758                *skipped = (ip->ip_hl*4);
     759
     760        return trans_ptr;
     761}
     762
    722763/* get a pointer to the TCP header (if any)
    723764 * @param packet        a pointer to a libtrace_packet structure
     
    732773                return 0;
    733774        }
    734         if ((ipptr->ip_p == 6) && ((ipptr->ip_off & SW_IP_OFFMASK) == 0)) {
    735                 tcpptr = (struct libtrace_tcp *)((ptrdiff_t)ipptr + (ipptr->ip_hl * 4));
     775        if (ipptr->ip_p == 6) {
     776                tcpptr = (struct libtrace_tcp *)trace_get_transport_from_ip(ipptr, 0);
    736777        }
    737778        return tcpptr;
     
    751792        struct libtrace_tcp *tcpptr = 0;
    752793
    753         if ((ip->ip_p == 6) && ((ip->ip_off & SW_IP_OFFMASK) == 0))  {
    754                 tcpptr = (struct libtrace_tcp *)((ptrdiff_t)ip+ (ip->ip_hl * 4));
    755         }
    756 
    757         if (skipped)
    758                 *skipped=(ip->ip_hl*4);
     794        if (ip->ip_p == 6)  {
     795                tcpptr = (struct libtrace_tcp *)trace_get_transport_from_ip(ip, skipped);
     796        }
    759797
    760798        return tcpptr;
     
    773811                return 0;
    774812        }
    775         if ((ipptr->ip_p == 17) && ((ipptr->ip_off & SW_IP_OFFMASK) == 0)) {
    776                 udpptr = (struct libtrace_udp *)((ptrdiff_t)ipptr + (ipptr->ip_hl * 4));
     813        if (ipptr->ip_p == 17) {
     814                udpptr = (struct libtrace_udp *)trace_get_transport_from_ip(ipptr, 0);
    777815        }
    778816
     
    792830        struct libtrace_udp *udpptr = 0;
    793831
    794         if ((ip->ip_p == 17) && ((ip->ip_off & SW_IP_OFFMASK) == 0))  {
    795                 udpptr = (struct libtrace_udp *)((ptrdiff_t)ip+ (ip->ip_hl * 4));
    796         }
    797 
    798         if (skipped)
    799                 *skipped=(ip->ip_hl*4);
     832        if (ip->ip_p == 17) {
     833                udpptr = (struct libtrace_udp *)trace_get_transport_from_ip(ip, skipped);
     834        }
    800835
    801836        return udpptr;
     
    815850                return 0;
    816851        }
    817         if ((ipptr->ip_p == 1)&& ((ipptr->ip_off & SW_IP_OFFMASK) == 0 )){
    818                 icmpptr = (struct libtrace_icmp *)((ptrdiff_t)ipptr + (ipptr->ip_hl * 4));
     852        if (ipptr->ip_p == 1){
     853                icmpptr = (struct libtrace_icmp *)trace_get_transport_from_ip(ipptr, 0);
    819854        }
    820855        return icmpptr;
     
    833868        struct libtrace_icmp *icmpptr = 0;
    834869
    835         if ((ip->ip_p == 6) && ((ip->ip_off & SW_IP_OFFMASK) == 0))  {
    836                 icmpptr = (struct libtrace_icmp *)((ptrdiff_t)ip+ (ip->ip_hl * 4));
    837         }
    838 
    839         if (skipped)
    840                 *skipped=(ip->ip_hl*4);
     870        if (ip->ip_p == 1)  {
     871                icmpptr = (struct libtrace_icmp *)trace_get_transport_from_ip(ip, skipped);
     872        }
    841873
    842874        return icmpptr;
Note: See TracChangeset for help on using the changeset viewer.