pkt.h 1.7 KB

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