tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

prnetaddr.rst (2372B)


      1 PRNetAddr
      2 =========
      3 
      4 Type used with `Socket Manipulation
      5 Functions <Socket_Manipulation_Functions>`__ to specify a network
      6 address.
      7 
      8 
      9 Syntax
     10 ------
     11 
     12 .. code::
     13 
     14   #include <prio.h>
     15 
     16   union PRNetAddr {
     17     struct {
     18        PRUint16 family;
     19        char data[14];
     20     } raw;
     21     struct {
     22        PRUint16 family;
     23        PRUint16 port;
     24        PRUint32 ip;
     25        char pad[8];
     26     } inet;
     27   #if defined(_PR_INET6)
     28     struct {
     29        PRUint16 family;
     30        PRUint16 port;
     31        PRUint32 flowinfo;
     32        PRIPv6Addr ip;
     33     } ipv6;
     34   #endif /* defined(_PR_INET6) */
     35   };
     36 
     37   typedef union PRNetAddr PRNetAddr;
     38 
     39 
     40 Fields
     41 ~~~~~~
     42 
     43 The structure has the following fields:
     44 
     45 ``family``
     46   Address family: ``PR_AF_INET|PR_AF_INET6`` for ``raw.family``,
     47   ``PR_AF_INET`` for ``inet.family``, ``PR_AF_INET6`` for
     48   ``ipv6.family``.
     49 ``data``
     50   Raw address data.
     51 ``port``
     52   Port number of TCP or UDP, in network byte order.
     53 ``ip``
     54   The actual 32 (for ``inet.ip``) or 128 (for ``ipv6.ip``) bits of IP
     55   address. The ``inet.ip`` field is in network byte order.
     56 ``pad``
     57   Unused.
     58 ``flowinfo``
     59   Routing information.
     60 
     61 
     62 Description
     63 -----------
     64 
     65 The union :ref:`PRNetAddr` represents a network address. NSPR supports only
     66 the Internet address family. By default, NSPR is built to support only
     67 IPv4, but it's possible to build the NSPR library to support both IPv4
     68 and IPv6. Therefore, the ``family`` field can be ``PR_AF_INET`` only for
     69 default NSPR, and can also be ``PR_AF_INET6`` if the binary supports
     70 ``IPv6``.
     71 
     72 :ref:`PRNetAddr` is binary-compatible with the socket address structures in
     73 the familiar Berkeley socket interface, although this fact should not be
     74 relied upon. The raw member of the union is equivalent to
     75 ``struct sockaddr``, the ``inet`` member is equivalent to
     76 ``struct sockaddr_in``, and if the binary is built with ``IPv6``
     77 support, the ``ipv6`` member is equivalent to ``struct sockaddr_in6``.
     78 (Note that :ref:`PRNetAddr` does not have the ``length`` field that is
     79 present in ``struct sockaddr_in`` on some Unix platforms.)
     80 
     81 The macros ``PR_AF_INET``, ``PR_AF_INET6``, ``PR_INADDR_ANY``,
     82 ``PR_INADDR_LOOPBACK`` are defined if ``prio.h`` is included.
     83 ``PR_INADDR_ANY`` and ``PR_INADDR_LOOPBACK`` are special ``IPv4``
     84 addresses in host byte order, so they must be converted to network byte
     85 order before being assigned to the ``inet.ip`` field.