Changeset 58e9e02 for lib/trace.c
- Timestamp:
- 04/28/05 15:22:40 (17 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:
- a6badc2
- Parents:
- 48cfaed
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/trace.c
r808a478 r58e9e02 925 925 * @returns a pointer to the IP header, or NULL if there is not an IP packet 926 926 */ 927 struct libtrace_ip *trace_get_ip( struct libtrace_packet_t *packet) {927 struct libtrace_ip *trace_get_ip(const struct libtrace_packet_t *packet) { 928 928 struct libtrace_ip *ipptr = 0; 929 929 … … 1019 1019 * @returns a pointer to the TCP header, or NULL if there is not a TCP packet 1020 1020 */ 1021 struct libtrace_tcp *trace_get_tcp( struct libtrace_packet_t *packet) {1021 struct libtrace_tcp *trace_get_tcp(const struct libtrace_packet_t *packet) { 1022 1022 struct libtrace_tcp *tcpptr = 0; 1023 1023 struct libtrace_ip *ipptr = 0; … … 1040 1040 * Skipped can be NULL, in which case it will be ignored by the program. 1041 1041 */ 1042 struct libtrace_tcp *get_tcp_from_ip( struct libtrace_ip *ip, int *skipped)1042 struct libtrace_tcp *get_tcp_from_ip(const struct libtrace_ip *ip, int *skipped) 1043 1043 { 1044 1044 #define SW_IP_OFFMASK 0xff1f … … 1060 1060 * @returns a pointer to the UDP header, or NULL if this is not a UDP packet 1061 1061 */ 1062 struct libtrace_udp *trace_get_udp( struct libtrace_packet_t *packet) {1062 struct libtrace_udp *trace_get_udp(const struct libtrace_packet_t *packet) { 1063 1063 struct libtrace_udp *udpptr = 0; 1064 1064 struct libtrace_ip *ipptr = 0; … … 1082 1082 * Skipped can be NULL, in which case it will be ignored by the program. 1083 1083 */ 1084 struct libtrace_udp *get_udp_from_ip( struct libtrace_ip *ip, int *skipped)1084 struct libtrace_udp *get_udp_from_ip(const struct libtrace_ip *ip, int *skipped) 1085 1085 { 1086 1086 struct libtrace_udp *udpptr = 0; … … 1102 1102 * @returns a pointer to the ICMP header, or NULL if this is not a ICMP packet 1103 1103 */ 1104 struct libtrace_icmp *trace_get_icmp( struct libtrace_packet_t *packet) {1104 struct libtrace_icmp *trace_get_icmp(const struct libtrace_packet_t *packet) { 1105 1105 struct libtrace_icmp *icmpptr = 0; 1106 1106 struct libtrace_ip *ipptr = 0; … … 1621 1621 */ 1622 1622 int trace_bpf_filter(struct libtrace_filter_t *filter, 1623 struct libtrace_packet_t *packet) {1623 const struct libtrace_packet_t *packet) { 1624 1624 #if HAVE_BPF 1625 1625 void *linkptr = 0; … … 1765 1765 } 1766 1766 1767 struct ports_t { 1768 uint16_t src; 1769 uint16_t dst; 1770 }; 1771 1772 /* Return the client port 1773 */ 1774 uint16_t trace_get_source_port(const struct libtrace_packet_t *packet) 1775 { 1776 struct libtrace_ip *ip = trace_get_ip(packet); 1777 if (6 != ip->ip_p 1778 && 17 != ip->ip_p) 1779 return 0; 1780 if (0 != (ip->ip_off & SW_IP_OFFMASK)) 1781 return 0; 1782 1783 struct ports_t *port; 1784 port = (struct ports_t *)((ptrdiff_t)ip + (ip->ip_hl * 4)); 1785 1786 return htons(port->src); 1787 } 1788 1789 /* Same as get_source_port except use the destination port */ 1790 uint16_t trace_get_destination_port(const struct libtrace_packet_t *packet) 1791 { 1792 struct libtrace_ip *ip = trace_get_ip(packet); 1793 1794 if (6 != ip->ip_p 1795 && 17 != ip->ip_p) 1796 return 0; 1797 1798 if (0 != (ip->ip_off & SW_IP_OFFMASK)) 1799 return 0; 1800 1801 struct ports_t *port; 1802 port = (struct ports_t *)((ptrdiff_t)ip + (ip->ip_hl * 4)); 1803 1804 return htons(port->dst); 1805 } 1806 1767 1807 #define ROOT_SERVER(x) ((x) < 512) 1768 1808 #define ROOT_CLIENT(x) ((512 <= (x)) && ((x) < 1024)) … … 1772 1812 #define SERVER(x) ROOT_SERVER(x) || NONROOT_SERVER(x) 1773 1813 #define CLIENT(x) ROOT_CLIENT(x) || NONROOT_CLIENT(x) 1774 1775 1814 1776 1815 /* Attempt to deduce the 'server' port
Note: See TracChangeset
for help on using the changeset viewer.