2 * networking.c: Portable networking functions
5 * Rodrigo Kumpera (kumpera@gmail.com)
10 #include <mono/utils/networking.h>
14 mono_free_address_info (MonoAddressInfo *ai)
16 MonoAddressEntry *cur = ai->entries, *next;
19 g_free ((void*)cur->canonical_name);
23 g_strfreev (ai->aliases);
28 /* port in host order, address in network order */
30 mono_socket_address_init (MonoSocketAddress *sa, socklen_t *len, int family, const void *address, int port)
32 memset (sa, 0, sizeof (MonoSocketAddress));
33 if (family == AF_INET) {
34 *len = sizeof (struct sockaddr_in);
36 sa->v4.sin_family = family;
37 sa->v4.sin_addr = *(struct in_addr*)address;
38 sa->v4.sin_port = htons (port);
39 #if HAVE_SOCKADDR_IN_SIN_LEN
40 sa->v4.sin_len = sizeof (*len);
42 } else if (family == AF_INET6) {
43 *len = sizeof (struct sockaddr_in6);
45 sa->v6.sin6_family = family;
46 sa->v6.sin6_addr = *(struct in6_addr*)address;
47 sa->v6.sin6_port = htons (port);
48 #if HAVE_SOCKADDR_IN6_SIN_LEN
49 sa->v6.sin6_len = sizeof (*len);
52 g_error ("Cannot handle address family %d", family);