Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / utils / networking.h
1 /**
2  * \file
3  * Portable networking functions
4  *
5  * Author:
6  *      Rodrigo Kumpera (kumpera@gmail.com)
7  *
8  * (C) 2015 Xamarin
9  */
10
11
12 #ifndef __MONO_NETWORKING_H__
13 #define __MONO_NETWORKING_H__
14
15 #include <config.h>
16 #include <glib.h>
17
18 #ifdef HAVE_ARPA_INET_H
19 #include <arpa/inet.h>
20 #endif
21 #include <sys/types.h>
22 #ifdef HAVE_SYS_SOCKET_H
23 #include <sys/socket.h>
24 #endif
25 #ifdef HAVE_SYS_SOCKIO_H
26 #include <sys/sockio.h>
27 #endif
28
29 #ifdef HAVE_NETINET_IN_H
30 #include <netinet/in.h>
31 #endif
32
33 #ifdef HOST_WIN32
34 #include <winsock2.h>
35 #include <ws2tcpip.h>
36 #endif
37
38 #include <mono/utils/mono-compiler.h>
39
40 typedef enum {
41         MONO_HINT_UNSPECIFIED           = 0,
42         MONO_HINT_IPV4                          = 1,
43         MONO_HINT_IPV6                          = 2,
44         MONO_HINT_CANONICAL_NAME        = 4,
45         MONO_HINT_CONFIGURED_ONLY       = 8,
46 } MonoGetAddressHints;
47
48 typedef struct _MonoAddressEntry MonoAddressEntry;
49
50 struct _MonoAddressEntry {
51         int family;
52         int socktype;
53         int protocol;
54         int address_len;
55         union {
56                 struct in_addr v4;
57                 struct in6_addr v6;
58         } address;
59         const char *canonical_name;
60         MonoAddressEntry *next;
61 };
62
63 typedef struct {
64         MonoAddressEntry *entries;
65         char **aliases;
66 } MonoAddressInfo;
67
68 typedef union {
69         struct sockaddr_in v4;
70         struct sockaddr_in6 v6;
71         struct sockaddr addr;
72 } MonoSocketAddress;
73
74 typedef struct {
75         int family;
76         union {
77                 struct in_addr v4;
78                 struct in6_addr v6;
79         } addr;
80 } MonoAddress;
81
82 /* This only supports IPV4 / IPV6 and tcp */
83 int mono_get_address_info (const char *hostname, int port, int flags, MonoAddressInfo **res);
84
85 void mono_free_address_info (MonoAddressInfo *ai);
86
87 void mono_socket_address_init (MonoSocketAddress *sa, socklen_t *len, int family, const void *address, int port);
88
89 void *mono_get_local_interfaces (int family, int *interface_count);
90
91 #ifndef HAVE_INET_PTON
92 int inet_pton (int family, const char *address, void *inaddrp);
93 #endif
94
95 void mono_address_init (MonoAddress *out_addr, int family, void *in_addr);
96 int mono_address_size_for_family (int family);
97 gboolean mono_networking_addr_to_str (MonoAddress *address, char *buffer, socklen_t buflen);
98
99 int mono_networking_get_tcp_protocol (void);
100 int mono_networking_get_ip_protocol (void);
101 int mono_networking_get_ipv6_protocol (void);
102
103 void mono_networking_init (void);
104 void mono_networking_shutdown (void);
105
106
107 #endif