dom/network/src/NetUtils.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 /**
     6  * Abstraction on top of the network support from libnetutils that we
     7  * use to set up network connections.
     8  */
    10 #ifndef NetUtils_h
    11 #define NetUtils_h
    13 #include "arpa/inet.h"
    15 // Copied from ifc.h
    16 #define RESET_IPV4_ADDRESSES 0x01
    17 #define RESET_IPV6_ADDRESSES 0x02
    18 #define RESET_ALL_ADDRESSES  (RESET_IPV4_ADDRESSES | RESET_IPV6_ADDRESSES)
    20 // Implements netutils functions. No need for an abstract class here since we
    21 // only have a one sdk specific method (dhcp_do_request)
    22 class NetUtils
    23 {
    24 public:
    25   static void* GetSharedLibrary();
    27   int32_t do_ifc_enable(const char *ifname);
    28   int32_t do_ifc_disable(const char *ifname);
    29   int32_t do_ifc_configure(const char *ifname,
    30                            in_addr_t address,
    31                            uint32_t prefixLength,
    32                            in_addr_t gateway,
    33                            in_addr_t dns1,
    34                            in_addr_t dns2);
    35   int32_t do_ifc_reset_connections(const char *ifname, const int32_t resetMask);
    36   int32_t do_ifc_set_default_route(const char *ifname, in_addr_t gateway);
    37   int32_t do_ifc_add_route(const char *ifname,
    38                            const char *dst,
    39                            uint32_t prefixLength,
    40                            const char *gateway);
    41   int32_t do_ifc_remove_route(const char *ifname,
    42                               const char *dst,
    43                               uint32_t prefixLength,
    44                               const char *gateway);
    45   int32_t do_ifc_remove_host_routes(const char *ifname);
    46   int32_t do_ifc_remove_default_route(const char *ifname);
    47   int32_t do_dhcp_stop(const char *ifname);
    48   int32_t do_dhcp_do_request(const char *ifname,
    49                              char *ipaddr,
    50                              char *gateway,
    51                              uint32_t *prefixLength,
    52                              char *dns1,
    53                              char *dns2,
    54                              char *server,
    55                              uint32_t  *lease,
    56                              char* vendorinfo);
    58   static int32_t SdkVersion();
    59 };
    61 // Defines a function type with the right arguments and return type.
    62 #define DEFINE_DLFUNC(name, ret, args...) typedef ret (*FUNC##name)(args);
    64 // Set up a dlsymed function ready to use.
    65 #define USE_DLFUNC(name)                                                      \
    66   FUNC##name name = (FUNC##name) dlsym(GetSharedLibrary(), #name);            \
    67   if (!name) {                                                                \
    68     MOZ_ASSUME_UNREACHABLE("Symbol not found in shared library : " #name);    \
    69   }
    71 #endif // NetUtils_h

mercurial