dom/network/src/NetUtils.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/network/src/NetUtils.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,71 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +/**
     1.9 + * Abstraction on top of the network support from libnetutils that we
    1.10 + * use to set up network connections.
    1.11 + */
    1.12 +
    1.13 +#ifndef NetUtils_h
    1.14 +#define NetUtils_h
    1.15 +
    1.16 +#include "arpa/inet.h"
    1.17 +
    1.18 +// Copied from ifc.h
    1.19 +#define RESET_IPV4_ADDRESSES 0x01
    1.20 +#define RESET_IPV6_ADDRESSES 0x02
    1.21 +#define RESET_ALL_ADDRESSES  (RESET_IPV4_ADDRESSES | RESET_IPV6_ADDRESSES)
    1.22 +
    1.23 +// Implements netutils functions. No need for an abstract class here since we
    1.24 +// only have a one sdk specific method (dhcp_do_request)
    1.25 +class NetUtils
    1.26 +{
    1.27 +public:
    1.28 +  static void* GetSharedLibrary();
    1.29 +
    1.30 +  int32_t do_ifc_enable(const char *ifname);
    1.31 +  int32_t do_ifc_disable(const char *ifname);
    1.32 +  int32_t do_ifc_configure(const char *ifname,
    1.33 +                           in_addr_t address,
    1.34 +                           uint32_t prefixLength,
    1.35 +                           in_addr_t gateway,
    1.36 +                           in_addr_t dns1,
    1.37 +                           in_addr_t dns2);
    1.38 +  int32_t do_ifc_reset_connections(const char *ifname, const int32_t resetMask);
    1.39 +  int32_t do_ifc_set_default_route(const char *ifname, in_addr_t gateway);
    1.40 +  int32_t do_ifc_add_route(const char *ifname,
    1.41 +                           const char *dst,
    1.42 +                           uint32_t prefixLength,
    1.43 +                           const char *gateway);
    1.44 +  int32_t do_ifc_remove_route(const char *ifname,
    1.45 +                              const char *dst,
    1.46 +                              uint32_t prefixLength,
    1.47 +                              const char *gateway);
    1.48 +  int32_t do_ifc_remove_host_routes(const char *ifname);
    1.49 +  int32_t do_ifc_remove_default_route(const char *ifname);
    1.50 +  int32_t do_dhcp_stop(const char *ifname);
    1.51 +  int32_t do_dhcp_do_request(const char *ifname,
    1.52 +                             char *ipaddr,
    1.53 +                             char *gateway,
    1.54 +                             uint32_t *prefixLength,
    1.55 +                             char *dns1,
    1.56 +                             char *dns2,
    1.57 +                             char *server,
    1.58 +                             uint32_t  *lease,
    1.59 +                             char* vendorinfo);
    1.60 +
    1.61 +  static int32_t SdkVersion();
    1.62 +};
    1.63 +
    1.64 +// Defines a function type with the right arguments and return type.
    1.65 +#define DEFINE_DLFUNC(name, ret, args...) typedef ret (*FUNC##name)(args);
    1.66 +
    1.67 +// Set up a dlsymed function ready to use.
    1.68 +#define USE_DLFUNC(name)                                                      \
    1.69 +  FUNC##name name = (FUNC##name) dlsym(GetSharedLibrary(), #name);            \
    1.70 +  if (!name) {                                                                \
    1.71 +    MOZ_ASSUME_UNREACHABLE("Symbol not found in shared library : " #name);    \
    1.72 +  }
    1.73 +
    1.74 +#endif // NetUtils_h

mercurial