michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /** michael@0: * Abstraction on top of the network support from libnetutils that we michael@0: * use to set up network connections. michael@0: */ michael@0: michael@0: #ifndef NetUtils_h michael@0: #define NetUtils_h michael@0: michael@0: #include "arpa/inet.h" michael@0: michael@0: // Copied from ifc.h michael@0: #define RESET_IPV4_ADDRESSES 0x01 michael@0: #define RESET_IPV6_ADDRESSES 0x02 michael@0: #define RESET_ALL_ADDRESSES (RESET_IPV4_ADDRESSES | RESET_IPV6_ADDRESSES) michael@0: michael@0: // Implements netutils functions. No need for an abstract class here since we michael@0: // only have a one sdk specific method (dhcp_do_request) michael@0: class NetUtils michael@0: { michael@0: public: michael@0: static void* GetSharedLibrary(); michael@0: michael@0: int32_t do_ifc_enable(const char *ifname); michael@0: int32_t do_ifc_disable(const char *ifname); michael@0: int32_t do_ifc_configure(const char *ifname, michael@0: in_addr_t address, michael@0: uint32_t prefixLength, michael@0: in_addr_t gateway, michael@0: in_addr_t dns1, michael@0: in_addr_t dns2); michael@0: int32_t do_ifc_reset_connections(const char *ifname, const int32_t resetMask); michael@0: int32_t do_ifc_set_default_route(const char *ifname, in_addr_t gateway); michael@0: int32_t do_ifc_add_route(const char *ifname, michael@0: const char *dst, michael@0: uint32_t prefixLength, michael@0: const char *gateway); michael@0: int32_t do_ifc_remove_route(const char *ifname, michael@0: const char *dst, michael@0: uint32_t prefixLength, michael@0: const char *gateway); michael@0: int32_t do_ifc_remove_host_routes(const char *ifname); michael@0: int32_t do_ifc_remove_default_route(const char *ifname); michael@0: int32_t do_dhcp_stop(const char *ifname); michael@0: int32_t do_dhcp_do_request(const char *ifname, michael@0: char *ipaddr, michael@0: char *gateway, michael@0: uint32_t *prefixLength, michael@0: char *dns1, michael@0: char *dns2, michael@0: char *server, michael@0: uint32_t *lease, michael@0: char* vendorinfo); michael@0: michael@0: static int32_t SdkVersion(); michael@0: }; michael@0: michael@0: // Defines a function type with the right arguments and return type. michael@0: #define DEFINE_DLFUNC(name, ret, args...) typedef ret (*FUNC##name)(args); michael@0: michael@0: // Set up a dlsymed function ready to use. michael@0: #define USE_DLFUNC(name) \ michael@0: FUNC##name name = (FUNC##name) dlsym(GetSharedLibrary(), #name); \ michael@0: if (!name) { \ michael@0: MOZ_ASSUME_UNREACHABLE("Symbol not found in shared library : " #name); \ michael@0: } michael@0: michael@0: #endif // NetUtils_h