pkt.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * pkt.h
  3. *
  4. * Copyright (c) 2001 Dug Song <dugsong@monkey.org>
  5. *
  6. * $Id$
  7. */
  8. #ifndef PKT_H
  9. #define PKT_H
  10. #include "config.h"
  11. #include "lib/queue.h"
  12. #include "defines.h"
  13. #include <sys/time.h>
  14. #ifdef HAVE_LIBDNET
  15. /* need to undef these which are pulled in via defines.h, prior to importing dnet.h */
  16. #undef icmp_id
  17. #undef icmp_seq
  18. #undef icmp_data
  19. #undef icmp_mask
  20. #ifdef HAVE_DNET_H
  21. #include <dnet.h>
  22. #endif
  23. #ifdef HAVE_DUMBNET_H
  24. #include <dumbnet.h>
  25. #endif
  26. #endif
  27. #define PKT_BUF_LEN (ETH_HDR_LEN + ETH_MTU)
  28. #define PKT_BUF_ALIGN 2
  29. struct pkt {
  30. struct timeval pkt_ts;
  31. struct eth_hdr *pkt_eth;
  32. union {
  33. u_char *eth_data;
  34. struct ip_hdr *ip;
  35. struct ip6_hdr *ip6;
  36. } pkt_n_hdr_u;
  37. union {
  38. u_char *ip_data;
  39. struct icmp_hdr *icmp;
  40. struct tcp_hdr *tcp;
  41. struct udp_hdr *udp;
  42. } pkt_t_hdr_u;
  43. union {
  44. u_char *t_data;
  45. union icmp_msg *icmp;
  46. } pkt_t_data_u;
  47. u_char *pkt_buf;
  48. size_t pkt_buf_size;
  49. u_char *pkt_data;
  50. u_char *pkt_end;
  51. TAILQ_ENTRY(pkt) pkt_next;
  52. };
  53. #define pkt_ip pkt_n_hdr_u.ip
  54. #define pkt_ip6 pkt_n_hdr_u.ip6
  55. #define pkt_eth_data pkt_n_hdr_u.eth_data
  56. #define pkt_icmp pkt_t_hdr_u.icmp
  57. #define pkt_tcp pkt_t_hdr_u.tcp
  58. #define pkt_udp pkt_t_hdr_u.udp
  59. #define pkt_ip_data pkt_t_hdr_u.ip_data
  60. #define pkt_tcp_data pkt_t_data_u.t_data
  61. #define pkt_udp_data pkt_t_data_u.t_data
  62. #define pkt_icmp_msg pkt_t_data_u.icmp
  63. TAILQ_HEAD(pktq, pkt);
  64. void pkt_init(int size);
  65. void pkt_close(void);
  66. struct pkt *pkt_new(size_t len);
  67. struct pkt *pkt_dup(struct pkt *);
  68. void pkt_decorate(struct pkt *pkt);
  69. void pkt_free(struct pkt *pkt);
  70. void pktq_reverse(struct pktq *pktq);
  71. void pktq_shuffle(rand_t *r, struct pktq *pktq);
  72. struct pkt *pktq_random(rand_t *r, struct pktq *pktq);
  73. #endif /* PKT_H */