common.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* vi: set sw=4 ts=4: */
  2. /* common.h
  3. *
  4. * Russ Dill <Russ.Dill@asu.edu> September 2001
  5. * Rewritten by Vladimir Oleynik <dzo@simtreas.ru> (C) 2003
  6. *
  7. * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
  8. */
  9. #ifndef _COMMON_H
  10. #define _COMMON_H
  11. #include "libbb.h"
  12. #define DEFAULT_SCRIPT CONFIG_DHCPC_DEFAULT_SCRIPT
  13. extern const uint8_t MAC_BCAST_ADDR[6]; /* six all-ones */
  14. /*** packet.h ***/
  15. #include <netinet/udp.h>
  16. #include <netinet/ip.h>
  17. #define DHCP_OPTIONS_BUFSIZE 308
  18. struct dhcpMessage {
  19. uint8_t op;
  20. uint8_t htype;
  21. uint8_t hlen;
  22. uint8_t hops;
  23. uint32_t xid;
  24. uint16_t secs;
  25. uint16_t flags;
  26. uint32_t ciaddr;
  27. uint32_t yiaddr;
  28. uint32_t siaddr;
  29. uint32_t giaddr;
  30. uint8_t chaddr[16];
  31. uint8_t sname[64];
  32. uint8_t file[128];
  33. uint32_t cookie;
  34. uint8_t options[DHCP_OPTIONS_BUFSIZE + CONFIG_UDHCPC_SLACK_FOR_BUGGY_SERVERS];
  35. } ATTRIBUTE_PACKED;
  36. struct udp_dhcp_packet {
  37. struct iphdr ip;
  38. struct udphdr udp;
  39. struct dhcpMessage data;
  40. } ATTRIBUTE_PACKED;
  41. /* Let's see whether compiler understood us right */
  42. struct BUG_bad_sizeof_struct_udp_dhcp_packet {
  43. char BUG_bad_sizeof_struct_udp_dhcp_packet
  44. [(sizeof(struct udp_dhcp_packet) != 576 + CONFIG_UDHCPC_SLACK_FOR_BUGGY_SERVERS) ? -1 : 1];
  45. };
  46. uint16_t udhcp_checksum(void *addr, int count);
  47. void udhcp_init_header(struct dhcpMessage *packet, char type);
  48. int udhcp_recv_packet(struct dhcpMessage *packet, int fd);
  49. int udhcp_send_raw_packet(struct dhcpMessage *payload,
  50. uint32_t source_ip, int source_port,
  51. uint32_t dest_ip, int dest_port,
  52. const uint8_t *dest_arp, int ifindex);
  53. int udhcp_send_kernel_packet(struct dhcpMessage *payload,
  54. uint32_t source_ip, int source_port,
  55. uint32_t dest_ip, int dest_port);
  56. /**/
  57. void udhcp_run_script(struct dhcpMessage *packet, const char *name);
  58. // Still need to clean these up...
  59. /* from options.h */
  60. #define get_option udhcp_get_option
  61. #define end_option udhcp_end_option
  62. #define add_option_string udhcp_add_option_string
  63. #define add_simple_option udhcp_add_simple_option
  64. /* from socket.h */
  65. #define listen_socket udhcp_listen_socket
  66. #define read_interface udhcp_read_interface
  67. void udhcp_sp_setup(void);
  68. int udhcp_sp_fd_set(fd_set *rfds, int extra_fd);
  69. int udhcp_sp_read(const fd_set *rfds);
  70. int raw_socket(int ifindex);
  71. int read_interface(const char *interface, int *ifindex, uint32_t *addr, uint8_t *arp);
  72. int listen_socket(/*uint32_t ip,*/ int port, const char *inf);
  73. /* Returns 1 if no reply received */
  74. int arpping(uint32_t test_ip, uint32_t from_ip, uint8_t *from_mac, const char *interface);
  75. #if ENABLE_FEATURE_UDHCP_DEBUG
  76. # define DEBUG(str, args...) bb_info_msg("### " str, ## args)
  77. #else
  78. # define DEBUG(str, args...) do {;} while (0)
  79. #endif
  80. #endif