dom/network/src/NetUtils.h

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:ca0942c170c6
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/. */
4
5 /**
6 * Abstraction on top of the network support from libnetutils that we
7 * use to set up network connections.
8 */
9
10 #ifndef NetUtils_h
11 #define NetUtils_h
12
13 #include "arpa/inet.h"
14
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)
19
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();
26
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);
57
58 static int32_t SdkVersion();
59 };
60
61 // Defines a function type with the right arguments and return type.
62 #define DEFINE_DLFUNC(name, ret, args...) typedef ret (*FUNC##name)(args);
63
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 }
70
71 #endif // NetUtils_h

mercurial