dhcp_proto.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /**
  2. * @file dhcp_proto.h
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the name of the author nor the
  15. * names of its contributors may be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. * @section DESCRIPTION
  30. *
  31. * Definitions for the DHCP protocol.
  32. */
  33. #ifndef BADVPN_MISC_DHCP_PROTO_H
  34. #define BADVPN_MISC_DHCP_PROTO_H
  35. #include <stdint.h>
  36. #define DHCP_OP_BOOTREQUEST 1
  37. #define DHCP_OP_BOOTREPLY 2
  38. #define DHCP_HARDWARE_ADDRESS_TYPE_ETHERNET 1
  39. #define DHCP_MAGIC 0x63825363
  40. #define DHCP_OPTION_PAD 0
  41. #define DHCP_OPTION_END 255
  42. #define DHCP_OPTION_SUBNET_MASK 1
  43. #define DHCP_OPTION_ROUTER 3
  44. #define DHCP_OPTION_DOMAIN_NAME_SERVER 6
  45. #define DHCP_OPTION_HOST_NAME 12
  46. #define DHCP_OPTION_REQUESTED_IP_ADDRESS 50
  47. #define DHCP_OPTION_IP_ADDRESS_LEASE_TIME 51
  48. #define DHCP_OPTION_DHCP_MESSAGE_TYPE 53
  49. #define DHCP_OPTION_DHCP_SERVER_IDENTIFIER 54
  50. #define DHCP_OPTION_PARAMETER_REQUEST_LIST 55
  51. #define DHCP_OPTION_MAXIMUM_MESSAGE_SIZE 57
  52. #define DHCP_OPTION_RENEWAL_TIME_VALUE 58
  53. #define DHCP_OPTION_REBINDING_TIME_VALUE 59
  54. #define DHCP_OPTION_VENDOR_CLASS_IDENTIFIER 60
  55. #define DHCP_OPTION_CLIENT_IDENTIFIER 61
  56. #define DHCP_MESSAGE_TYPE_DISCOVER 1
  57. #define DHCP_MESSAGE_TYPE_OFFER 2
  58. #define DHCP_MESSAGE_TYPE_REQUEST 3
  59. #define DHCP_MESSAGE_TYPE_DECLINE 4
  60. #define DHCP_MESSAGE_TYPE_ACK 5
  61. #define DHCP_MESSAGE_TYPE_NAK 6
  62. #define DHCP_MESSAGE_TYPE_RELEASE 7
  63. struct dhcp_header {
  64. uint8_t op;
  65. uint8_t htype;
  66. uint8_t hlen;
  67. uint8_t hops;
  68. uint32_t xid;
  69. uint16_t secs;
  70. uint16_t flags;
  71. uint32_t ciaddr;
  72. uint32_t yiaddr;
  73. uint32_t siaddr;
  74. uint32_t giaddr;
  75. uint8_t chaddr[16];
  76. uint8_t sname[64];
  77. uint8_t file[128];
  78. uint32_t magic;
  79. } __attribute__((packed));
  80. struct dhcp_option_header {
  81. uint8_t type;
  82. uint8_t len;
  83. } __attribute__((packed));
  84. struct dhcp_option_dhcp_message_type {
  85. uint8_t type;
  86. } __attribute__((packed));
  87. struct dhcp_option_maximum_message_size {
  88. uint16_t size;
  89. } __attribute__((packed));
  90. struct dhcp_option_dhcp_server_identifier {
  91. uint32_t id;
  92. } __attribute__((packed));
  93. struct dhcp_option_time {
  94. uint32_t time;
  95. } __attribute__((packed));
  96. struct dhcp_option_addr {
  97. uint32_t addr;
  98. } __attribute__((packed));
  99. #endif