pkt.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * pkt.h
  3. *
  4. * Copyright (c) 2001 Dug Song <dugsong@monkey.org>
  5. *
  6. * $Id: pkt.h 2035 2008-05-19 05:35:24Z aturner $
  7. */
  8. #ifndef PKT_H
  9. #define PKT_H
  10. #include "config.h"
  11. #include "defines.h"
  12. #include "../../lib/queue.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. #include <dnet.h>
  21. #endif
  22. #define PKT_BUF_LEN (ETH_HDR_LEN + ETH_MTU)
  23. #define PKT_BUF_ALIGN 2
  24. struct pkt {
  25. struct timeval pkt_ts;
  26. // struct event pkt_ev;
  27. struct eth_hdr *pkt_eth;
  28. union {
  29. u_char *eth_data;
  30. struct ip_hdr *ip;
  31. } pkt_n_hdr_u;
  32. union {
  33. u_char *ip_data;
  34. struct icmp_hdr *icmp;
  35. struct tcp_hdr *tcp;
  36. struct udp_hdr *udp;
  37. } pkt_t_hdr_u;
  38. union {
  39. u_char *t_data;
  40. union icmp_msg *icmp;
  41. } pkt_t_data_u;
  42. u_char pkt_buf[PKT_BUF_ALIGN + PKT_BUF_LEN];
  43. u_char *pkt_data;
  44. u_char *pkt_end;
  45. TAILQ_ENTRY(pkt) pkt_next;
  46. };
  47. #define pkt_ip pkt_n_hdr_u.ip
  48. #define pkt_eth_data pkt_n_hdr_u.eth_data
  49. #define pkt_icmp pkt_t_hdr_u.icmp
  50. #define pkt_tcp pkt_t_hdr_u.tcp
  51. #define pkt_udp pkt_t_hdr_u.udp
  52. #define pkt_ip_data pkt_t_hdr_u.ip_data
  53. #define pkt_tcp_data pkt_t_data_u.t_data
  54. #define pkt_udp_data pkt_t_data_u.t_data
  55. #define pkt_icmp_msg pkt_t_data_u.icmp
  56. TAILQ_HEAD(pktq, pkt);
  57. void pkt_init(int size);
  58. struct pkt *pkt_new(void);
  59. struct pkt *pkt_dup(struct pkt *);
  60. void pkt_decorate(struct pkt *pkt);
  61. void pkt_free(struct pkt *pkt);
  62. void pktq_reverse(struct pktq *pktq);
  63. void pktq_shuffle(rand_t *r, struct pktq *pktq);
  64. struct pkt *pktq_random(rand_t *r, struct pktq *pktq);
  65. #endif /* PKT_H */