common.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 "/usr/share/udhcpc/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. struct dhcpMessage {
  18. uint8_t op;
  19. uint8_t htype;
  20. uint8_t hlen;
  21. uint8_t hops;
  22. uint32_t xid;
  23. uint16_t secs;
  24. uint16_t flags;
  25. uint32_t ciaddr;
  26. uint32_t yiaddr;
  27. uint32_t siaddr;
  28. uint32_t giaddr;
  29. uint8_t chaddr[16];
  30. uint8_t sname[64];
  31. uint8_t file[128];
  32. uint32_t cookie;
  33. uint8_t options[308]; /* 312 - cookie */
  34. };
  35. struct udp_dhcp_packet {
  36. struct iphdr ip;
  37. struct udphdr udp;
  38. struct dhcpMessage data;
  39. };
  40. void udhcp_init_header(struct dhcpMessage *packet, char type);
  41. int udhcp_get_packet(struct dhcpMessage *packet, int fd);
  42. uint16_t udhcp_checksum(void *addr, int count);
  43. int udhcp_raw_packet(struct dhcpMessage *payload,
  44. uint32_t source_ip, int source_port,
  45. uint32_t dest_ip, int dest_port,
  46. const uint8_t *dest_arp, int ifindex);
  47. int udhcp_kernel_packet(struct dhcpMessage *payload,
  48. uint32_t source_ip, int source_port,
  49. uint32_t dest_ip, int dest_port);
  50. /**/
  51. void udhcp_run_script(struct dhcpMessage *packet, const char *name);
  52. // Still need to clean these up...
  53. /* from options.h */
  54. #define get_option udhcp_get_option
  55. #define end_option udhcp_end_option
  56. #define add_option_string udhcp_add_option_string
  57. #define add_simple_option udhcp_add_simple_option
  58. #define option_lengths udhcp_option_lengths
  59. /* from socket.h */
  60. #define listen_socket udhcp_listen_socket
  61. #define read_interface udhcp_read_interface
  62. void udhcp_sp_setup(void);
  63. int udhcp_sp_fd_set(fd_set *rfds, int extra_fd);
  64. int udhcp_sp_read(fd_set *rfds);
  65. int raw_socket(int ifindex);
  66. int read_interface(const char *interface, int *ifindex, uint32_t *addr, uint8_t *arp);
  67. int listen_socket(/*uint32_t ip,*/ int port, const char *inf);
  68. /* Returns 1 if no reply received */
  69. int arpping(uint32_t test_ip, uint32_t from_ip, uint8_t *from_mac, const char *interface);
  70. #if ENABLE_FEATURE_UDHCP_DEBUG
  71. # define DEBUG(str, args...) bb_info_msg(str, ## args)
  72. #else
  73. # define DEBUG(str, args...) do {;} while (0)
  74. #endif
  75. #endif