Merge pull request #5675 from mono/glib-debug-symbols
[mono.git] / support / map.c
index 737c217727585521e981daf3f93ed8c7b5eb1f7b..a0580964684a6c532f2f9378dd11e31005a21ee7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * This file was automatically generated by create-native-map from /cvs/mono/mcs/class/lib/net_4_5/Mono.Posix.dll.
+ * This file was automatically generated by create-native-map from ../mcs/class/lib/net_4_x/Mono.Posix.dll.
  *
  * DO NOT MODIFY.
  */
@@ -27,6 +27,9 @@
  */
 #include <sys/types.h>
 #include <sys/stat.h>
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif /* ndef HAVE_NETINET_IN_H */
 #ifdef HAVE_SYS_TIME_H
 #include <sys/time.h>
 #endif /* ndef HAVE_SYS_TIME_H */
@@ -45,6 +48,9 @@
 #ifdef HAVE_SYS_MMAN_H
 #include <sys/mman.h>
 #endif /* ndef HAVE_SYS_MMAN_H */
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif /* ndef HAVE_SYS_SOCKET_H */
 #ifdef HAVE_SYS_UIO_H
 #include <sys/uio.h>
 #endif /* ndef HAVE_SYS_UIO_H */
@@ -361,6 +367,48 @@ int Mono_Posix_ToAtFlags (int x, int *r)
        return 0;
 }
 
+#ifdef HAVE_STRUCT_CMSGHDR
+int
+Mono_Posix_FromCmsghdr (struct Mono_Posix_Cmsghdr *from, struct cmsghdr *to)
+{
+       _cnm_return_val_if_overflow (gint64, from->cmsg_len, -1);
+
+       memset (to, 0, sizeof(*to));
+
+       to->cmsg_len   = from->cmsg_len;
+       if (Mono_Posix_FromUnixSocketProtocol (from->cmsg_level, &to->cmsg_level) != 0) {
+               return -1;
+       }
+       if (Mono_Posix_FromUnixSocketControlMessage (from->cmsg_type, &to->cmsg_type) != 0) {
+               return -1;
+       }
+
+       return 0;
+}
+#endif /* ndef HAVE_STRUCT_CMSGHDR */
+
+
+#ifdef HAVE_STRUCT_CMSGHDR
+int
+Mono_Posix_ToCmsghdr (struct cmsghdr *from, struct Mono_Posix_Cmsghdr *to)
+{
+       _cnm_return_val_if_overflow (gint64, from->cmsg_len, -1);
+
+       memset (to, 0, sizeof(*to));
+
+       to->cmsg_len   = from->cmsg_len;
+       if (Mono_Posix_ToUnixSocketProtocol (from->cmsg_level, &to->cmsg_level) != 0) {
+               return -1;
+       }
+       if (Mono_Posix_ToUnixSocketControlMessage (from->cmsg_type, &to->cmsg_type) != 0) {
+               return -1;
+       }
+
+       return 0;
+}
+#endif /* ndef HAVE_STRUCT_CMSGHDR */
+
+
 int Mono_Posix_FromConfstrName (int x, int *r)
 {
        *r = 0;
@@ -3115,6 +3163,40 @@ Mono_Posix_ToIovec (struct iovec *from, struct Mono_Posix_Iovec *to)
 #endif /* ndef HAVE_STRUCT_IOVEC */
 
 
+#ifdef HAVE_STRUCT_LINGER
+int
+Mono_Posix_FromLinger (struct Mono_Posix_Linger *from, struct linger *to)
+{
+       _cnm_return_val_if_overflow (int, from->l_onoff, -1);
+       _cnm_return_val_if_overflow (int, from->l_linger, -1);
+
+       memset (to, 0, sizeof(*to));
+
+       to->l_onoff  = from->l_onoff;
+       to->l_linger = from->l_linger;
+
+       return 0;
+}
+#endif /* ndef HAVE_STRUCT_LINGER */
+
+
+#ifdef HAVE_STRUCT_LINGER
+int
+Mono_Posix_ToLinger (struct linger *from, struct Mono_Posix_Linger *to)
+{
+       _cnm_return_val_if_overflow (int, from->l_onoff, -1);
+       _cnm_return_val_if_overflow (int, from->l_linger, -1);
+
+       memset (to, 0, sizeof(*to));
+
+       to->l_onoff  = from->l_onoff;
+       to->l_linger = from->l_linger;
+
+       return 0;
+}
+#endif /* ndef HAVE_STRUCT_LINGER */
+
+
 int Mono_Posix_FromLockType (short x, short *r)
 {
        *r = 0;
@@ -3217,6 +3299,212 @@ int Mono_Posix_ToLockfCommand (int x, int *r)
        errno = EINVAL; return -1;
 }
 
+int Mono_Posix_FromMessageFlags (int x, int *r)
+{
+       *r = 0;
+       if ((x & Mono_Posix_MessageFlags_MSG_CMSG_CLOEXEC) == Mono_Posix_MessageFlags_MSG_CMSG_CLOEXEC)
+#ifdef MSG_CMSG_CLOEXEC
+               *r |= MSG_CMSG_CLOEXEC;
+#else /* def MSG_CMSG_CLOEXEC */
+               {errno = EINVAL; return -1;}
+#endif /* ndef MSG_CMSG_CLOEXEC */
+       if ((x & Mono_Posix_MessageFlags_MSG_CONFIRM) == Mono_Posix_MessageFlags_MSG_CONFIRM)
+#ifdef MSG_CONFIRM
+               *r |= MSG_CONFIRM;
+#else /* def MSG_CONFIRM */
+               {errno = EINVAL; return -1;}
+#endif /* ndef MSG_CONFIRM */
+       if ((x & Mono_Posix_MessageFlags_MSG_CTRUNC) == Mono_Posix_MessageFlags_MSG_CTRUNC)
+#ifdef MSG_CTRUNC
+               *r |= MSG_CTRUNC;
+#else /* def MSG_CTRUNC */
+               {errno = EINVAL; return -1;}
+#endif /* ndef MSG_CTRUNC */
+       if ((x & Mono_Posix_MessageFlags_MSG_DONTROUTE) == Mono_Posix_MessageFlags_MSG_DONTROUTE)
+#ifdef MSG_DONTROUTE
+               *r |= MSG_DONTROUTE;
+#else /* def MSG_DONTROUTE */
+               {errno = EINVAL; return -1;}
+#endif /* ndef MSG_DONTROUTE */
+       if ((x & Mono_Posix_MessageFlags_MSG_DONTWAIT) == Mono_Posix_MessageFlags_MSG_DONTWAIT)
+#ifdef MSG_DONTWAIT
+               *r |= MSG_DONTWAIT;
+#else /* def MSG_DONTWAIT */
+               {errno = EINVAL; return -1;}
+#endif /* ndef MSG_DONTWAIT */
+       if ((x & Mono_Posix_MessageFlags_MSG_EOR) == Mono_Posix_MessageFlags_MSG_EOR)
+#ifdef MSG_EOR
+               *r |= MSG_EOR;
+#else /* def MSG_EOR */
+               {errno = EINVAL; return -1;}
+#endif /* ndef MSG_EOR */
+       if ((x & Mono_Posix_MessageFlags_MSG_ERRQUEUE) == Mono_Posix_MessageFlags_MSG_ERRQUEUE)
+#ifdef MSG_ERRQUEUE
+               *r |= MSG_ERRQUEUE;
+#else /* def MSG_ERRQUEUE */
+               {errno = EINVAL; return -1;}
+#endif /* ndef MSG_ERRQUEUE */
+       if ((x & Mono_Posix_MessageFlags_MSG_FASTOPEN) == Mono_Posix_MessageFlags_MSG_FASTOPEN)
+#ifdef MSG_FASTOPEN
+               *r |= MSG_FASTOPEN;
+#else /* def MSG_FASTOPEN */
+               {errno = EINVAL; return -1;}
+#endif /* ndef MSG_FASTOPEN */
+       if ((x & Mono_Posix_MessageFlags_MSG_FIN) == Mono_Posix_MessageFlags_MSG_FIN)
+#ifdef MSG_FIN
+               *r |= MSG_FIN;
+#else /* def MSG_FIN */
+               {errno = EINVAL; return -1;}
+#endif /* ndef MSG_FIN */
+       if ((x & Mono_Posix_MessageFlags_MSG_MORE) == Mono_Posix_MessageFlags_MSG_MORE)
+#ifdef MSG_MORE
+               *r |= MSG_MORE;
+#else /* def MSG_MORE */
+               {errno = EINVAL; return -1;}
+#endif /* ndef MSG_MORE */
+       if ((x & Mono_Posix_MessageFlags_MSG_NOSIGNAL) == Mono_Posix_MessageFlags_MSG_NOSIGNAL)
+#ifdef MSG_NOSIGNAL
+               *r |= MSG_NOSIGNAL;
+#else /* def MSG_NOSIGNAL */
+               {errno = EINVAL; return -1;}
+#endif /* ndef MSG_NOSIGNAL */
+       if ((x & Mono_Posix_MessageFlags_MSG_OOB) == Mono_Posix_MessageFlags_MSG_OOB)
+#ifdef MSG_OOB
+               *r |= MSG_OOB;
+#else /* def MSG_OOB */
+               {errno = EINVAL; return -1;}
+#endif /* ndef MSG_OOB */
+       if ((x & Mono_Posix_MessageFlags_MSG_PEEK) == Mono_Posix_MessageFlags_MSG_PEEK)
+#ifdef MSG_PEEK
+               *r |= MSG_PEEK;
+#else /* def MSG_PEEK */
+               {errno = EINVAL; return -1;}
+#endif /* ndef MSG_PEEK */
+       if ((x & Mono_Posix_MessageFlags_MSG_PROXY) == Mono_Posix_MessageFlags_MSG_PROXY)
+#ifdef MSG_PROXY
+               *r |= MSG_PROXY;
+#else /* def MSG_PROXY */
+               {errno = EINVAL; return -1;}
+#endif /* ndef MSG_PROXY */
+       if ((x & Mono_Posix_MessageFlags_MSG_RST) == Mono_Posix_MessageFlags_MSG_RST)
+#ifdef MSG_RST
+               *r |= MSG_RST;
+#else /* def MSG_RST */
+               {errno = EINVAL; return -1;}
+#endif /* ndef MSG_RST */
+       if ((x & Mono_Posix_MessageFlags_MSG_SYN) == Mono_Posix_MessageFlags_MSG_SYN)
+#ifdef MSG_SYN
+               *r |= MSG_SYN;
+#else /* def MSG_SYN */
+               {errno = EINVAL; return -1;}
+#endif /* ndef MSG_SYN */
+       if ((x & Mono_Posix_MessageFlags_MSG_TRUNC) == Mono_Posix_MessageFlags_MSG_TRUNC)
+#ifdef MSG_TRUNC
+               *r |= MSG_TRUNC;
+#else /* def MSG_TRUNC */
+               {errno = EINVAL; return -1;}
+#endif /* ndef MSG_TRUNC */
+       if ((x & Mono_Posix_MessageFlags_MSG_WAITALL) == Mono_Posix_MessageFlags_MSG_WAITALL)
+#ifdef MSG_WAITALL
+               *r |= MSG_WAITALL;
+#else /* def MSG_WAITALL */
+               {errno = EINVAL; return -1;}
+#endif /* ndef MSG_WAITALL */
+       if ((x & Mono_Posix_MessageFlags_MSG_WAITFORONE) == Mono_Posix_MessageFlags_MSG_WAITFORONE)
+#ifdef MSG_WAITFORONE
+               *r |= MSG_WAITFORONE;
+#else /* def MSG_WAITFORONE */
+               {errno = EINVAL; return -1;}
+#endif /* ndef MSG_WAITFORONE */
+       if (x == 0)
+               return 0;
+       return 0;
+}
+
+int Mono_Posix_ToMessageFlags (int x, int *r)
+{
+       *r = 0;
+       if (x == 0)
+               return 0;
+#ifdef MSG_CMSG_CLOEXEC
+       if ((x & MSG_CMSG_CLOEXEC) == MSG_CMSG_CLOEXEC)
+               *r |= Mono_Posix_MessageFlags_MSG_CMSG_CLOEXEC;
+#endif /* ndef MSG_CMSG_CLOEXEC */
+#ifdef MSG_CONFIRM
+       if ((x & MSG_CONFIRM) == MSG_CONFIRM)
+               *r |= Mono_Posix_MessageFlags_MSG_CONFIRM;
+#endif /* ndef MSG_CONFIRM */
+#ifdef MSG_CTRUNC
+       if ((x & MSG_CTRUNC) == MSG_CTRUNC)
+               *r |= Mono_Posix_MessageFlags_MSG_CTRUNC;
+#endif /* ndef MSG_CTRUNC */
+#ifdef MSG_DONTROUTE
+       if ((x & MSG_DONTROUTE) == MSG_DONTROUTE)
+               *r |= Mono_Posix_MessageFlags_MSG_DONTROUTE;
+#endif /* ndef MSG_DONTROUTE */
+#ifdef MSG_DONTWAIT
+       if ((x & MSG_DONTWAIT) == MSG_DONTWAIT)
+               *r |= Mono_Posix_MessageFlags_MSG_DONTWAIT;
+#endif /* ndef MSG_DONTWAIT */
+#ifdef MSG_EOR
+       if ((x & MSG_EOR) == MSG_EOR)
+               *r |= Mono_Posix_MessageFlags_MSG_EOR;
+#endif /* ndef MSG_EOR */
+#ifdef MSG_ERRQUEUE
+       if ((x & MSG_ERRQUEUE) == MSG_ERRQUEUE)
+               *r |= Mono_Posix_MessageFlags_MSG_ERRQUEUE;
+#endif /* ndef MSG_ERRQUEUE */
+#ifdef MSG_FASTOPEN
+       if ((x & MSG_FASTOPEN) == MSG_FASTOPEN)
+               *r |= Mono_Posix_MessageFlags_MSG_FASTOPEN;
+#endif /* ndef MSG_FASTOPEN */
+#ifdef MSG_FIN
+       if ((x & MSG_FIN) == MSG_FIN)
+               *r |= Mono_Posix_MessageFlags_MSG_FIN;
+#endif /* ndef MSG_FIN */
+#ifdef MSG_MORE
+       if ((x & MSG_MORE) == MSG_MORE)
+               *r |= Mono_Posix_MessageFlags_MSG_MORE;
+#endif /* ndef MSG_MORE */
+#ifdef MSG_NOSIGNAL
+       if ((x & MSG_NOSIGNAL) == MSG_NOSIGNAL)
+               *r |= Mono_Posix_MessageFlags_MSG_NOSIGNAL;
+#endif /* ndef MSG_NOSIGNAL */
+#ifdef MSG_OOB
+       if ((x & MSG_OOB) == MSG_OOB)
+               *r |= Mono_Posix_MessageFlags_MSG_OOB;
+#endif /* ndef MSG_OOB */
+#ifdef MSG_PEEK
+       if ((x & MSG_PEEK) == MSG_PEEK)
+               *r |= Mono_Posix_MessageFlags_MSG_PEEK;
+#endif /* ndef MSG_PEEK */
+#ifdef MSG_PROXY
+       if ((x & MSG_PROXY) == MSG_PROXY)
+               *r |= Mono_Posix_MessageFlags_MSG_PROXY;
+#endif /* ndef MSG_PROXY */
+#ifdef MSG_RST
+       if ((x & MSG_RST) == MSG_RST)
+               *r |= Mono_Posix_MessageFlags_MSG_RST;
+#endif /* ndef MSG_RST */
+#ifdef MSG_SYN
+       if ((x & MSG_SYN) == MSG_SYN)
+               *r |= Mono_Posix_MessageFlags_MSG_SYN;
+#endif /* ndef MSG_SYN */
+#ifdef MSG_TRUNC
+       if ((x & MSG_TRUNC) == MSG_TRUNC)
+               *r |= Mono_Posix_MessageFlags_MSG_TRUNC;
+#endif /* ndef MSG_TRUNC */
+#ifdef MSG_WAITALL
+       if ((x & MSG_WAITALL) == MSG_WAITALL)
+               *r |= Mono_Posix_MessageFlags_MSG_WAITALL;
+#endif /* ndef MSG_WAITALL */
+#ifdef MSG_WAITFORONE
+       if ((x & MSG_WAITFORONE) == MSG_WAITFORONE)
+               *r |= Mono_Posix_MessageFlags_MSG_WAITFORONE;
+#endif /* ndef MSG_WAITFORONE */
+       return 0;
+}
+
 int Mono_Posix_FromMlockallFlags (int x, int *r)
 {
        *r = 0;
@@ -3634,12 +3922,17 @@ int Mono_Posix_ToMountFlags (guint64 x, guint64 *r)
 int Mono_Posix_FromMremapFlags (guint64 x, guint64 *r)
 {
        *r = 0;
+#ifndef __NetBSD__
        if ((x & Mono_Posix_MremapFlags_MREMAP_MAYMOVE) == Mono_Posix_MremapFlags_MREMAP_MAYMOVE)
 #ifdef MREMAP_MAYMOVE
                *r |= MREMAP_MAYMOVE;
 #else /* def MREMAP_MAYMOVE */
                {errno = EINVAL; return -1;}
 #endif /* ndef MREMAP_MAYMOVE */
+#else /* def __NetBSD__ */
+       if ((x & Mono_Posix_MremapFlags_MREMAP_MAYMOVE) != Mono_Posix_MremapFlags_MREMAP_MAYMOVE)
+               *r = MAP_FIXED;
+#endif /* def __NetBSD__ */
        if (x == 0)
                return 0;
        return 0;
@@ -3648,12 +3941,17 @@ int Mono_Posix_FromMremapFlags (guint64 x, guint64 *r)
 int Mono_Posix_ToMremapFlags (guint64 x, guint64 *r)
 {
        *r = 0;
+#ifndef __NetBSD__
        if (x == 0)
                return 0;
 #ifdef MREMAP_MAYMOVE
        if ((x & MREMAP_MAYMOVE) == MREMAP_MAYMOVE)
                *r |= Mono_Posix_MremapFlags_MREMAP_MAYMOVE;
 #endif /* ndef MREMAP_MAYMOVE */
+#else /* def __NetBSD__ */
+       if ((x & MAP_FIXED) != MAP_FIXED)
+               *r |= Mono_Posix_MremapFlags_MREMAP_MAYMOVE;
+#endif
        return 0;
 }
 
@@ -4491,6 +4789,52 @@ int Mono_Posix_ToSeekFlags (short x, short *r)
        errno = EINVAL; return -1;
 }
 
+int Mono_Posix_FromShutdownOption (int x, int *r)
+{
+       *r = 0;
+       if (x == Mono_Posix_ShutdownOption_SHUT_RD)
+#ifdef SHUT_RD
+               {*r = SHUT_RD; return 0;}
+#else /* def SHUT_RD */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SHUT_RD */
+       if (x == Mono_Posix_ShutdownOption_SHUT_RDWR)
+#ifdef SHUT_RDWR
+               {*r = SHUT_RDWR; return 0;}
+#else /* def SHUT_RDWR */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SHUT_RDWR */
+       if (x == Mono_Posix_ShutdownOption_SHUT_WR)
+#ifdef SHUT_WR
+               {*r = SHUT_WR; return 0;}
+#else /* def SHUT_WR */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SHUT_WR */
+       if (x == 0)
+               return 0;
+       errno = EINVAL; return -1;
+}
+
+int Mono_Posix_ToShutdownOption (int x, int *r)
+{
+       *r = 0;
+       if (x == 0)
+               return 0;
+#ifdef SHUT_RD
+       if (x == SHUT_RD)
+               {*r = Mono_Posix_ShutdownOption_SHUT_RD; return 0;}
+#endif /* ndef SHUT_RD */
+#ifdef SHUT_RDWR
+       if (x == SHUT_RDWR)
+               {*r = Mono_Posix_ShutdownOption_SHUT_RDWR; return 0;}
+#endif /* ndef SHUT_RDWR */
+#ifdef SHUT_WR
+       if (x == SHUT_WR)
+               {*r = Mono_Posix_ShutdownOption_SHUT_WR; return 0;}
+#endif /* ndef SHUT_WR */
+       errno = EINVAL; return -1;
+}
+
 int Mono_Posix_FromSignum (int x, int *r)
 {
        *r = 0;
@@ -4857,6 +5201,172 @@ int Mono_Posix_ToSignum (int x, int *r)
        errno = EINVAL; return -1;
 }
 
+#ifdef HAVE_STRUCT_SOCKADDR_IN
+int
+Mono_Posix_FromSockaddrIn (struct Mono_Posix_SockaddrIn *from, struct sockaddr_in *to)
+{
+       _cnm_return_val_if_overflow (unsigned short, from->sin_port, -1);
+
+       memset (to, 0, sizeof(*to));
+
+       to->sin_port = from->sin_port;
+       if (Mono_Posix_FromInAddr (&from->sin_addr, &to->sin_addr) != 0) {
+               return -1;
+       }
+
+       return 0;
+}
+#endif /* ndef HAVE_STRUCT_SOCKADDR_IN */
+
+
+#ifdef HAVE_STRUCT_SOCKADDR_IN
+int
+Mono_Posix_ToSockaddrIn (struct sockaddr_in *from, struct Mono_Posix_SockaddrIn *to)
+{
+       _cnm_return_val_if_overflow (unsigned short, from->sin_port, -1);
+
+       memset (to, 0, sizeof(*to));
+
+       to->sin_port = from->sin_port;
+       if (Mono_Posix_ToInAddr (&from->sin_addr, &to->sin_addr) != 0) {
+               return -1;
+       }
+
+       return 0;
+}
+#endif /* ndef HAVE_STRUCT_SOCKADDR_IN */
+
+
+#if defined(HAVE_STRUCT_SOCKADDR_IN6) && !defined(HOST_WIN32)
+int
+Mono_Posix_FromSockaddrIn6 (struct Mono_Posix_SockaddrIn6 *from, struct sockaddr_in6 *to)
+{
+       _cnm_return_val_if_overflow (unsigned short, from->sin6_port, -1);
+       _cnm_return_val_if_overflow (unsigned int, from->sin6_flowinfo, -1);
+       _cnm_return_val_if_overflow (unsigned int, from->sin6_scope_id, -1);
+
+       memset (to, 0, sizeof(*to));
+
+       to->sin6_port     = from->sin6_port;
+       to->sin6_flowinfo = from->sin6_flowinfo;
+       if (Mono_Posix_FromIn6Addr (&from->sin6_addr, &to->sin6_addr) != 0) {
+               return -1;
+       }
+       to->sin6_scope_id = from->sin6_scope_id;
+
+       return 0;
+}
+#endif /* ndef HAVE_STRUCT_SOCKADDR_IN6 */
+
+
+#if defined(HAVE_STRUCT_SOCKADDR_IN6) && !defined(HOST_WIN32)
+int
+Mono_Posix_ToSockaddrIn6 (struct sockaddr_in6 *from, struct Mono_Posix_SockaddrIn6 *to)
+{
+       _cnm_return_val_if_overflow (unsigned short, from->sin6_port, -1);
+       _cnm_return_val_if_overflow (unsigned int, from->sin6_flowinfo, -1);
+       _cnm_return_val_if_overflow (unsigned int, from->sin6_scope_id, -1);
+
+       memset (to, 0, sizeof(*to));
+
+       to->sin6_port     = from->sin6_port;
+       to->sin6_flowinfo = from->sin6_flowinfo;
+       if (Mono_Posix_ToIn6Addr (&from->sin6_addr, &to->sin6_addr) != 0) {
+               return -1;
+       }
+       to->sin6_scope_id = from->sin6_scope_id;
+
+       return 0;
+}
+#endif /* ndef HAVE_STRUCT_SOCKADDR_IN6 */
+
+
+int Mono_Posix_FromSockaddrType (int x, int *r)
+{
+       *r = 0;
+       if (x == Mono_Posix_SockaddrType_Invalid)
+#ifdef Invalid
+               {*r = Invalid; return 0;}
+#else /* def Invalid */
+               {errno = EINVAL; return -1;}
+#endif /* ndef Invalid */
+       if (x == Mono_Posix_SockaddrType_MustBeWrapped)
+#ifdef MustBeWrapped
+               {*r = MustBeWrapped; return 0;}
+#else /* def MustBeWrapped */
+               {errno = EINVAL; return -1;}
+#endif /* ndef MustBeWrapped */
+       if (x == Mono_Posix_SockaddrType_Sockaddr)
+#ifdef Sockaddr
+               {*r = Sockaddr; return 0;}
+#else /* def Sockaddr */
+               {errno = EINVAL; return -1;}
+#endif /* ndef Sockaddr */
+       if (x == Mono_Posix_SockaddrType_SockaddrIn)
+#ifdef SockaddrIn
+               {*r = SockaddrIn; return 0;}
+#else /* def SockaddrIn */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SockaddrIn */
+       if (x == Mono_Posix_SockaddrType_SockaddrIn6)
+#ifdef SockaddrIn6
+               {*r = SockaddrIn6; return 0;}
+#else /* def SockaddrIn6 */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SockaddrIn6 */
+       if (x == Mono_Posix_SockaddrType_SockaddrStorage)
+#ifdef SockaddrStorage
+               {*r = SockaddrStorage; return 0;}
+#else /* def SockaddrStorage */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SockaddrStorage */
+       if (x == Mono_Posix_SockaddrType_SockaddrUn)
+#ifdef SockaddrUn
+               {*r = SockaddrUn; return 0;}
+#else /* def SockaddrUn */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SockaddrUn */
+       if (x == 0)
+               return 0;
+       errno = EINVAL; return -1;
+}
+
+int Mono_Posix_ToSockaddrType (int x, int *r)
+{
+       *r = 0;
+       if (x == 0)
+               return 0;
+#ifdef Invalid
+       if (x == Invalid)
+               {*r = Mono_Posix_SockaddrType_Invalid; return 0;}
+#endif /* ndef Invalid */
+#ifdef MustBeWrapped
+       if (x == MustBeWrapped)
+               {*r = Mono_Posix_SockaddrType_MustBeWrapped; return 0;}
+#endif /* ndef MustBeWrapped */
+#ifdef Sockaddr
+       if (x == Sockaddr)
+               {*r = Mono_Posix_SockaddrType_Sockaddr; return 0;}
+#endif /* ndef Sockaddr */
+#ifdef SockaddrIn
+       if (x == SockaddrIn)
+               {*r = Mono_Posix_SockaddrType_SockaddrIn; return 0;}
+#endif /* ndef SockaddrIn */
+#ifdef SockaddrIn6
+       if (x == SockaddrIn6)
+               {*r = Mono_Posix_SockaddrType_SockaddrIn6; return 0;}
+#endif /* ndef SockaddrIn6 */
+#ifdef SockaddrStorage
+       if (x == SockaddrStorage)
+               {*r = Mono_Posix_SockaddrType_SockaddrStorage; return 0;}
+#endif /* ndef SockaddrStorage */
+#ifdef SockaddrUn
+       if (x == SockaddrUn)
+               {*r = Mono_Posix_SockaddrType_SockaddrUn; return 0;}
+#endif /* ndef SockaddrUn */
+       errno = EINVAL; return -1;
+}
+
 int Mono_Posix_FromSysconfName (int x, int *r)
 {
        *r = 0;
@@ -7373,6 +7883,1332 @@ Mono_Posix_ToTimezone (struct timezone *from, struct Mono_Posix_Timezone *to)
 #endif /* ndef HAVE_STRUCT_TIMEZONE */
 
 
+int Mono_Posix_FromUnixAddressFamily (int x, int *r)
+{
+       *r = 0;
+       if (x == Mono_Posix_UnixAddressFamily_AF_ALG)
+#ifdef AF_ALG
+               {*r = AF_ALG; return 0;}
+#else /* def AF_ALG */
+               {errno = EINVAL; return -1;}
+#endif /* ndef AF_ALG */
+       if (x == Mono_Posix_UnixAddressFamily_AF_APPLETALK)
+#ifdef AF_APPLETALK
+               {*r = AF_APPLETALK; return 0;}
+#else /* def AF_APPLETALK */
+               {errno = EINVAL; return -1;}
+#endif /* ndef AF_APPLETALK */
+       if (x == Mono_Posix_UnixAddressFamily_AF_ASH)
+#ifdef AF_ASH
+               {*r = AF_ASH; return 0;}
+#else /* def AF_ASH */
+               {errno = EINVAL; return -1;}
+#endif /* ndef AF_ASH */
+       if (x == Mono_Posix_UnixAddressFamily_AF_ATMPVC)
+#ifdef AF_ATMPVC
+               {*r = AF_ATMPVC; return 0;}
+#else /* def AF_ATMPVC */
+               {errno = EINVAL; return -1;}
+#endif /* ndef AF_ATMPVC */
+       if (x == Mono_Posix_UnixAddressFamily_AF_ATMSVC)
+#ifdef AF_ATMSVC
+               {*r = AF_ATMSVC; return 0;}
+#else /* def AF_ATMSVC */
+               {errno = EINVAL; return -1;}
+#endif /* ndef AF_ATMSVC */
+       if (x == Mono_Posix_UnixAddressFamily_AF_AX25)
+#ifdef AF_AX25
+               {*r = AF_AX25; return 0;}
+#else /* def AF_AX25 */
+               {errno = EINVAL; return -1;}
+#endif /* ndef AF_AX25 */
+       if (x == Mono_Posix_UnixAddressFamily_AF_BLUETOOTH)
+#ifdef AF_BLUETOOTH
+               {*r = AF_BLUETOOTH; return 0;}
+#else /* def AF_BLUETOOTH */
+               {errno = EINVAL; return -1;}
+#endif /* ndef AF_BLUETOOTH */
+       if (x == Mono_Posix_UnixAddressFamily_AF_BRIDGE)
+#ifdef AF_BRIDGE
+               {*r = AF_BRIDGE; return 0;}
+#else /* def AF_BRIDGE */
+               {errno = EINVAL; return -1;}
+#endif /* ndef AF_BRIDGE */
+       if (x == Mono_Posix_UnixAddressFamily_AF_CAIF)
+#ifdef AF_CAIF
+               {*r = AF_CAIF; return 0;}
+#else /* def AF_CAIF */
+               {errno = EINVAL; return -1;}
+#endif /* ndef AF_CAIF */
+       if (x == Mono_Posix_UnixAddressFamily_AF_CAN)
+#ifdef AF_CAN
+               {*r = AF_CAN; return 0;}
+#else /* def AF_CAN */
+               {errno = EINVAL; return -1;}
+#endif /* ndef AF_CAN */
+       if (x == Mono_Posix_UnixAddressFamily_AF_DECnet)
+#ifdef AF_DECnet
+               {*r = AF_DECnet; return 0;}
+#else /* def AF_DECnet */
+               {errno = EINVAL; return -1;}
+#endif /* ndef AF_DECnet */
+       if (x == Mono_Posix_UnixAddressFamily_AF_ECONET)
+#ifdef AF_ECONET
+               {*r = AF_ECONET; return 0;}
+#else /* def AF_ECONET */
+               {errno = EINVAL; return -1;}
+#endif /* ndef AF_ECONET */
+       if (x == Mono_Posix_UnixAddressFamily_AF_IEEE802154)
+#ifdef AF_IEEE802154
+               {*r = AF_IEEE802154; return 0;}
+#else /* def AF_IEEE802154 */
+               {errno = EINVAL; return -1;}
+#endif /* ndef AF_IEEE802154 */
+       if (x == Mono_Posix_UnixAddressFamily_AF_INET)
+#ifdef AF_INET
+               {*r = AF_INET; return 0;}
+#else /* def AF_INET */
+               {errno = EINVAL; return -1;}
+#endif /* ndef AF_INET */
+       if (x == Mono_Posix_UnixAddressFamily_AF_INET6)
+#ifdef AF_INET6
+               {*r = AF_INET6; return 0;}
+#else /* def AF_INET6 */
+               {errno = EINVAL; return -1;}
+#endif /* ndef AF_INET6 */
+       if (x == Mono_Posix_UnixAddressFamily_AF_IPX)
+#ifdef AF_IPX
+               {*r = AF_IPX; return 0;}
+#else /* def AF_IPX */
+               {errno = EINVAL; return -1;}
+#endif /* ndef AF_IPX */
+       if (x == Mono_Posix_UnixAddressFamily_AF_IRDA)
+#ifdef AF_IRDA
+               {*r = AF_IRDA; return 0;}
+#else /* def AF_IRDA */
+               {errno = EINVAL; return -1;}
+#endif /* ndef AF_IRDA */
+       if (x == Mono_Posix_UnixAddressFamily_AF_ISDN)
+#ifdef AF_ISDN
+               {*r = AF_ISDN; return 0;}
+#else /* def AF_ISDN */
+               {errno = EINVAL; return -1;}
+#endif /* ndef AF_ISDN */
+       if (x == Mono_Posix_UnixAddressFamily_AF_IUCV)
+#ifdef AF_IUCV
+               {*r = AF_IUCV; return 0;}
+#else /* def AF_IUCV */
+               {errno = EINVAL; return -1;}
+#endif /* ndef AF_IUCV */
+       if (x == Mono_Posix_UnixAddressFamily_AF_KEY)
+#ifdef AF_KEY
+               {*r = AF_KEY; return 0;}
+#else /* def AF_KEY */
+               {errno = EINVAL; return -1;}
+#endif /* ndef AF_KEY */
+       if (x == Mono_Posix_UnixAddressFamily_AF_LLC)
+#ifdef AF_LLC
+               {*r = AF_LLC; return 0;}
+#else /* def AF_LLC */
+               {errno = EINVAL; return -1;}
+#endif /* ndef AF_LLC */
+       if (x == Mono_Posix_UnixAddressFamily_AF_NETBEUI)
+#ifdef AF_NETBEUI
+               {*r = AF_NETBEUI; return 0;}
+#else /* def AF_NETBEUI */
+               {errno = EINVAL; return -1;}
+#endif /* ndef AF_NETBEUI */
+       if (x == Mono_Posix_UnixAddressFamily_AF_NETLINK)
+#ifdef AF_NETLINK
+               {*r = AF_NETLINK; return 0;}
+#else /* def AF_NETLINK */
+               {errno = EINVAL; return -1;}
+#endif /* ndef AF_NETLINK */
+       if (x == Mono_Posix_UnixAddressFamily_AF_NETROM)
+#ifdef AF_NETROM
+               {*r = AF_NETROM; return 0;}
+#else /* def AF_NETROM */
+               {errno = EINVAL; return -1;}
+#endif /* ndef AF_NETROM */
+       if (x == Mono_Posix_UnixAddressFamily_AF_NFC)
+#ifdef AF_NFC
+               {*r = AF_NFC; return 0;}
+#else /* def AF_NFC */
+               {errno = EINVAL; return -1;}
+#endif /* ndef AF_NFC */
+       if (x == Mono_Posix_UnixAddressFamily_AF_PACKET)
+#ifdef AF_PACKET
+               {*r = AF_PACKET; return 0;}
+#else /* def AF_PACKET */
+               {errno = EINVAL; return -1;}
+#endif /* ndef AF_PACKET */
+       if (x == Mono_Posix_UnixAddressFamily_AF_PHONET)
+#ifdef AF_PHONET
+               {*r = AF_PHONET; return 0;}
+#else /* def AF_PHONET */
+               {errno = EINVAL; return -1;}
+#endif /* ndef AF_PHONET */
+       if (x == Mono_Posix_UnixAddressFamily_AF_PPPOX)
+#ifdef AF_PPPOX
+               {*r = AF_PPPOX; return 0;}
+#else /* def AF_PPPOX */
+               {errno = EINVAL; return -1;}
+#endif /* ndef AF_PPPOX */
+       if (x == Mono_Posix_UnixAddressFamily_AF_RDS)
+#ifdef AF_RDS
+               {*r = AF_RDS; return 0;}
+#else /* def AF_RDS */
+               {errno = EINVAL; return -1;}
+#endif /* ndef AF_RDS */
+       if (x == Mono_Posix_UnixAddressFamily_AF_ROSE)
+#ifdef AF_ROSE
+               {*r = AF_ROSE; return 0;}
+#else /* def AF_ROSE */
+               {errno = EINVAL; return -1;}
+#endif /* ndef AF_ROSE */
+       if (x == Mono_Posix_UnixAddressFamily_AF_RXRPC)
+#ifdef AF_RXRPC
+               {*r = AF_RXRPC; return 0;}
+#else /* def AF_RXRPC */
+               {errno = EINVAL; return -1;}
+#endif /* ndef AF_RXRPC */
+       if (x == Mono_Posix_UnixAddressFamily_AF_SECURITY)
+#ifdef AF_SECURITY
+               {*r = AF_SECURITY; return 0;}
+#else /* def AF_SECURITY */
+               {errno = EINVAL; return -1;}
+#endif /* ndef AF_SECURITY */
+       if (x == Mono_Posix_UnixAddressFamily_AF_SNA)
+#ifdef AF_SNA
+               {*r = AF_SNA; return 0;}
+#else /* def AF_SNA */
+               {errno = EINVAL; return -1;}
+#endif /* ndef AF_SNA */
+       if (x == Mono_Posix_UnixAddressFamily_AF_TIPC)
+#ifdef AF_TIPC
+               {*r = AF_TIPC; return 0;}
+#else /* def AF_TIPC */
+               {errno = EINVAL; return -1;}
+#endif /* ndef AF_TIPC */
+       if (x == Mono_Posix_UnixAddressFamily_AF_UNIX)
+#ifdef AF_UNIX
+               {*r = AF_UNIX; return 0;}
+#else /* def AF_UNIX */
+               {errno = EINVAL; return -1;}
+#endif /* ndef AF_UNIX */
+       if (x == Mono_Posix_UnixAddressFamily_AF_UNSPEC)
+#ifdef AF_UNSPEC
+               {*r = AF_UNSPEC; return 0;}
+#else /* def AF_UNSPEC */
+               {errno = EINVAL; return -1;}
+#endif /* ndef AF_UNSPEC */
+       if (x == Mono_Posix_UnixAddressFamily_AF_VSOCK)
+#ifdef AF_VSOCK
+               {*r = AF_VSOCK; return 0;}
+#else /* def AF_VSOCK */
+               {errno = EINVAL; return -1;}
+#endif /* ndef AF_VSOCK */
+       if (x == Mono_Posix_UnixAddressFamily_AF_WANPIPE)
+#ifdef AF_WANPIPE
+               {*r = AF_WANPIPE; return 0;}
+#else /* def AF_WANPIPE */
+               {errno = EINVAL; return -1;}
+#endif /* ndef AF_WANPIPE */
+       if (x == Mono_Posix_UnixAddressFamily_AF_X25)
+#ifdef AF_X25
+               {*r = AF_X25; return 0;}
+#else /* def AF_X25 */
+               {errno = EINVAL; return -1;}
+#endif /* ndef AF_X25 */
+       if (x == Mono_Posix_UnixAddressFamily_Unknown)
+#ifdef Unknown
+               {*r = Unknown; return 0;}
+#else /* def Unknown */
+               {errno = EINVAL; return -1;}
+#endif /* ndef Unknown */
+       if (x == 0)
+               return 0;
+       errno = EINVAL; return -1;
+}
+
+int Mono_Posix_ToUnixAddressFamily (int x, int *r)
+{
+       *r = 0;
+       if (x == 0)
+               return 0;
+#ifdef AF_ALG
+       if (x == AF_ALG)
+               {*r = Mono_Posix_UnixAddressFamily_AF_ALG; return 0;}
+#endif /* ndef AF_ALG */
+#ifdef AF_APPLETALK
+       if (x == AF_APPLETALK)
+               {*r = Mono_Posix_UnixAddressFamily_AF_APPLETALK; return 0;}
+#endif /* ndef AF_APPLETALK */
+#ifdef AF_ASH
+       if (x == AF_ASH)
+               {*r = Mono_Posix_UnixAddressFamily_AF_ASH; return 0;}
+#endif /* ndef AF_ASH */
+#ifdef AF_ATMPVC
+       if (x == AF_ATMPVC)
+               {*r = Mono_Posix_UnixAddressFamily_AF_ATMPVC; return 0;}
+#endif /* ndef AF_ATMPVC */
+#ifdef AF_ATMSVC
+       if (x == AF_ATMSVC)
+               {*r = Mono_Posix_UnixAddressFamily_AF_ATMSVC; return 0;}
+#endif /* ndef AF_ATMSVC */
+#ifdef AF_AX25
+       if (x == AF_AX25)
+               {*r = Mono_Posix_UnixAddressFamily_AF_AX25; return 0;}
+#endif /* ndef AF_AX25 */
+#ifdef AF_BLUETOOTH
+       if (x == AF_BLUETOOTH)
+               {*r = Mono_Posix_UnixAddressFamily_AF_BLUETOOTH; return 0;}
+#endif /* ndef AF_BLUETOOTH */
+#ifdef AF_BRIDGE
+       if (x == AF_BRIDGE)
+               {*r = Mono_Posix_UnixAddressFamily_AF_BRIDGE; return 0;}
+#endif /* ndef AF_BRIDGE */
+#ifdef AF_CAIF
+       if (x == AF_CAIF)
+               {*r = Mono_Posix_UnixAddressFamily_AF_CAIF; return 0;}
+#endif /* ndef AF_CAIF */
+#ifdef AF_CAN
+       if (x == AF_CAN)
+               {*r = Mono_Posix_UnixAddressFamily_AF_CAN; return 0;}
+#endif /* ndef AF_CAN */
+#ifdef AF_DECnet
+       if (x == AF_DECnet)
+               {*r = Mono_Posix_UnixAddressFamily_AF_DECnet; return 0;}
+#endif /* ndef AF_DECnet */
+#ifdef AF_ECONET
+       if (x == AF_ECONET)
+               {*r = Mono_Posix_UnixAddressFamily_AF_ECONET; return 0;}
+#endif /* ndef AF_ECONET */
+#ifdef AF_IEEE802154
+       if (x == AF_IEEE802154)
+               {*r = Mono_Posix_UnixAddressFamily_AF_IEEE802154; return 0;}
+#endif /* ndef AF_IEEE802154 */
+#ifdef AF_INET
+       if (x == AF_INET)
+               {*r = Mono_Posix_UnixAddressFamily_AF_INET; return 0;}
+#endif /* ndef AF_INET */
+#ifdef AF_INET6
+       if (x == AF_INET6)
+               {*r = Mono_Posix_UnixAddressFamily_AF_INET6; return 0;}
+#endif /* ndef AF_INET6 */
+#ifdef AF_IPX
+       if (x == AF_IPX)
+               {*r = Mono_Posix_UnixAddressFamily_AF_IPX; return 0;}
+#endif /* ndef AF_IPX */
+#ifdef AF_IRDA
+       if (x == AF_IRDA)
+               {*r = Mono_Posix_UnixAddressFamily_AF_IRDA; return 0;}
+#endif /* ndef AF_IRDA */
+#ifdef AF_ISDN
+       if (x == AF_ISDN)
+               {*r = Mono_Posix_UnixAddressFamily_AF_ISDN; return 0;}
+#endif /* ndef AF_ISDN */
+#ifdef AF_IUCV
+       if (x == AF_IUCV)
+               {*r = Mono_Posix_UnixAddressFamily_AF_IUCV; return 0;}
+#endif /* ndef AF_IUCV */
+#ifdef AF_KEY
+       if (x == AF_KEY)
+               {*r = Mono_Posix_UnixAddressFamily_AF_KEY; return 0;}
+#endif /* ndef AF_KEY */
+#ifdef AF_LLC
+       if (x == AF_LLC)
+               {*r = Mono_Posix_UnixAddressFamily_AF_LLC; return 0;}
+#endif /* ndef AF_LLC */
+#ifdef AF_NETBEUI
+       if (x == AF_NETBEUI)
+               {*r = Mono_Posix_UnixAddressFamily_AF_NETBEUI; return 0;}
+#endif /* ndef AF_NETBEUI */
+#ifdef AF_NETLINK
+       if (x == AF_NETLINK)
+               {*r = Mono_Posix_UnixAddressFamily_AF_NETLINK; return 0;}
+#endif /* ndef AF_NETLINK */
+#ifdef AF_NETROM
+       if (x == AF_NETROM)
+               {*r = Mono_Posix_UnixAddressFamily_AF_NETROM; return 0;}
+#endif /* ndef AF_NETROM */
+#ifdef AF_NFC
+       if (x == AF_NFC)
+               {*r = Mono_Posix_UnixAddressFamily_AF_NFC; return 0;}
+#endif /* ndef AF_NFC */
+#ifdef AF_PACKET
+       if (x == AF_PACKET)
+               {*r = Mono_Posix_UnixAddressFamily_AF_PACKET; return 0;}
+#endif /* ndef AF_PACKET */
+#ifdef AF_PHONET
+       if (x == AF_PHONET)
+               {*r = Mono_Posix_UnixAddressFamily_AF_PHONET; return 0;}
+#endif /* ndef AF_PHONET */
+#ifdef AF_PPPOX
+       if (x == AF_PPPOX)
+               {*r = Mono_Posix_UnixAddressFamily_AF_PPPOX; return 0;}
+#endif /* ndef AF_PPPOX */
+#ifdef AF_RDS
+       if (x == AF_RDS)
+               {*r = Mono_Posix_UnixAddressFamily_AF_RDS; return 0;}
+#endif /* ndef AF_RDS */
+#ifdef AF_ROSE
+       if (x == AF_ROSE)
+               {*r = Mono_Posix_UnixAddressFamily_AF_ROSE; return 0;}
+#endif /* ndef AF_ROSE */
+#ifdef AF_RXRPC
+       if (x == AF_RXRPC)
+               {*r = Mono_Posix_UnixAddressFamily_AF_RXRPC; return 0;}
+#endif /* ndef AF_RXRPC */
+#ifdef AF_SECURITY
+       if (x == AF_SECURITY)
+               {*r = Mono_Posix_UnixAddressFamily_AF_SECURITY; return 0;}
+#endif /* ndef AF_SECURITY */
+#ifdef AF_SNA
+       if (x == AF_SNA)
+               {*r = Mono_Posix_UnixAddressFamily_AF_SNA; return 0;}
+#endif /* ndef AF_SNA */
+#ifdef AF_TIPC
+       if (x == AF_TIPC)
+               {*r = Mono_Posix_UnixAddressFamily_AF_TIPC; return 0;}
+#endif /* ndef AF_TIPC */
+#ifdef AF_UNIX
+       if (x == AF_UNIX)
+               {*r = Mono_Posix_UnixAddressFamily_AF_UNIX; return 0;}
+#endif /* ndef AF_UNIX */
+#ifdef AF_UNSPEC
+       if (x == AF_UNSPEC)
+               {*r = Mono_Posix_UnixAddressFamily_AF_UNSPEC; return 0;}
+#endif /* ndef AF_UNSPEC */
+#ifdef AF_VSOCK
+       if (x == AF_VSOCK)
+               {*r = Mono_Posix_UnixAddressFamily_AF_VSOCK; return 0;}
+#endif /* ndef AF_VSOCK */
+#ifdef AF_WANPIPE
+       if (x == AF_WANPIPE)
+               {*r = Mono_Posix_UnixAddressFamily_AF_WANPIPE; return 0;}
+#endif /* ndef AF_WANPIPE */
+#ifdef AF_X25
+       if (x == AF_X25)
+               {*r = Mono_Posix_UnixAddressFamily_AF_X25; return 0;}
+#endif /* ndef AF_X25 */
+#ifdef Unknown
+       if (x == Unknown)
+               {*r = Mono_Posix_UnixAddressFamily_Unknown; return 0;}
+#endif /* ndef Unknown */
+       errno = EINVAL; return -1;
+}
+
+int Mono_Posix_FromUnixSocketControlMessage (int x, int *r)
+{
+       *r = 0;
+       if (x == Mono_Posix_UnixSocketControlMessage_SCM_CREDENTIALS)
+#ifdef SCM_CREDENTIALS
+               {*r = SCM_CREDENTIALS; return 0;}
+#else /* def SCM_CREDENTIALS */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SCM_CREDENTIALS */
+       if (x == Mono_Posix_UnixSocketControlMessage_SCM_RIGHTS)
+#ifdef SCM_RIGHTS
+               {*r = SCM_RIGHTS; return 0;}
+#else /* def SCM_RIGHTS */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SCM_RIGHTS */
+       if (x == 0)
+               return 0;
+       errno = EINVAL; return -1;
+}
+
+int Mono_Posix_ToUnixSocketControlMessage (int x, int *r)
+{
+       *r = 0;
+       if (x == 0)
+               return 0;
+#ifdef SCM_CREDENTIALS
+       if (x == SCM_CREDENTIALS)
+               {*r = Mono_Posix_UnixSocketControlMessage_SCM_CREDENTIALS; return 0;}
+#endif /* ndef SCM_CREDENTIALS */
+#ifdef SCM_RIGHTS
+       if (x == SCM_RIGHTS)
+               {*r = Mono_Posix_UnixSocketControlMessage_SCM_RIGHTS; return 0;}
+#endif /* ndef SCM_RIGHTS */
+       errno = EINVAL; return -1;
+}
+
+int Mono_Posix_FromUnixSocketFlags (int x, int *r)
+{
+       *r = 0;
+       if ((x & Mono_Posix_UnixSocketFlags_SOCK_CLOEXEC) == Mono_Posix_UnixSocketFlags_SOCK_CLOEXEC)
+#ifdef SOCK_CLOEXEC
+               *r |= SOCK_CLOEXEC;
+#else /* def SOCK_CLOEXEC */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SOCK_CLOEXEC */
+       if ((x & Mono_Posix_UnixSocketFlags_SOCK_NONBLOCK) == Mono_Posix_UnixSocketFlags_SOCK_NONBLOCK)
+#ifdef SOCK_NONBLOCK
+               *r |= SOCK_NONBLOCK;
+#else /* def SOCK_NONBLOCK */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SOCK_NONBLOCK */
+       if (x == 0)
+               return 0;
+       return 0;
+}
+
+int Mono_Posix_ToUnixSocketFlags (int x, int *r)
+{
+       *r = 0;
+       if (x == 0)
+               return 0;
+#ifdef SOCK_CLOEXEC
+       if ((x & SOCK_CLOEXEC) == SOCK_CLOEXEC)
+               *r |= Mono_Posix_UnixSocketFlags_SOCK_CLOEXEC;
+#endif /* ndef SOCK_CLOEXEC */
+#ifdef SOCK_NONBLOCK
+       if ((x & SOCK_NONBLOCK) == SOCK_NONBLOCK)
+               *r |= Mono_Posix_UnixSocketFlags_SOCK_NONBLOCK;
+#endif /* ndef SOCK_NONBLOCK */
+       return 0;
+}
+
+int Mono_Posix_FromUnixSocketOptionName (int x, int *r)
+{
+       *r = 0;
+       if (x == Mono_Posix_UnixSocketOptionName_SO_ACCEPTCONN)
+#ifdef SO_ACCEPTCONN
+               {*r = SO_ACCEPTCONN; return 0;}
+#else /* def SO_ACCEPTCONN */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_ACCEPTCONN */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_ATTACH_FILTER)
+#ifdef SO_ATTACH_FILTER
+               {*r = SO_ATTACH_FILTER; return 0;}
+#else /* def SO_ATTACH_FILTER */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_ATTACH_FILTER */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_BINDTODEVICE)
+#ifdef SO_BINDTODEVICE
+               {*r = SO_BINDTODEVICE; return 0;}
+#else /* def SO_BINDTODEVICE */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_BINDTODEVICE */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_BROADCAST)
+#ifdef SO_BROADCAST
+               {*r = SO_BROADCAST; return 0;}
+#else /* def SO_BROADCAST */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_BROADCAST */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_BSDCOMPAT)
+#ifdef SO_BSDCOMPAT
+               {*r = SO_BSDCOMPAT; return 0;}
+#else /* def SO_BSDCOMPAT */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_BSDCOMPAT */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_BUSY_POLL)
+#ifdef SO_BUSY_POLL
+               {*r = SO_BUSY_POLL; return 0;}
+#else /* def SO_BUSY_POLL */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_BUSY_POLL */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_DEBUG)
+#ifdef SO_DEBUG
+               {*r = SO_DEBUG; return 0;}
+#else /* def SO_DEBUG */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_DEBUG */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_DETACH_FILTER)
+#ifdef SO_DETACH_FILTER
+               {*r = SO_DETACH_FILTER; return 0;}
+#else /* def SO_DETACH_FILTER */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_DETACH_FILTER */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_DOMAIN)
+#ifdef SO_DOMAIN
+               {*r = SO_DOMAIN; return 0;}
+#else /* def SO_DOMAIN */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_DOMAIN */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_DONTROUTE)
+#ifdef SO_DONTROUTE
+               {*r = SO_DONTROUTE; return 0;}
+#else /* def SO_DONTROUTE */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_DONTROUTE */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_ERROR)
+#ifdef SO_ERROR
+               {*r = SO_ERROR; return 0;}
+#else /* def SO_ERROR */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_ERROR */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_KEEPALIVE)
+#ifdef SO_KEEPALIVE
+               {*r = SO_KEEPALIVE; return 0;}
+#else /* def SO_KEEPALIVE */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_KEEPALIVE */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_LINGER)
+#ifdef SO_LINGER
+               {*r = SO_LINGER; return 0;}
+#else /* def SO_LINGER */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_LINGER */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_LOCK_FILTER)
+#ifdef SO_LOCK_FILTER
+               {*r = SO_LOCK_FILTER; return 0;}
+#else /* def SO_LOCK_FILTER */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_LOCK_FILTER */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_MARK)
+#ifdef SO_MARK
+               {*r = SO_MARK; return 0;}
+#else /* def SO_MARK */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_MARK */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_MAX_PACING_RATE)
+#ifdef SO_MAX_PACING_RATE
+               {*r = SO_MAX_PACING_RATE; return 0;}
+#else /* def SO_MAX_PACING_RATE */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_MAX_PACING_RATE */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_NOFCS)
+#ifdef SO_NOFCS
+               {*r = SO_NOFCS; return 0;}
+#else /* def SO_NOFCS */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_NOFCS */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_NO_CHECK)
+#ifdef SO_NO_CHECK
+               {*r = SO_NO_CHECK; return 0;}
+#else /* def SO_NO_CHECK */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_NO_CHECK */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_OOBINLINE)
+#ifdef SO_OOBINLINE
+               {*r = SO_OOBINLINE; return 0;}
+#else /* def SO_OOBINLINE */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_OOBINLINE */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_PASSCRED)
+#ifdef SO_PASSCRED
+               {*r = SO_PASSCRED; return 0;}
+#else /* def SO_PASSCRED */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_PASSCRED */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_PASSSEC)
+#ifdef SO_PASSSEC
+               {*r = SO_PASSSEC; return 0;}
+#else /* def SO_PASSSEC */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_PASSSEC */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_PEEK_OFF)
+#ifdef SO_PEEK_OFF
+               {*r = SO_PEEK_OFF; return 0;}
+#else /* def SO_PEEK_OFF */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_PEEK_OFF */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_PEERCRED)
+#ifdef SO_PEERCRED
+               {*r = SO_PEERCRED; return 0;}
+#else /* def SO_PEERCRED */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_PEERCRED */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_PEERNAME)
+#ifdef SO_PEERNAME
+               {*r = SO_PEERNAME; return 0;}
+#else /* def SO_PEERNAME */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_PEERNAME */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_PEERSEC)
+#ifdef SO_PEERSEC
+               {*r = SO_PEERSEC; return 0;}
+#else /* def SO_PEERSEC */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_PEERSEC */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_PRIORITY)
+#ifdef SO_PRIORITY
+               {*r = SO_PRIORITY; return 0;}
+#else /* def SO_PRIORITY */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_PRIORITY */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_PROTOCOL)
+#ifdef SO_PROTOCOL
+               {*r = SO_PROTOCOL; return 0;}
+#else /* def SO_PROTOCOL */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_PROTOCOL */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_RCVBUF)
+#ifdef SO_RCVBUF
+               {*r = SO_RCVBUF; return 0;}
+#else /* def SO_RCVBUF */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_RCVBUF */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_RCVBUFFORCE)
+#ifdef SO_RCVBUFFORCE
+               {*r = SO_RCVBUFFORCE; return 0;}
+#else /* def SO_RCVBUFFORCE */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_RCVBUFFORCE */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_RCVLOWAT)
+#ifdef SO_RCVLOWAT
+               {*r = SO_RCVLOWAT; return 0;}
+#else /* def SO_RCVLOWAT */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_RCVLOWAT */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_RCVTIMEO)
+#ifdef SO_RCVTIMEO
+               {*r = SO_RCVTIMEO; return 0;}
+#else /* def SO_RCVTIMEO */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_RCVTIMEO */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_REUSEADDR)
+#ifdef SO_REUSEADDR
+               {*r = SO_REUSEADDR; return 0;}
+#else /* def SO_REUSEADDR */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_REUSEADDR */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_REUSEPORT)
+#ifdef SO_REUSEPORT
+               {*r = SO_REUSEPORT; return 0;}
+#else /* def SO_REUSEPORT */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_REUSEPORT */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_RXQ_OVFL)
+#ifdef SO_RXQ_OVFL
+               {*r = SO_RXQ_OVFL; return 0;}
+#else /* def SO_RXQ_OVFL */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_RXQ_OVFL */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_SECURITY_AUTHENTICATION)
+#ifdef SO_SECURITY_AUTHENTICATION
+               {*r = SO_SECURITY_AUTHENTICATION; return 0;}
+#else /* def SO_SECURITY_AUTHENTICATION */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_SECURITY_AUTHENTICATION */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_SECURITY_ENCRYPTION_NETWORK)
+#ifdef SO_SECURITY_ENCRYPTION_NETWORK
+               {*r = SO_SECURITY_ENCRYPTION_NETWORK; return 0;}
+#else /* def SO_SECURITY_ENCRYPTION_NETWORK */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_SECURITY_ENCRYPTION_NETWORK */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_SECURITY_ENCRYPTION_TRANSPORT)
+#ifdef SO_SECURITY_ENCRYPTION_TRANSPORT
+               {*r = SO_SECURITY_ENCRYPTION_TRANSPORT; return 0;}
+#else /* def SO_SECURITY_ENCRYPTION_TRANSPORT */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_SECURITY_ENCRYPTION_TRANSPORT */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_SELECT_ERR_QUEUE)
+#ifdef SO_SELECT_ERR_QUEUE
+               {*r = SO_SELECT_ERR_QUEUE; return 0;}
+#else /* def SO_SELECT_ERR_QUEUE */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_SELECT_ERR_QUEUE */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_SNDBUF)
+#ifdef SO_SNDBUF
+               {*r = SO_SNDBUF; return 0;}
+#else /* def SO_SNDBUF */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_SNDBUF */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_SNDBUFFORCE)
+#ifdef SO_SNDBUFFORCE
+               {*r = SO_SNDBUFFORCE; return 0;}
+#else /* def SO_SNDBUFFORCE */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_SNDBUFFORCE */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_SNDLOWAT)
+#ifdef SO_SNDLOWAT
+               {*r = SO_SNDLOWAT; return 0;}
+#else /* def SO_SNDLOWAT */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_SNDLOWAT */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_SNDTIMEO)
+#ifdef SO_SNDTIMEO
+               {*r = SO_SNDTIMEO; return 0;}
+#else /* def SO_SNDTIMEO */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_SNDTIMEO */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_TIMESTAMP)
+#ifdef SO_TIMESTAMP
+               {*r = SO_TIMESTAMP; return 0;}
+#else /* def SO_TIMESTAMP */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_TIMESTAMP */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_TIMESTAMPING)
+#ifdef SO_TIMESTAMPING
+               {*r = SO_TIMESTAMPING; return 0;}
+#else /* def SO_TIMESTAMPING */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_TIMESTAMPING */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_TIMESTAMPNS)
+#ifdef SO_TIMESTAMPNS
+               {*r = SO_TIMESTAMPNS; return 0;}
+#else /* def SO_TIMESTAMPNS */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_TIMESTAMPNS */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_TYPE)
+#ifdef SO_TYPE
+               {*r = SO_TYPE; return 0;}
+#else /* def SO_TYPE */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_TYPE */
+       if (x == Mono_Posix_UnixSocketOptionName_SO_WIFI_STATUS)
+#ifdef SO_WIFI_STATUS
+               {*r = SO_WIFI_STATUS; return 0;}
+#else /* def SO_WIFI_STATUS */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SO_WIFI_STATUS */
+       if (x == 0)
+               return 0;
+       errno = EINVAL; return -1;
+}
+
+int Mono_Posix_ToUnixSocketOptionName (int x, int *r)
+{
+       *r = 0;
+       if (x == 0)
+               return 0;
+#ifdef SO_ACCEPTCONN
+       if (x == SO_ACCEPTCONN)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_ACCEPTCONN; return 0;}
+#endif /* ndef SO_ACCEPTCONN */
+#ifdef SO_ATTACH_FILTER
+       if (x == SO_ATTACH_FILTER)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_ATTACH_FILTER; return 0;}
+#endif /* ndef SO_ATTACH_FILTER */
+#ifdef SO_BINDTODEVICE
+       if (x == SO_BINDTODEVICE)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_BINDTODEVICE; return 0;}
+#endif /* ndef SO_BINDTODEVICE */
+#ifdef SO_BROADCAST
+       if (x == SO_BROADCAST)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_BROADCAST; return 0;}
+#endif /* ndef SO_BROADCAST */
+#ifdef SO_BSDCOMPAT
+       if (x == SO_BSDCOMPAT)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_BSDCOMPAT; return 0;}
+#endif /* ndef SO_BSDCOMPAT */
+#ifdef SO_BUSY_POLL
+       if (x == SO_BUSY_POLL)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_BUSY_POLL; return 0;}
+#endif /* ndef SO_BUSY_POLL */
+#ifdef SO_DEBUG
+       if (x == SO_DEBUG)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_DEBUG; return 0;}
+#endif /* ndef SO_DEBUG */
+#ifdef SO_DETACH_FILTER
+       if (x == SO_DETACH_FILTER)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_DETACH_FILTER; return 0;}
+#endif /* ndef SO_DETACH_FILTER */
+#ifdef SO_DOMAIN
+       if (x == SO_DOMAIN)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_DOMAIN; return 0;}
+#endif /* ndef SO_DOMAIN */
+#ifdef SO_DONTROUTE
+       if (x == SO_DONTROUTE)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_DONTROUTE; return 0;}
+#endif /* ndef SO_DONTROUTE */
+#ifdef SO_ERROR
+       if (x == SO_ERROR)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_ERROR; return 0;}
+#endif /* ndef SO_ERROR */
+#ifdef SO_KEEPALIVE
+       if (x == SO_KEEPALIVE)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_KEEPALIVE; return 0;}
+#endif /* ndef SO_KEEPALIVE */
+#ifdef SO_LINGER
+       if (x == SO_LINGER)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_LINGER; return 0;}
+#endif /* ndef SO_LINGER */
+#ifdef SO_LOCK_FILTER
+       if (x == SO_LOCK_FILTER)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_LOCK_FILTER; return 0;}
+#endif /* ndef SO_LOCK_FILTER */
+#ifdef SO_MARK
+       if (x == SO_MARK)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_MARK; return 0;}
+#endif /* ndef SO_MARK */
+#ifdef SO_MAX_PACING_RATE
+       if (x == SO_MAX_PACING_RATE)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_MAX_PACING_RATE; return 0;}
+#endif /* ndef SO_MAX_PACING_RATE */
+#ifdef SO_NOFCS
+       if (x == SO_NOFCS)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_NOFCS; return 0;}
+#endif /* ndef SO_NOFCS */
+#ifdef SO_NO_CHECK
+       if (x == SO_NO_CHECK)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_NO_CHECK; return 0;}
+#endif /* ndef SO_NO_CHECK */
+#ifdef SO_OOBINLINE
+       if (x == SO_OOBINLINE)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_OOBINLINE; return 0;}
+#endif /* ndef SO_OOBINLINE */
+#ifdef SO_PASSCRED
+       if (x == SO_PASSCRED)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_PASSCRED; return 0;}
+#endif /* ndef SO_PASSCRED */
+#ifdef SO_PASSSEC
+       if (x == SO_PASSSEC)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_PASSSEC; return 0;}
+#endif /* ndef SO_PASSSEC */
+#ifdef SO_PEEK_OFF
+       if (x == SO_PEEK_OFF)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_PEEK_OFF; return 0;}
+#endif /* ndef SO_PEEK_OFF */
+#ifdef SO_PEERCRED
+       if (x == SO_PEERCRED)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_PEERCRED; return 0;}
+#endif /* ndef SO_PEERCRED */
+#ifdef SO_PEERNAME
+       if (x == SO_PEERNAME)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_PEERNAME; return 0;}
+#endif /* ndef SO_PEERNAME */
+#ifdef SO_PEERSEC
+       if (x == SO_PEERSEC)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_PEERSEC; return 0;}
+#endif /* ndef SO_PEERSEC */
+#ifdef SO_PRIORITY
+       if (x == SO_PRIORITY)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_PRIORITY; return 0;}
+#endif /* ndef SO_PRIORITY */
+#ifdef SO_PROTOCOL
+       if (x == SO_PROTOCOL)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_PROTOCOL; return 0;}
+#endif /* ndef SO_PROTOCOL */
+#ifdef SO_RCVBUF
+       if (x == SO_RCVBUF)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_RCVBUF; return 0;}
+#endif /* ndef SO_RCVBUF */
+#ifdef SO_RCVBUFFORCE
+       if (x == SO_RCVBUFFORCE)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_RCVBUFFORCE; return 0;}
+#endif /* ndef SO_RCVBUFFORCE */
+#ifdef SO_RCVLOWAT
+       if (x == SO_RCVLOWAT)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_RCVLOWAT; return 0;}
+#endif /* ndef SO_RCVLOWAT */
+#ifdef SO_RCVTIMEO
+       if (x == SO_RCVTIMEO)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_RCVTIMEO; return 0;}
+#endif /* ndef SO_RCVTIMEO */
+#ifdef SO_REUSEADDR
+       if (x == SO_REUSEADDR)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_REUSEADDR; return 0;}
+#endif /* ndef SO_REUSEADDR */
+#ifdef SO_REUSEPORT
+       if (x == SO_REUSEPORT)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_REUSEPORT; return 0;}
+#endif /* ndef SO_REUSEPORT */
+#ifdef SO_RXQ_OVFL
+       if (x == SO_RXQ_OVFL)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_RXQ_OVFL; return 0;}
+#endif /* ndef SO_RXQ_OVFL */
+#ifdef SO_SECURITY_AUTHENTICATION
+       if (x == SO_SECURITY_AUTHENTICATION)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_SECURITY_AUTHENTICATION; return 0;}
+#endif /* ndef SO_SECURITY_AUTHENTICATION */
+#ifdef SO_SECURITY_ENCRYPTION_NETWORK
+       if (x == SO_SECURITY_ENCRYPTION_NETWORK)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_SECURITY_ENCRYPTION_NETWORK; return 0;}
+#endif /* ndef SO_SECURITY_ENCRYPTION_NETWORK */
+#ifdef SO_SECURITY_ENCRYPTION_TRANSPORT
+       if (x == SO_SECURITY_ENCRYPTION_TRANSPORT)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_SECURITY_ENCRYPTION_TRANSPORT; return 0;}
+#endif /* ndef SO_SECURITY_ENCRYPTION_TRANSPORT */
+#ifdef SO_SELECT_ERR_QUEUE
+       if (x == SO_SELECT_ERR_QUEUE)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_SELECT_ERR_QUEUE; return 0;}
+#endif /* ndef SO_SELECT_ERR_QUEUE */
+#ifdef SO_SNDBUF
+       if (x == SO_SNDBUF)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_SNDBUF; return 0;}
+#endif /* ndef SO_SNDBUF */
+#ifdef SO_SNDBUFFORCE
+       if (x == SO_SNDBUFFORCE)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_SNDBUFFORCE; return 0;}
+#endif /* ndef SO_SNDBUFFORCE */
+#ifdef SO_SNDLOWAT
+       if (x == SO_SNDLOWAT)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_SNDLOWAT; return 0;}
+#endif /* ndef SO_SNDLOWAT */
+#ifdef SO_SNDTIMEO
+       if (x == SO_SNDTIMEO)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_SNDTIMEO; return 0;}
+#endif /* ndef SO_SNDTIMEO */
+#ifdef SO_TIMESTAMP
+       if (x == SO_TIMESTAMP)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_TIMESTAMP; return 0;}
+#endif /* ndef SO_TIMESTAMP */
+#ifdef SO_TIMESTAMPING
+       if (x == SO_TIMESTAMPING)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_TIMESTAMPING; return 0;}
+#endif /* ndef SO_TIMESTAMPING */
+#ifdef SO_TIMESTAMPNS
+       if (x == SO_TIMESTAMPNS)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_TIMESTAMPNS; return 0;}
+#endif /* ndef SO_TIMESTAMPNS */
+#ifdef SO_TYPE
+       if (x == SO_TYPE)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_TYPE; return 0;}
+#endif /* ndef SO_TYPE */
+#ifdef SO_WIFI_STATUS
+       if (x == SO_WIFI_STATUS)
+               {*r = Mono_Posix_UnixSocketOptionName_SO_WIFI_STATUS; return 0;}
+#endif /* ndef SO_WIFI_STATUS */
+       errno = EINVAL; return -1;
+}
+
+int Mono_Posix_FromUnixSocketProtocol (int x, int *r)
+{
+       *r = 0;
+       if (x == Mono_Posix_UnixSocketProtocol_IPPROTO_AH)
+#ifdef IPPROTO_AH
+               {*r = IPPROTO_AH; return 0;}
+#else /* def IPPROTO_AH */
+               {errno = EINVAL; return -1;}
+#endif /* ndef IPPROTO_AH */
+       if (x == Mono_Posix_UnixSocketProtocol_IPPROTO_BEETPH)
+#ifdef IPPROTO_BEETPH
+               {*r = IPPROTO_BEETPH; return 0;}
+#else /* def IPPROTO_BEETPH */
+               {errno = EINVAL; return -1;}
+#endif /* ndef IPPROTO_BEETPH */
+       if (x == Mono_Posix_UnixSocketProtocol_IPPROTO_COMP)
+#ifdef IPPROTO_COMP
+               {*r = IPPROTO_COMP; return 0;}
+#else /* def IPPROTO_COMP */
+               {errno = EINVAL; return -1;}
+#endif /* ndef IPPROTO_COMP */
+       if (x == Mono_Posix_UnixSocketProtocol_IPPROTO_DCCP)
+#ifdef IPPROTO_DCCP
+               {*r = IPPROTO_DCCP; return 0;}
+#else /* def IPPROTO_DCCP */
+               {errno = EINVAL; return -1;}
+#endif /* ndef IPPROTO_DCCP */
+       if (x == Mono_Posix_UnixSocketProtocol_IPPROTO_EGP)
+#ifdef IPPROTO_EGP
+               {*r = IPPROTO_EGP; return 0;}
+#else /* def IPPROTO_EGP */
+               {errno = EINVAL; return -1;}
+#endif /* ndef IPPROTO_EGP */
+       if (x == Mono_Posix_UnixSocketProtocol_IPPROTO_ENCAP)
+#ifdef IPPROTO_ENCAP
+               {*r = IPPROTO_ENCAP; return 0;}
+#else /* def IPPROTO_ENCAP */
+               {errno = EINVAL; return -1;}
+#endif /* ndef IPPROTO_ENCAP */
+       if (x == Mono_Posix_UnixSocketProtocol_IPPROTO_ESP)
+#ifdef IPPROTO_ESP
+               {*r = IPPROTO_ESP; return 0;}
+#else /* def IPPROTO_ESP */
+               {errno = EINVAL; return -1;}
+#endif /* ndef IPPROTO_ESP */
+       if (x == Mono_Posix_UnixSocketProtocol_IPPROTO_GRE)
+#ifdef IPPROTO_GRE
+               {*r = IPPROTO_GRE; return 0;}
+#else /* def IPPROTO_GRE */
+               {errno = EINVAL; return -1;}
+#endif /* ndef IPPROTO_GRE */
+       if (x == Mono_Posix_UnixSocketProtocol_IPPROTO_ICMP)
+#ifdef IPPROTO_ICMP
+               {*r = IPPROTO_ICMP; return 0;}
+#else /* def IPPROTO_ICMP */
+               {errno = EINVAL; return -1;}
+#endif /* ndef IPPROTO_ICMP */
+       if (x == Mono_Posix_UnixSocketProtocol_IPPROTO_IDP)
+#ifdef IPPROTO_IDP
+               {*r = IPPROTO_IDP; return 0;}
+#else /* def IPPROTO_IDP */
+               {errno = EINVAL; return -1;}
+#endif /* ndef IPPROTO_IDP */
+       if (x == Mono_Posix_UnixSocketProtocol_IPPROTO_IGMP)
+#ifdef IPPROTO_IGMP
+               {*r = IPPROTO_IGMP; return 0;}
+#else /* def IPPROTO_IGMP */
+               {errno = EINVAL; return -1;}
+#endif /* ndef IPPROTO_IGMP */
+       if (x == Mono_Posix_UnixSocketProtocol_IPPROTO_IP)
+#ifdef IPPROTO_IP
+               {*r = IPPROTO_IP; return 0;}
+#else /* def IPPROTO_IP */
+               {errno = EINVAL; return -1;}
+#endif /* ndef IPPROTO_IP */
+       if (x == Mono_Posix_UnixSocketProtocol_IPPROTO_IPIP)
+#ifdef IPPROTO_IPIP
+               {*r = IPPROTO_IPIP; return 0;}
+#else /* def IPPROTO_IPIP */
+               {errno = EINVAL; return -1;}
+#endif /* ndef IPPROTO_IPIP */
+       if (x == Mono_Posix_UnixSocketProtocol_IPPROTO_IPV6)
+#ifdef IPPROTO_IPV6
+               {*r = IPPROTO_IPV6; return 0;}
+#else /* def IPPROTO_IPV6 */
+               {errno = EINVAL; return -1;}
+#endif /* ndef IPPROTO_IPV6 */
+       if (x == Mono_Posix_UnixSocketProtocol_IPPROTO_MTP)
+#ifdef IPPROTO_MTP
+               {*r = IPPROTO_MTP; return 0;}
+#else /* def IPPROTO_MTP */
+               {errno = EINVAL; return -1;}
+#endif /* ndef IPPROTO_MTP */
+       if (x == Mono_Posix_UnixSocketProtocol_IPPROTO_PIM)
+#ifdef IPPROTO_PIM
+               {*r = IPPROTO_PIM; return 0;}
+#else /* def IPPROTO_PIM */
+               {errno = EINVAL; return -1;}
+#endif /* ndef IPPROTO_PIM */
+       if (x == Mono_Posix_UnixSocketProtocol_IPPROTO_PUP)
+#ifdef IPPROTO_PUP
+               {*r = IPPROTO_PUP; return 0;}
+#else /* def IPPROTO_PUP */
+               {errno = EINVAL; return -1;}
+#endif /* ndef IPPROTO_PUP */
+       if (x == Mono_Posix_UnixSocketProtocol_IPPROTO_RAW)
+#ifdef IPPROTO_RAW
+               {*r = IPPROTO_RAW; return 0;}
+#else /* def IPPROTO_RAW */
+               {errno = EINVAL; return -1;}
+#endif /* ndef IPPROTO_RAW */
+       if (x == Mono_Posix_UnixSocketProtocol_IPPROTO_RSVP)
+#ifdef IPPROTO_RSVP
+               {*r = IPPROTO_RSVP; return 0;}
+#else /* def IPPROTO_RSVP */
+               {errno = EINVAL; return -1;}
+#endif /* ndef IPPROTO_RSVP */
+       if (x == Mono_Posix_UnixSocketProtocol_IPPROTO_SCTP)
+#ifdef IPPROTO_SCTP
+               {*r = IPPROTO_SCTP; return 0;}
+#else /* def IPPROTO_SCTP */
+               {errno = EINVAL; return -1;}
+#endif /* ndef IPPROTO_SCTP */
+       if (x == Mono_Posix_UnixSocketProtocol_IPPROTO_TCP)
+#ifdef IPPROTO_TCP
+               {*r = IPPROTO_TCP; return 0;}
+#else /* def IPPROTO_TCP */
+               {errno = EINVAL; return -1;}
+#endif /* ndef IPPROTO_TCP */
+       if (x == Mono_Posix_UnixSocketProtocol_IPPROTO_TP)
+#ifdef IPPROTO_TP
+               {*r = IPPROTO_TP; return 0;}
+#else /* def IPPROTO_TP */
+               {errno = EINVAL; return -1;}
+#endif /* ndef IPPROTO_TP */
+       if (x == Mono_Posix_UnixSocketProtocol_IPPROTO_UDP)
+#ifdef IPPROTO_UDP
+               {*r = IPPROTO_UDP; return 0;}
+#else /* def IPPROTO_UDP */
+               {errno = EINVAL; return -1;}
+#endif /* ndef IPPROTO_UDP */
+       if (x == Mono_Posix_UnixSocketProtocol_IPPROTO_UDPLITE)
+#ifdef IPPROTO_UDPLITE
+               {*r = IPPROTO_UDPLITE; return 0;}
+#else /* def IPPROTO_UDPLITE */
+               {errno = EINVAL; return -1;}
+#endif /* ndef IPPROTO_UDPLITE */
+       if (x == Mono_Posix_UnixSocketProtocol_SOL_SOCKET)
+#ifdef SOL_SOCKET
+               {*r = SOL_SOCKET; return 0;}
+#else /* def SOL_SOCKET */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SOL_SOCKET */
+       if (x == 0)
+               return 0;
+       errno = EINVAL; return -1;
+}
+
+int Mono_Posix_ToUnixSocketProtocol (int x, int *r)
+{
+       *r = 0;
+       if (x == 0)
+               return 0;
+#ifdef IPPROTO_AH
+       if (x == IPPROTO_AH)
+               {*r = Mono_Posix_UnixSocketProtocol_IPPROTO_AH; return 0;}
+#endif /* ndef IPPROTO_AH */
+#ifdef IPPROTO_BEETPH
+       if (x == IPPROTO_BEETPH)
+               {*r = Mono_Posix_UnixSocketProtocol_IPPROTO_BEETPH; return 0;}
+#endif /* ndef IPPROTO_BEETPH */
+#ifdef IPPROTO_COMP
+       if (x == IPPROTO_COMP)
+               {*r = Mono_Posix_UnixSocketProtocol_IPPROTO_COMP; return 0;}
+#endif /* ndef IPPROTO_COMP */
+#ifdef IPPROTO_DCCP
+       if (x == IPPROTO_DCCP)
+               {*r = Mono_Posix_UnixSocketProtocol_IPPROTO_DCCP; return 0;}
+#endif /* ndef IPPROTO_DCCP */
+#ifdef IPPROTO_EGP
+       if (x == IPPROTO_EGP)
+               {*r = Mono_Posix_UnixSocketProtocol_IPPROTO_EGP; return 0;}
+#endif /* ndef IPPROTO_EGP */
+#ifdef IPPROTO_ENCAP
+       if (x == IPPROTO_ENCAP)
+               {*r = Mono_Posix_UnixSocketProtocol_IPPROTO_ENCAP; return 0;}
+#endif /* ndef IPPROTO_ENCAP */
+#ifdef IPPROTO_ESP
+       if (x == IPPROTO_ESP)
+               {*r = Mono_Posix_UnixSocketProtocol_IPPROTO_ESP; return 0;}
+#endif /* ndef IPPROTO_ESP */
+#ifdef IPPROTO_GRE
+       if (x == IPPROTO_GRE)
+               {*r = Mono_Posix_UnixSocketProtocol_IPPROTO_GRE; return 0;}
+#endif /* ndef IPPROTO_GRE */
+#ifdef IPPROTO_ICMP
+       if (x == IPPROTO_ICMP)
+               {*r = Mono_Posix_UnixSocketProtocol_IPPROTO_ICMP; return 0;}
+#endif /* ndef IPPROTO_ICMP */
+#ifdef IPPROTO_IDP
+       if (x == IPPROTO_IDP)
+               {*r = Mono_Posix_UnixSocketProtocol_IPPROTO_IDP; return 0;}
+#endif /* ndef IPPROTO_IDP */
+#ifdef IPPROTO_IGMP
+       if (x == IPPROTO_IGMP)
+               {*r = Mono_Posix_UnixSocketProtocol_IPPROTO_IGMP; return 0;}
+#endif /* ndef IPPROTO_IGMP */
+#ifdef IPPROTO_IP
+       if (x == IPPROTO_IP)
+               {*r = Mono_Posix_UnixSocketProtocol_IPPROTO_IP; return 0;}
+#endif /* ndef IPPROTO_IP */
+#ifdef IPPROTO_IPIP
+       if (x == IPPROTO_IPIP)
+               {*r = Mono_Posix_UnixSocketProtocol_IPPROTO_IPIP; return 0;}
+#endif /* ndef IPPROTO_IPIP */
+#ifdef IPPROTO_IPV6
+       if (x == IPPROTO_IPV6)
+               {*r = Mono_Posix_UnixSocketProtocol_IPPROTO_IPV6; return 0;}
+#endif /* ndef IPPROTO_IPV6 */
+#ifdef IPPROTO_MTP
+       if (x == IPPROTO_MTP)
+               {*r = Mono_Posix_UnixSocketProtocol_IPPROTO_MTP; return 0;}
+#endif /* ndef IPPROTO_MTP */
+#ifdef IPPROTO_PIM
+       if (x == IPPROTO_PIM)
+               {*r = Mono_Posix_UnixSocketProtocol_IPPROTO_PIM; return 0;}
+#endif /* ndef IPPROTO_PIM */
+#ifdef IPPROTO_PUP
+       if (x == IPPROTO_PUP)
+               {*r = Mono_Posix_UnixSocketProtocol_IPPROTO_PUP; return 0;}
+#endif /* ndef IPPROTO_PUP */
+#ifdef IPPROTO_RAW
+       if (x == IPPROTO_RAW)
+               {*r = Mono_Posix_UnixSocketProtocol_IPPROTO_RAW; return 0;}
+#endif /* ndef IPPROTO_RAW */
+#ifdef IPPROTO_RSVP
+       if (x == IPPROTO_RSVP)
+               {*r = Mono_Posix_UnixSocketProtocol_IPPROTO_RSVP; return 0;}
+#endif /* ndef IPPROTO_RSVP */
+#ifdef IPPROTO_SCTP
+       if (x == IPPROTO_SCTP)
+               {*r = Mono_Posix_UnixSocketProtocol_IPPROTO_SCTP; return 0;}
+#endif /* ndef IPPROTO_SCTP */
+#ifdef IPPROTO_TCP
+       if (x == IPPROTO_TCP)
+               {*r = Mono_Posix_UnixSocketProtocol_IPPROTO_TCP; return 0;}
+#endif /* ndef IPPROTO_TCP */
+#ifdef IPPROTO_TP
+       if (x == IPPROTO_TP)
+               {*r = Mono_Posix_UnixSocketProtocol_IPPROTO_TP; return 0;}
+#endif /* ndef IPPROTO_TP */
+#ifdef IPPROTO_UDP
+       if (x == IPPROTO_UDP)
+               {*r = Mono_Posix_UnixSocketProtocol_IPPROTO_UDP; return 0;}
+#endif /* ndef IPPROTO_UDP */
+#ifdef IPPROTO_UDPLITE
+       if (x == IPPROTO_UDPLITE)
+               {*r = Mono_Posix_UnixSocketProtocol_IPPROTO_UDPLITE; return 0;}
+#endif /* ndef IPPROTO_UDPLITE */
+#ifdef SOL_SOCKET
+       if (x == SOL_SOCKET)
+               {*r = Mono_Posix_UnixSocketProtocol_SOL_SOCKET; return 0;}
+#endif /* ndef SOL_SOCKET */
+       errno = EINVAL; return -1;
+}
+
+int Mono_Posix_FromUnixSocketType (int x, int *r)
+{
+       *r = 0;
+       if (x == Mono_Posix_UnixSocketType_SOCK_DCCP)
+#ifdef SOCK_DCCP
+               {*r = SOCK_DCCP; return 0;}
+#else /* def SOCK_DCCP */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SOCK_DCCP */
+       if (x == Mono_Posix_UnixSocketType_SOCK_DGRAM)
+#ifdef SOCK_DGRAM
+               {*r = SOCK_DGRAM; return 0;}
+#else /* def SOCK_DGRAM */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SOCK_DGRAM */
+       if (x == Mono_Posix_UnixSocketType_SOCK_PACKET)
+#ifdef SOCK_PACKET
+               {*r = SOCK_PACKET; return 0;}
+#else /* def SOCK_PACKET */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SOCK_PACKET */
+       if (x == Mono_Posix_UnixSocketType_SOCK_RAW)
+#ifdef SOCK_RAW
+               {*r = SOCK_RAW; return 0;}
+#else /* def SOCK_RAW */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SOCK_RAW */
+       if (x == Mono_Posix_UnixSocketType_SOCK_RDM)
+#ifdef SOCK_RDM
+               {*r = SOCK_RDM; return 0;}
+#else /* def SOCK_RDM */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SOCK_RDM */
+       if (x == Mono_Posix_UnixSocketType_SOCK_SEQPACKET)
+#ifdef SOCK_SEQPACKET
+               {*r = SOCK_SEQPACKET; return 0;}
+#else /* def SOCK_SEQPACKET */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SOCK_SEQPACKET */
+       if (x == Mono_Posix_UnixSocketType_SOCK_STREAM)
+#ifdef SOCK_STREAM
+               {*r = SOCK_STREAM; return 0;}
+#else /* def SOCK_STREAM */
+               {errno = EINVAL; return -1;}
+#endif /* ndef SOCK_STREAM */
+       if (x == 0)
+               return 0;
+       errno = EINVAL; return -1;
+}
+
+int Mono_Posix_ToUnixSocketType (int x, int *r)
+{
+       *r = 0;
+       if (x == 0)
+               return 0;
+#ifdef SOCK_DCCP
+       if (x == SOCK_DCCP)
+               {*r = Mono_Posix_UnixSocketType_SOCK_DCCP; return 0;}
+#endif /* ndef SOCK_DCCP */
+#ifdef SOCK_DGRAM
+       if (x == SOCK_DGRAM)
+               {*r = Mono_Posix_UnixSocketType_SOCK_DGRAM; return 0;}
+#endif /* ndef SOCK_DGRAM */
+#ifdef SOCK_PACKET
+       if (x == SOCK_PACKET)
+               {*r = Mono_Posix_UnixSocketType_SOCK_PACKET; return 0;}
+#endif /* ndef SOCK_PACKET */
+#ifdef SOCK_RAW
+       if (x == SOCK_RAW)
+               {*r = Mono_Posix_UnixSocketType_SOCK_RAW; return 0;}
+#endif /* ndef SOCK_RAW */
+#ifdef SOCK_RDM
+       if (x == SOCK_RDM)
+               {*r = Mono_Posix_UnixSocketType_SOCK_RDM; return 0;}
+#endif /* ndef SOCK_RDM */
+#ifdef SOCK_SEQPACKET
+       if (x == SOCK_SEQPACKET)
+               {*r = Mono_Posix_UnixSocketType_SOCK_SEQPACKET; return 0;}
+#endif /* ndef SOCK_SEQPACKET */
+#ifdef SOCK_STREAM
+       if (x == SOCK_STREAM)
+               {*r = Mono_Posix_UnixSocketType_SOCK_STREAM; return 0;}
+#endif /* ndef SOCK_STREAM */
+       errno = EINVAL; return -1;
+}
+
 #ifdef HAVE_STRUCT_UTIMBUF
 int
 Mono_Posix_FromUtimbuf (struct Mono_Posix_Utimbuf *from, struct utimbuf *to)
@@ -7488,4 +9324,3 @@ int Mono_Posix_ToXattrFlags (int x, int *r)
 #endif /* ndef XATTR_REPLACE */
        return 0;
 }
-