Changeset 58e9e02
- 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
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
ChangeLog
r48cfaed r58e9e02 33 33 * Fixed a bug in the event api where it would die instantly 34 34 for offline traces. 35 * Added trace_get_{source,destination}_port 36 * Added some constification fixes 35 37 36 38 - Version 2.0.15b -
lib/libtrace.h
r7bb7dda r58e9e02 34 34 #include <sys/types.h> 35 35 #include <netinet/in.h> 36 37 /** API version as 3 byte hex digits */ 38 #define LIBTRACE_API_VERSION 0x010010 36 39 37 40 #ifdef __cplusplus … … 239 242 * @returns a pointer to the IP header, or NULL if there is not an IP packet 240 243 */ 241 struct libtrace_ip *trace_get_ip( struct libtrace_packet_t *packet);244 struct libtrace_ip *trace_get_ip(const struct libtrace_packet_t *packet); 242 245 243 246 /** get a pointer to the TCP header (if any) … … 246 249 * @returns a pointer to the TCP header, or NULL if there is not a TCP packet 247 250 */ 248 struct libtrace_tcp *trace_get_tcp( struct libtrace_packet_t *packet);251 struct libtrace_tcp *trace_get_tcp(const struct libtrace_packet_t *packet); 249 252 250 253 /** get a pointer to the TCP header (if any) given a pointer to the IP header … … 265 268 * @returns a pointer to the UDP header, or NULL if this is not a UDP packet 266 269 */ 267 struct libtrace_udp *trace_get_udp( struct libtrace_packet_t *packet);270 struct libtrace_udp *trace_get_udp(const struct libtrace_packet_t *packet); 268 271 269 272 /** get a pointer to the UDP header (if any) given a pointer to the IP header … … 282 285 * @returns a pointer to the ICMP header, or NULL if this is not a ICMP packet 283 286 */ 284 struct libtrace_icmp *trace_get_icmp( struct libtrace_packet_t *packet);287 struct libtrace_icmp *trace_get_icmp(const struct libtrace_packet_t *packet); 285 288 286 289 /** get a pointer to the ICMP header (if any) given a pointer to the IP header … … 479 482 */ 480 483 int trace_bpf_filter(struct libtrace_filter_t *filter, 481 struct libtrace_packet_t *packet);484 const struct libtrace_packet_t *packet); 482 485 483 486 484 487 typedef enum {USE_DEST, USE_SOURCE} serverport_t; 488 489 /** Get the source port 490 * @param packet the packet to read from 491 * @returns a port in \em HOST byte order, or equivilent to ports for this 492 * protocol, or 0 if this protocol has no ports. 493 * @author Perry Lorier 494 */ 495 uint16_t trace_get_source_port(const struct libtrace_packet_t *); 496 497 /** Get the destination port 498 * @param packet the packet to read from 499 * @returns a port in \em HOST byte order, or equivilent to ports for this 500 * protocol, or 0 if this protocol has no ports. 501 * @author Perry Lorier 502 */ 503 uint16_t trace_get_destination_port(const struct libtrace_packet_t *); 485 504 486 505 /** hint at the server port in specified protocol -
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.