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