Merge pull request #1495 from akoeplinger/fix-cancelrequestviaproxy
[mono.git] / mono / utils / networking.h
1 /*
2  * networking.h: Portable networking functions
3  *
4  * Author:
5  *      Rodrigo Kumpera (kumpera@gmail.com)
6  *
7  * (C) 2015 Xamarin
8  */
9
10
11 #ifndef __MONO_NETWORKING_H__
12 #define __MONO_NETWORKING_H__
13
14 #include <config.h>
15
16 #ifdef HAVE_ARPA_INET_H
17 #include <arpa/inet.h>
18 #endif
19 #include <sys/types.h>
20 #ifdef HAVE_SYS_SOCKET_H
21 #include <sys/socket.h>
22 #endif
23
24 #ifdef HOST_WIN32
25 #include <winsock2.h>
26 #include <ws2tcpip.h>
27 typedef unsigned int socklen_t;
28 #endif
29
30 #include <mono/utils/mono-compiler.h>
31
32 typedef enum {
33         MONO_HINT_UNSPECIFIED           = 0,
34         MONO_HINT_IPV4                          = 1,
35         MONO_HINT_IPV6                          = 2,
36         MONO_HINT_CANONICAL_NAME        = 4,
37         MONO_HINT_CONFIGURED_ONLY       = 8,
38 } MonoGetAddressHints;
39
40 typedef struct _MonoAddressEntry MonoAddressEntry;
41
42 struct _MonoAddressEntry {
43         int family;
44         int socktype;
45         int protocol;
46         int address_len;
47         union {
48                 struct in_addr v4;
49                 struct in6_addr v6;
50         } address;
51         const char *canonical_name;
52         MonoAddressEntry *next;
53 };
54
55 typedef struct {
56         MonoAddressEntry *entries;
57         char **aliases;
58 } MonoAddressInfo;
59
60 typedef union {
61         struct sockaddr_in v4;
62         struct sockaddr_in6 v6;
63         struct sockaddr addr;
64 } MonoSocketAddress;
65
66 /* This only supports IPV4 / IPV6 and tcp */
67 int mono_get_address_info (const char *hostname, int port, int flags, MonoAddressInfo **res) MONO_INTERNAL;
68
69 void mono_free_address_info (MonoAddressInfo *ai) MONO_INTERNAL;
70
71 void mono_socket_address_init (MonoSocketAddress *sa, socklen_t *len, int family, const void *address, int port) MONO_INTERNAL;
72
73 void *mono_get_local_interfaces (int family, int *interface_count) MONO_INTERNAL;
74
75 #ifndef HAVE_INET_PTON
76 int inet_pton (int family, const char *address, void *inaddrp) MONO_INTERNAL;
77 #endif
78
79 int mono_networking_get_tcp_protocol (void) MONO_INTERNAL;
80 int mono_networking_get_ip_protocol (void) MONO_INTERNAL;
81 int mono_networking_get_ipv6_protocol (void) MONO_INTERNAL;
82
83 #endif