media/webrtc/signaling/src/sipcc/cpr/android/cpr_android_socket.h

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     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 #ifndef _CPR_ANDROID_SOCKET_H_
     6 #define _CPR_ANDROID_SOCKET_H_
     8 #include "cpr_types.h"
     9 #include <sys/socket.h>
    10 #include <sys/select.h>
    11 #include <sys/un.h>
    12 #include <netinet/in.h>
    13 #include <netinet/tcp.h>
    14 #include <unistd.h>
    15 #include <arpa/inet.h>
    17 /**
    18  * Set public CPR header file options
    19  */
    20 #define SUPPORT_CONNECT_CONST const
    22 /**
    23  * Define SOCKET_ERROR
    24  */
    25 #define SOCKET_ERROR   (-1)
    27 /**
    28  * Define INVALID_SOCKET
    29  */
    30 #define INVALID_SOCKET (-1)
    32 /**
    33  * Define cpr_socket_t
    34  */
    35 typedef int cpr_socket_t;
    37 /**
    38  * Define cpr_socklen_t
    39  */
    40 typedef socklen_t cpr_socklen_t;
    42 /**
    43  * Address family, defined in sys/socket.h
    44  *  AF_UNSPEC
    45  *  AF_LOCAL / AF_UNIX
    46  *  AF_INET
    47  *  AF_INET6
    48  *  AF_MAX
    49  *
    50  *  AF_NETLYR2 (unique to CNU) interface directly to layer 2, bypass IP
    51  */
    52 #ifndef AF_UNIX
    53 #define AF_UNIX  AF_LOCAL
    54 #endif
    57 /*
    58  * Constants and structures defined by the internet system,
    59  * Per RFC 790, September 1981, based on the BSD file netinet/in.h.
    60  * IPv6 additions per RFC 2292.
    61  */
    64 /*
    65  * Define the following socket options as needed
    66  *   SO_DEBUG
    67  *   SO_ACCEPTCONN
    68  *   SO_REUSEADDR / SO_EXCLUSIVEADDRUSE
    69  *   SO_KEEPALIVE
    70  *   SO_DONTROUTE
    71  *   SO_BROADCAST
    72  *   SO_USELOOPBACK
    73  *   SO_LINGER / SO_DONTLINGER
    74  *   SO_OOBINLINE
    75  *   SO_SNDBUF
    76  *   SO_RCVBUF
    77  *   SO_ERROR
    78  *   SO_TYPE
    79  *
    80  * The following options are available for Unix-only variants
    81  *   SO_SNDLOWAT
    82  *   SO_RCVLOWAT
    83  *   SO_SNDTIMEO
    84  *   SO_RCVTIMEO
    85  *   SO_PROTOTYPE - Not documented as being supported by CNU
    86  */
    88 /* defined in netinet/in.h */
    89 #define SO_DONTLINGER       ((int)(~SO_LINGER))
    90 #define SO_EXCLUSIVEADDRUSE ((int)(~SO_REUSEADDR))
    92 /*
    93  * Protocols (Base),
    94  * reference http://www.iana.org/assignments/protocol-numbers.html
    95  *   IPPROTO_IP
    96  *   IPPROTO_GGP
    97  *   IPPROTO_ICMP
    98  *   IPPROTO_IGMP
    99  *   IPPROTO_IPV4 / IPPROTO_IPIP
   100  *   IPPROTO_TCP
   101  *   IPPROTO_EGP
   102  *   IPPROTO_PUP
   103  *   IPPROTO_UDP
   104  *   IPPROTO_IDP
   105  *   IPPROTO_IPV6
   106  *   IPPROTO_ROUTING
   107  *   IPPROTO_FRAGMENT
   108  *   IPPROTO_ESP
   109  *   IPPROTO_AH
   110  *   IPPROTO_ICMPV6
   111  *   IPPROTO_NONE
   112  *   IPPROTO_DSTOPTS
   113  *   IPPROTO_ND
   114  *   IPPROTO_EON
   115  *   IPPROTO_IGRP
   116  *   IPPROTO_ENCAP
   117  *   IPPROTO_IPCOMP
   118  *   IPPROTO_RAW
   119  *   IPPROTO_MAX
   120  */
   122 /* defined in netinet/in.h */
   123 #ifndef IPPROTO_IPV4
   124 #define IPPROTO_IPV4         4
   125 #endif
   127 #ifndef IPPROTO_IPIP
   128 #define IPPROTO_IPIP  IPPROTO_IPV4
   129 #endif
   131 //#define IPPROTO_RSVP        46
   132 #define IPPROTO_IGRP        88  /* Cisco/GXS IGRP */
   133 #define IPPROTO_EIGRP       88
   134 #define IPPROTO_IPCOMP     108  /* IP payload compression */
   136 /*
   137  * Protocols (IPv6)
   138  *   Assumming if IPV6 is not there, then none of the are
   139  */
   140 #ifndef IPPROTO_IPV6
   141 #define IPPROTO_HOPOPTS      0  /* IPv6 hop-by-hop options */
   142 #define IPPROTO_IPV6        41  /* IPv6 */
   143 #define IPPROTO_ROUTING     43  /* IPv6 routing header */
   144 #define IPPROTO_FRAGMENT    44  /* IPv6 fragmentation header */
   145 #define IPPROTO_ICMPV6      58  /* ICMPv6 */
   146 #define IPPROTO_NONE        59  /* IPv6 no next header */
   147 #define IPPROTO_DSTOPTS     60  /* IPv6 destination options */
   148 #endif
   150 /*
   151  * Protocols (Local)
   152  * reference, RFC 3692
   153  *   IPPROTO_UNX       Local sockets Unix protocol
   154  *   IPPROTO_CDP       Non-Standard at 254, technially this value
   155  *                     is for experimentation and testing
   156  */
   158 /* defined in netinet/in.h */
   160 /*
   161  * Port/socket numbers: network standard functions
   162  * reference http://www.iana.org/assignments/port-numbers
   163  *  IPPORT_ECHO
   164  *  IPPORT_DISCARD
   165  *  IPPORT_SYSTAT
   166  *  IPPORT_DAYTIME
   167  *  IPPORT_NETSTAT
   168  *  IPPORT_FTP
   169  *  IPPORT_SSH
   170  *  IPPORT_TELNET
   171  *  IPPORT_SMTP
   172  *  IPPORT_TIMESERVER
   173  *  IPPORT_NAMESERVER
   174  *  IPPORT_WHOIS
   175  *  IPPORT_MTP
   176  *  IPPORT_HTTP
   177  *  IPPORT_NTP
   178  */
   180 /* defined in netinet/in.h */
   182 /*
   183  * Port/socket numbers: host specific functions
   184  *
   185  *  IPPORT_TFTP
   186  *  IPPORT_RJE
   187  *  IPPORT_FINGER
   188  *  IPPORT_TTYLINK
   189  *  IPPORT_SUPDUP
   190  */
   192 /* defined in netinet/in.h */
   194 /*
   195  * UNIX TCP sockets
   196  *
   197  *  IPPORT_EXECSERVER
   198  *  IPPORT_LOGINSERVER
   199  *  IPPORT_CMDSERVER
   200  *  IPPORT_EFSSERVER
   201  */
   203 /* defined in netinet/in.h */
   205 /*
   206  * UNIX UDP sockets
   207  *
   208  *  IPPORT_BIFFUDP
   209  *  IPPORT_WHOSERVER
   210  *  IPPORT_ROUTESERVER
   211  */
   213 /* defined in netinet/in.h */
   215 /*
   216  * SCCP sockets
   217  */
   218 #define IPPORT_SCCP       2000
   220 /*
   221  * tbd: need to finalize placement.
   222  * Define range of ephemeral ports used for Cisco IP Phones.
   223  */
   224 #define CIPPORT_EPH_LOW         0xC000
   225 #define CIPPORT_EPH_HI          0xCFFF
   228 /*
   229  * Ports < IPPORT_RESERVED are reserved for
   230  * privileged processes (e.g. root).
   231  *
   232  * IPPORT_RESERVED
   233  * IPPORT_USERRESERVED
   234  */
   236 /* defined in netinet/in.h */
   238 /*
   239  * Define INADDR constants
   240  *   INADDR_ANY
   241  *   INADDR_LOOPBACK
   242  *   INADDR_BROADCAST
   243  */
   245 /* defined in netinet/in.h */
   247 /*
   248  * Define IN_CLASS constants/macros
   249  *   IN_CLASS{A|B|C|D}(x)
   250  *   IN_CLASS{A|B|C|D}_NET
   251  *   IN_CLASS{A|B|C|D}_NSHIFT
   252  *   IN_CLASS{A|B|C|D}_HOST
   253  *   IN_CLASS{A|B|C|D}_MAX
   254  */
   257 /*
   258  * sockaddr_storage:
   259  * Common superset of at least AF_INET, AF_INET6 and AF_LINK sockaddr
   260  * structures. Has sufficient size and alignment for those sockaddrs.
   261  */
   262 typedef uint16_t        sa_family_t;
   264 typedef struct
   265 {
   266     sa_family_t sun_family;  /* AF_LOCAL/AF_UNIX */
   267     char        sun_path[108];
   268 } cpr_sockaddr_un_t;
   271 /*
   272  * Desired maximum size, alignment size and related types.
   273  */
   274 #define _SS_MAXSIZE     256     /* Implementation specific max size */
   276 #define cpr_sun_len(a) sizeof(a)
   277 void cpr_set_sockun_addr(cpr_sockaddr_un_t *addr, const char *name, pid_t pid);
   279 /*
   280  * To represent desired sockaddr max alignment for platform, a
   281  * type is chosen which may depend on implementation platform architecture.
   282  * Type chosen based on alignment size restrictions from <sys/isa_defs.h>.
   283  * We desire to force up to (but no more than) 64-bit (8 byte) alignment,
   284  * on platforms where it is possible to do so. (e.g not possible on ia32).
   285  * For all currently supported platforms by our implementation
   286  * in <sys/isa_defs.h>, (i.e. sparc, sparcv9, ia32, ia64)
   287  * type "double" is suitable for that intent.
   288  *
   289  * Note: Type "double" is chosen over the more obvious integer type int64_t.
   290  *   int64_t is not a valid type for strict ANSI/ISO C compilation on ILP32.
   291  */
   292 typedef double          sockaddr_maxalign_t;
   294 #define _SS_ALIGNSIZE   (sizeof (sockaddr_maxalign_t))
   296 /*
   297  * Definitions used for sockaddr_storage structure paddings design.
   298  */
   299 #define _SS_PAD1SIZE    (_SS_ALIGNSIZE - sizeof (sa_family_t))
   300 #define _SS_PAD2SIZE    (_SS_MAXSIZE - (sizeof (sa_family_t)+ \
   301                         _SS_PAD1SIZE + _SS_ALIGNSIZE))
   303 #ifndef __cplusplus
   304 typedef struct cpr_sockaddr_storage sockaddr_storage;
   305 #endif
   307 /*
   308  * IP level options
   309  *   IP_HDRINCL
   310  *   IP_TOS
   311  *   IP_TTL
   312  */
   314 /* defined in netinet/in.h */
   316 /*
   317  * TCP level options
   318  *   TCP_NODELAY
   319  *   TCP_MAXSEG
   320  *   TCP_KEEPALIVE
   321  */
   323 /* defined in netinet/tcp.h */
   326 /* TODO: Still to cleanup */
   328 /*
   329  * WinSock 2 extension -- new options
   330  */
   331 #define SO_MAX_MSG_SIZE   0x2003    /* maximum message size */
   334 #define SO_NBIO                 0x0400  /* Nonblocking socket I/O operation */
   335 #define SO_ASYNC                0x0800  /* should send asyn notification of
   336                                          * I/O events */
   337 #define SO_VRFTABLEID           0x1000  /* set VRF routing table id */
   338 #define SO_SRC_SPECIFIED        0x2000  /* Specified Source Address to be used */
   339 #define SO_STRICT_ADDR_BIND     0x4000  /* Accept only those packets that have
   340                                          * been sent to the address that this
   341                                          * socket is bound to */
   342 /*
   343  * Used for getting random port for tls connect
   344  */
   345 #define TCP_PORT_RETRY_CNT      5
   346 #define TCP_PORT_MASK           0xfff
   348 #endif

mercurial