ipv4_proto.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * @file ipv4_proto.h
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * This file is part of BadVPN.
  8. *
  9. * BadVPN is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2
  11. * as published by the Free Software Foundation.
  12. *
  13. * BadVPN is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. *
  22. * @section DESCRIPTION
  23. *
  24. * Definitions for the IPv4 protocol.
  25. */
  26. #ifndef BADVPN_MISC_IPV4_PROTO_H
  27. #define BADVPN_MISC_IPV4_PROTO_H
  28. #include <stdint.h>
  29. #define IPV4_PROTOCOL_IGMP 2
  30. struct ipv4_header {
  31. uint8_t version4_ihl4;
  32. uint8_t ds;
  33. uint16_t total_length;
  34. //
  35. uint16_t identification;
  36. uint16_t flags3_fragmentoffset13;
  37. //
  38. uint8_t ttl;
  39. uint8_t protocol;
  40. uint16_t checksum;
  41. //
  42. uint32_t source_address;
  43. //
  44. uint32_t destination_address;
  45. } __attribute__((packed));
  46. #define IPV4_GET_VERSION(_header) (((_header).version4_ihl4&0xF0)>>4)
  47. #define IPV4_GET_IHL(_header) (((_header).version4_ihl4&0x0F)>>0)
  48. #endif