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.

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

mercurial