Changeset 9c87732 for lib/trace.c
- Timestamp:
- 12/15/05 15:37:19 (16 years ago)
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/trace.c
r7c9b99b r9c87732 720 720 #define SW_IP_OFFMASK 0xff1f 721 721 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 */ 727 void *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 */ 750 void *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 722 763 /* get a pointer to the TCP header (if any) 723 764 * @param packet a pointer to a libtrace_packet structure … … 732 773 return 0; 733 774 } 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); 736 777 } 737 778 return tcpptr; … … 751 792 struct libtrace_tcp *tcpptr = 0; 752 793 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 } 759 797 760 798 return tcpptr; … … 773 811 return 0; 774 812 } 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); 777 815 } 778 816 … … 792 830 struct libtrace_udp *udpptr = 0; 793 831 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 } 800 835 801 836 return udpptr; … … 815 850 return 0; 816 851 } 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); 819 854 } 820 855 return icmpptr; … … 833 868 struct libtrace_icmp *icmpptr = 0; 834 869 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 } 841 873 842 874 return icmpptr;
Note: See TracChangeset
for help on using the changeset viewer.