pkt.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * pkt.h
  3. *
  4. * Copyright (c) 2001 Dug Song <dugsong@monkey.org>
  5. *
  6. * $Id: pkt.h 2000 2008-04-27 06:17:35Z 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. /* need to undef these which are pulled in via defines.h prior to import dnet.h */
  15. #undef icmp_id
  16. #undef icmp_seq
  17. #undef icmp_data
  18. #undef icmp_mask
  19. #include <dnet.h>
  20. // #include <event.h>
  21. #define PKT_BUF_LEN (ETH_HDR_LEN + ETH_MTU)
  22. #define PKT_BUF_ALIGN 2
  23. struct pkt {
  24. struct timeval pkt_ts;
  25. // struct event pkt_ev;
  26. struct eth_hdr *pkt_eth;
  27. union {
  28. u_char *eth_data;
  29. struct ip_hdr *ip;
  30. } pkt_n_hdr_u;
  31. union {
  32. u_char *ip_data;
  33. struct icmp_hdr *icmp;
  34. struct tcp_hdr *tcp;
  35. struct udp_hdr *udp;
  36. } pkt_t_hdr_u;
  37. union {
  38. u_char *t_data;
  39. union icmp_msg *icmp;
  40. } pkt_t_data_u;
  41. u_char pkt_buf[PKT_BUF_ALIGN + PKT_BUF_LEN];
  42. u_char *pkt_data;
  43. u_char *pkt_end;
  44. TAILQ_ENTRY(pkt) pkt_next;
  45. };
  46. #define pkt_ip pkt_n_hdr_u.ip
  47. #define pkt_eth_data pkt_n_hdr_u.eth_data
  48. #define pkt_icmp pkt_t_hdr_u.icmp
  49. #define pkt_tcp pkt_t_hdr_u.tcp
  50. #define pkt_udp pkt_t_hdr_u.udp
  51. #define pkt_ip_data pkt_t_hdr_u.ip_data
  52. #define pkt_tcp_data pkt_t_data_u.t_data
  53. #define pkt_udp_data pkt_t_data_u.t_data
  54. #define pkt_icmp_msg pkt_t_data_u.icmp
  55. TAILQ_HEAD(pktq, pkt);
  56. void pkt_init(int size);
  57. struct pkt *pkt_new(void);
  58. struct pkt *pkt_dup(struct pkt *);
  59. void pkt_decorate(struct pkt *pkt);
  60. void pkt_free(struct pkt *pkt);
  61. void pktq_reverse(struct pktq *pktq);
  62. void pktq_shuffle(rand_t *r, struct pktq *pktq);
  63. struct pkt *pktq_random(rand_t *r, struct pktq *pktq);
  64. #endif /* PKT_H */