BDHCPClient.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * @file BDHCPClient.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. * DHCP client.
  25. */
  26. #ifndef BADVPN_DHCPCLIENT_BDHCPCLIENT_H
  27. #define BADVPN_DHCPCLIENT_BDHCPCLIENT_H
  28. #include <system/DebugObject.h>
  29. #include <system/BSocket.h>
  30. #include <flow/PacketCopier.h>
  31. #include <flow/SinglePacketBuffer.h>
  32. #include <flow/DatagramSocketSink.h>
  33. #include <flow/DatagramSocketSource.h>
  34. #include <dhcpclient/BDHCPClientCore.h>
  35. #include <dhcpclient/DHCPIpUdpDecoder.h>
  36. #include <dhcpclient/DHCPIpUdpEncoder.h>
  37. #define BDHCPCLIENT_EVENT_UP 1
  38. #define BDHCPCLIENT_EVENT_DOWN 2
  39. #define BDHCPCLIENT_MAX_DOMAIN_NAME_SERVERS BDHCPCLIENTCORE_MAX_DOMAIN_NAME_SERVERS
  40. typedef void (*BDHCPClient_handler) (void *user, int event);
  41. typedef struct {
  42. BReactor *reactor;
  43. BSocket sock;
  44. BDHCPClient_handler handler;
  45. void *user;
  46. FlowErrorDomain domain;
  47. PacketCopier send_copier;
  48. DHCPIpUdpEncoder send_encoder;
  49. SinglePacketBuffer send_buffer;
  50. DatagramSocketSink send_sink;
  51. DatagramSocketSource recv_source;
  52. SinglePacketBuffer recv_buffer;
  53. DHCPIpUdpDecoder recv_decoder;
  54. PacketCopier recv_copier;
  55. BDHCPClientCore dhcp;
  56. int up;
  57. DebugObject d_obj;
  58. } BDHCPClient;
  59. int BDHCPClient_Init (BDHCPClient *o, const char *ifname, BReactor *reactor, BDHCPClient_handler handler, void *user);
  60. void BDHCPClient_Free (BDHCPClient *o);
  61. int BDHCPClient_IsUp (BDHCPClient *o);
  62. void BDHCPClient_GetClientIP (BDHCPClient *o, uint32_t *out_ip);
  63. void BDHCPClient_GetClientMask (BDHCPClient *o, uint32_t *out_mask);
  64. int BDHCPClient_GetRouter (BDHCPClient *o, uint32_t *out_router);
  65. int BDHCPClient_GetDNS (BDHCPClient *o, uint32_t *out_dns_servers, size_t max_dns_servers);
  66. #endif