[utils] Add abstraction to retrive the local interface addresses.
[mono-project.git] / mono / utils / networking.h
blob8c2e930b254751cf0b41ec7bcb7624b92d039192
1 /*
2 * networking.h: Portable networking functions
4 * Author:
5 * Rodrigo Kumpera (kumpera@gmail.com)
7 * (C) 2015 Xamarin
8 */
11 #ifndef __MONO_NETWORKING_H__
12 #define __MONO_NETWORKING_H__
14 #include <arpa/inet.h>
15 #include <sys/types.h>
16 #include <sys/socket.h>
17 #include <mono/utils/mono-compiler.h>
19 typedef enum {
20 MONO_HINT_UNSPECIFIED = 0,
21 MONO_HINT_IPV4 = 1,
22 MONO_HINT_IPV6 = 2,
23 MONO_HINT_CANONICAL_NAME = 4,
24 MONO_HINT_CONFIGURED_ONLY = 8,
25 } MonoGetAddressHints;
27 typedef struct _MonoAddressEntry MonoAddressEntry;
29 struct _MonoAddressEntry {
30 int family;
31 int socktype;
32 int protocol;
33 int address_len;
34 union {
35 struct in_addr v4;
36 struct in6_addr v6;
37 } address;
38 const char *canonical_name;
39 MonoAddressEntry *next;
42 typedef struct {
43 MonoAddressEntry *entries;
44 char **aliases;
45 } MonoAddressInfo;
47 typedef union {
48 struct sockaddr_in v4;
49 struct sockaddr_in6 v6;
50 struct sockaddr addr;
51 } MonoSocketAddress;
53 /* This only supports IPV4 / IPV6 and tcp */
54 int mono_get_address_info (const char *hostname, int port, int flags, MonoAddressInfo **res) MONO_INTERNAL;
56 void mono_free_address_info (MonoAddressInfo *ai) MONO_INTERNAL;
58 void mono_socket_address_init (MonoSocketAddress *sa, socklen_t *len, int family, const void *address, int port) MONO_INTERNAL;
60 void *mono_get_local_interfaces (int family, int *interface_count) MONO_INTERNAL;
62 #ifndef HAVE_INET_PTON
63 int inet_pton (int family, const char *address, void *inaddrp) MONO_INTERNAL;
64 #endif
66 int mono_networking_get_tcp_protocol (void) MONO_INTERNAL;
67 int mono_networking_get_ip_protocol (void) MONO_INTERNAL;
68 int mono_networking_get_ipv6_protocol (void) MONO_INTERNAL;
70 #endif