BDHCPClient.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 <base/DebugObject.h>
  29. #include <system/BDatagram.h>
  30. #include <flow/PacketCopier.h>
  31. #include <flow/SinglePacketBuffer.h>
  32. #include <dhcpclient/BDHCPClientCore.h>
  33. #include <dhcpclient/DHCPIpUdpDecoder.h>
  34. #include <dhcpclient/DHCPIpUdpEncoder.h>
  35. #define BDHCPCLIENT_EVENT_UP 1
  36. #define BDHCPCLIENT_EVENT_DOWN 2
  37. #define BDHCPCLIENT_EVENT_ERROR 3
  38. #define BDHCPCLIENT_MAX_DOMAIN_NAME_SERVERS BDHCPCLIENTCORE_MAX_DOMAIN_NAME_SERVERS
  39. typedef void (*BDHCPClient_handler) (void *user, int event);
  40. typedef struct {
  41. BReactor *reactor;
  42. BDatagram dgram;
  43. BDHCPClient_handler handler;
  44. void *user;
  45. PacketCopier send_copier;
  46. DHCPIpUdpEncoder send_encoder;
  47. SinglePacketBuffer send_buffer;
  48. SinglePacketBuffer recv_buffer;
  49. DHCPIpUdpDecoder recv_decoder;
  50. PacketCopier recv_copier;
  51. BDHCPClientCore dhcp;
  52. int up;
  53. DebugError d_err;
  54. DebugObject d_obj;
  55. } BDHCPClient;
  56. int BDHCPClient_Init (BDHCPClient *o, const char *ifname, BReactor *reactor, BDHCPClient_handler handler, void *user);
  57. void BDHCPClient_Free (BDHCPClient *o);
  58. int BDHCPClient_IsUp (BDHCPClient *o);
  59. void BDHCPClient_GetClientIP (BDHCPClient *o, uint32_t *out_ip);
  60. void BDHCPClient_GetClientMask (BDHCPClient *o, uint32_t *out_mask);
  61. int BDHCPClient_GetRouter (BDHCPClient *o, uint32_t *out_router);
  62. int BDHCPClient_GetDNS (BDHCPClient *o, uint32_t *out_dns_servers, size_t max_dns_servers);
  63. #endif