dhcp_proto.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /**
  2. * @file dhcp_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 DHCP protocol.
  25. */
  26. #ifndef BADVPN_MISC_DHCP_PROTO_H
  27. #define BADVPN_MISC_DHCP_PROTO_H
  28. #include <stdint.h>
  29. #define DHCP_OP_BOOTREQUEST 1
  30. #define DHCP_OP_BOOTREPLY 2
  31. #define DHCP_HARDWARE_ADDRESS_TYPE_ETHERNET 1
  32. #define DHCP_MAGIC 0x63825363
  33. #define DHCP_OPTION_PAD 0
  34. #define DHCP_OPTION_END 255
  35. #define DHCP_OPTION_SUBNET_MASK 1
  36. #define DHCP_OPTION_ROUTER 3
  37. #define DHCP_OPTION_DOMAIN_NAME_SERVER 6
  38. #define DHCP_OPTION_HOST_NAME 12
  39. #define DHCP_OPTION_REQUESTED_IP_ADDRESS 50
  40. #define DHCP_OPTION_IP_ADDRESS_LEASE_TIME 51
  41. #define DHCP_OPTION_DHCP_MESSAGE_TYPE 53
  42. #define DHCP_OPTION_DHCP_SERVER_IDENTIFIER 54
  43. #define DHCP_OPTION_PARAMETER_REQUEST_LIST 55
  44. #define DHCP_OPTION_MAXIMUM_MESSAGE_SIZE 57
  45. #define DHCP_OPTION_RENEWAL_TIME_VALUE 58
  46. #define DHCP_OPTION_REBINDING_TIME_VALUE 59
  47. #define DHCP_OPTION_VENDOR_CLASS_IDENTIFIER 60
  48. #define DHCP_MESSAGE_TYPE_DISCOVER 1
  49. #define DHCP_MESSAGE_TYPE_OFFER 2
  50. #define DHCP_MESSAGE_TYPE_REQUEST 3
  51. #define DHCP_MESSAGE_TYPE_DECLINE 4
  52. #define DHCP_MESSAGE_TYPE_ACK 5
  53. #define DHCP_MESSAGE_TYPE_NAK 6
  54. #define DHCP_MESSAGE_TYPE_RELEASE 7
  55. struct dhcp_header {
  56. uint8_t op;
  57. uint8_t htype;
  58. uint8_t hlen;
  59. uint8_t hops;
  60. uint32_t xid;
  61. uint16_t secs;
  62. uint16_t flags;
  63. uint32_t ciaddr;
  64. uint32_t yiaddr;
  65. uint32_t siaddr;
  66. uint32_t giaddr;
  67. uint8_t chaddr[16];
  68. uint8_t sname[64];
  69. uint8_t file[128];
  70. uint32_t magic;
  71. } __attribute__((packed));
  72. struct dhcp_option_header {
  73. uint8_t type;
  74. uint8_t len;
  75. } __attribute__((packed));
  76. struct dhcp_option_dhcp_message_type {
  77. uint8_t type;
  78. } __attribute__((packed));
  79. struct dhcp_option_maximum_message_size {
  80. uint16_t size;
  81. } __attribute__((packed));
  82. struct dhcp_option_dhcp_server_identifier {
  83. uint32_t id;
  84. } __attribute__((packed));
  85. struct dhcp_option_time {
  86. uint32_t time;
  87. } __attribute__((packed));
  88. struct dhcp_option_addr {
  89. uint32_t addr;
  90. } __attribute__((packed));
  91. #endif