Add socket-related functions and data structures to Mono.Posix
authorSteffen Kieß <s-kiess@web.de>
Mon, 24 Aug 2015 17:42:54 +0000 (19:42 +0200)
committerSteffen Kieß <s-kiess@web.de>
Mon, 24 Aug 2015 17:42:54 +0000 (19:42 +0200)
This commit adds those socket-related functions which do not require the
sockaddr_* structures or the msghdr structure.

configure.ac
mcs/class/Mono.Posix/Mono.Posix-tests-net_4_5.csproj
mcs/class/Mono.Posix/Mono.Posix_test.dll.sources
mcs/class/Mono.Posix/Mono.Unix.Native/NativeConvert.generated.cs
mcs/class/Mono.Posix/Mono.Unix.Native/Syscall.cs
mcs/class/Mono.Posix/Test/Mono.Unix.Native/SocketTest.cs [new file with mode: 0644]
support/Makefile.am
support/map.c
support/map.h
support/mph.h
support/sys-socket.c [new file with mode: 0644]

index 7191db1858c1080b7a2f7b281fa2d2c1f7b75dd4..2d28b82dfcee53b8f394d35dc7cbca529523c6e9 100644 (file)
@@ -2088,6 +2088,8 @@ if test x$host_win32 = xno; then
                 #include <fcntl.h>])
        AC_CHECK_TYPES([struct iovec], [AC_DEFINE(HAVE_STRUCT_IOVEC)], ,
                [#include <sys/uio.h>])
+       AC_CHECK_TYPES([struct linger], [AC_DEFINE(HAVE_STRUCT_LINGER)], ,
+               [#include <sys/socket.h>])
        AC_CHECK_TYPES([struct pollfd], [AC_DEFINE(HAVE_STRUCT_POLLFD)], ,
                [#include <sys/poll.h>])
        AC_CHECK_TYPES([struct stat], [AC_DEFINE(HAVE_STRUCT_STAT)], ,
index a7d9f70f9954a416e88e2cf320575532dc0a181a..a0c5cf12f5761423cc174f3ed89ba402a37b6265 100644 (file)
@@ -45,6 +45,7 @@
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />\r
   <ItemGroup>\r
     <Compile Include="Test\Mono.Unix.Native\RealTimeSignumTests.cs" />\r
+    <Compile Include="Test\Mono.Unix.Native\SocketTest.cs" />\r
     <Compile Include="Test\Mono.Unix.Native\StdlibTest.cs" />\r
     <Compile Include="Test\Mono.Unix\ReadlinkTest.cs" />\r
     <Compile Include="Test\Mono.Unix\StdioFileStreamTest.cs" />\r
index 270b0b6aee680cb64332b06638110b58a6eda18b..88e9eb1f1a0f0c5940f24b0b68bc3ac04ae26dfc 100644 (file)
@@ -7,4 +7,5 @@ Mono.Unix/UnixPathTest.cs
 Mono.Unix/UnixSignalTest.cs
 Mono.Unix/UnixUserTest.cs
 Mono.Unix.Native/RealTimeSignumTests.cs
+Mono.Unix.Native/SocketTest.cs
 Mono.Unix.Native/StdlibTest.cs
index d9097f8d7a3394610167957639000144950b97e6..2ac13c6677edd26437a6fc806df7cf3e12b6d027 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * This file was automatically generated by create-native-map from ../../class/lib/net_2_0/Mono.Posix.dll.
+ * This file was automatically generated by create-native-map from ./../../class/lib/net_4_x/Mono.Posix.dll.
  *
  * DO NOT MODIFY.
  */
@@ -342,6 +342,22 @@ namespace Mono.Unix.Native {
                        return ToIovec (source, out destination) == 0;
                }
 
+               [DllImport (LIB, EntryPoint="Mono_Posix_FromLinger")]
+               private static extern int FromLinger (ref Linger source, IntPtr destination);
+
+               public static bool TryCopy (ref Linger source, IntPtr destination)
+               {
+                       return FromLinger (ref source, destination) == 0;
+               }
+
+               [DllImport (LIB, EntryPoint="Mono_Posix_ToLinger")]
+               private static extern int ToLinger (IntPtr source, out Linger destination);
+
+               public static bool TryCopy (IntPtr source, out Linger destination)
+               {
+                       return ToLinger (source, out destination) == 0;
+               }
+
                [DllImport (LIB, EntryPoint="Mono_Posix_FromLockType")]
                private static extern int FromLockType (LockType value, out Int16 rval);
 
@@ -406,6 +422,38 @@ namespace Mono.Unix.Native {
                        return rval;
                }
 
+               [DllImport (LIB, EntryPoint="Mono_Posix_FromMessageFlags")]
+               private static extern int FromMessageFlags (MessageFlags value, out Int32 rval);
+
+               public static bool TryFromMessageFlags (MessageFlags value, out Int32 rval)
+               {
+                       return FromMessageFlags (value, out rval) == 0;
+               }
+
+               public static Int32 FromMessageFlags (MessageFlags value)
+               {
+                       Int32 rval;
+                       if (FromMessageFlags (value, out rval) == -1)
+                               ThrowArgumentException (value);
+                       return rval;
+               }
+
+               [DllImport (LIB, EntryPoint="Mono_Posix_ToMessageFlags")]
+               private static extern int ToMessageFlags (Int32 value, out MessageFlags rval);
+
+               public static bool TryToMessageFlags (Int32 value, out MessageFlags rval)
+               {
+                       return ToMessageFlags (value, out rval) == 0;
+               }
+
+               public static MessageFlags ToMessageFlags (Int32 value)
+               {
+                       MessageFlags rval;
+                       if (ToMessageFlags (value, out rval) == -1)
+                               ThrowArgumentException (value);
+                       return rval;
+               }
+
                [DllImport (LIB, EntryPoint="Mono_Posix_FromMlockallFlags")]
                private static extern int FromMlockallFlags (MlockallFlags value, out Int32 rval);
 
@@ -806,6 +854,38 @@ namespace Mono.Unix.Native {
                        return rval;
                }
 
+               [DllImport (LIB, EntryPoint="Mono_Posix_FromShutdownOption")]
+               private static extern int FromShutdownOption (ShutdownOption value, out Int32 rval);
+
+               public static bool TryFromShutdownOption (ShutdownOption value, out Int32 rval)
+               {
+                       return FromShutdownOption (value, out rval) == 0;
+               }
+
+               public static Int32 FromShutdownOption (ShutdownOption value)
+               {
+                       Int32 rval;
+                       if (FromShutdownOption (value, out rval) == -1)
+                               ThrowArgumentException (value);
+                       return rval;
+               }
+
+               [DllImport (LIB, EntryPoint="Mono_Posix_ToShutdownOption")]
+               private static extern int ToShutdownOption (Int32 value, out ShutdownOption rval);
+
+               public static bool TryToShutdownOption (Int32 value, out ShutdownOption rval)
+               {
+                       return ToShutdownOption (value, out rval) == 0;
+               }
+
+               public static ShutdownOption ToShutdownOption (Int32 value)
+               {
+                       ShutdownOption rval;
+                       if (ToShutdownOption (value, out rval) == -1)
+                               ThrowArgumentException (value);
+                       return rval;
+               }
+
                [DllImport (LIB, EntryPoint="Mono_Posix_FromSignum")]
                private static extern int FromSignum (Signum value, out Int32 rval);
 
@@ -1014,6 +1094,166 @@ namespace Mono.Unix.Native {
                        return ToTimezone (source, out destination) == 0;
                }
 
+               [DllImport (LIB, EntryPoint="Mono_Posix_FromUnixAddressFamily")]
+               private static extern int FromUnixAddressFamily (UnixAddressFamily value, out Int32 rval);
+
+               public static bool TryFromUnixAddressFamily (UnixAddressFamily value, out Int32 rval)
+               {
+                       return FromUnixAddressFamily (value, out rval) == 0;
+               }
+
+               public static Int32 FromUnixAddressFamily (UnixAddressFamily value)
+               {
+                       Int32 rval;
+                       if (FromUnixAddressFamily (value, out rval) == -1)
+                               ThrowArgumentException (value);
+                       return rval;
+               }
+
+               [DllImport (LIB, EntryPoint="Mono_Posix_ToUnixAddressFamily")]
+               private static extern int ToUnixAddressFamily (Int32 value, out UnixAddressFamily rval);
+
+               public static bool TryToUnixAddressFamily (Int32 value, out UnixAddressFamily rval)
+               {
+                       return ToUnixAddressFamily (value, out rval) == 0;
+               }
+
+               public static UnixAddressFamily ToUnixAddressFamily (Int32 value)
+               {
+                       UnixAddressFamily rval;
+                       if (ToUnixAddressFamily (value, out rval) == -1)
+                               ThrowArgumentException (value);
+                       return rval;
+               }
+
+               [DllImport (LIB, EntryPoint="Mono_Posix_FromUnixSocketFlags")]
+               private static extern int FromUnixSocketFlags (UnixSocketFlags value, out Int32 rval);
+
+               public static bool TryFromUnixSocketFlags (UnixSocketFlags value, out Int32 rval)
+               {
+                       return FromUnixSocketFlags (value, out rval) == 0;
+               }
+
+               public static Int32 FromUnixSocketFlags (UnixSocketFlags value)
+               {
+                       Int32 rval;
+                       if (FromUnixSocketFlags (value, out rval) == -1)
+                               ThrowArgumentException (value);
+                       return rval;
+               }
+
+               [DllImport (LIB, EntryPoint="Mono_Posix_ToUnixSocketFlags")]
+               private static extern int ToUnixSocketFlags (Int32 value, out UnixSocketFlags rval);
+
+               public static bool TryToUnixSocketFlags (Int32 value, out UnixSocketFlags rval)
+               {
+                       return ToUnixSocketFlags (value, out rval) == 0;
+               }
+
+               public static UnixSocketFlags ToUnixSocketFlags (Int32 value)
+               {
+                       UnixSocketFlags rval;
+                       if (ToUnixSocketFlags (value, out rval) == -1)
+                               ThrowArgumentException (value);
+                       return rval;
+               }
+
+               [DllImport (LIB, EntryPoint="Mono_Posix_FromUnixSocketOptionName")]
+               private static extern int FromUnixSocketOptionName (UnixSocketOptionName value, out Int32 rval);
+
+               public static bool TryFromUnixSocketOptionName (UnixSocketOptionName value, out Int32 rval)
+               {
+                       return FromUnixSocketOptionName (value, out rval) == 0;
+               }
+
+               public static Int32 FromUnixSocketOptionName (UnixSocketOptionName value)
+               {
+                       Int32 rval;
+                       if (FromUnixSocketOptionName (value, out rval) == -1)
+                               ThrowArgumentException (value);
+                       return rval;
+               }
+
+               [DllImport (LIB, EntryPoint="Mono_Posix_ToUnixSocketOptionName")]
+               private static extern int ToUnixSocketOptionName (Int32 value, out UnixSocketOptionName rval);
+
+               public static bool TryToUnixSocketOptionName (Int32 value, out UnixSocketOptionName rval)
+               {
+                       return ToUnixSocketOptionName (value, out rval) == 0;
+               }
+
+               public static UnixSocketOptionName ToUnixSocketOptionName (Int32 value)
+               {
+                       UnixSocketOptionName rval;
+                       if (ToUnixSocketOptionName (value, out rval) == -1)
+                               ThrowArgumentException (value);
+                       return rval;
+               }
+
+               [DllImport (LIB, EntryPoint="Mono_Posix_FromUnixSocketProtocol")]
+               private static extern int FromUnixSocketProtocol (UnixSocketProtocol value, out Int32 rval);
+
+               public static bool TryFromUnixSocketProtocol (UnixSocketProtocol value, out Int32 rval)
+               {
+                       return FromUnixSocketProtocol (value, out rval) == 0;
+               }
+
+               public static Int32 FromUnixSocketProtocol (UnixSocketProtocol value)
+               {
+                       Int32 rval;
+                       if (FromUnixSocketProtocol (value, out rval) == -1)
+                               ThrowArgumentException (value);
+                       return rval;
+               }
+
+               [DllImport (LIB, EntryPoint="Mono_Posix_ToUnixSocketProtocol")]
+               private static extern int ToUnixSocketProtocol (Int32 value, out UnixSocketProtocol rval);
+
+               public static bool TryToUnixSocketProtocol (Int32 value, out UnixSocketProtocol rval)
+               {
+                       return ToUnixSocketProtocol (value, out rval) == 0;
+               }
+
+               public static UnixSocketProtocol ToUnixSocketProtocol (Int32 value)
+               {
+                       UnixSocketProtocol rval;
+                       if (ToUnixSocketProtocol (value, out rval) == -1)
+                               ThrowArgumentException (value);
+                       return rval;
+               }
+
+               [DllImport (LIB, EntryPoint="Mono_Posix_FromUnixSocketType")]
+               private static extern int FromUnixSocketType (UnixSocketType value, out Int32 rval);
+
+               public static bool TryFromUnixSocketType (UnixSocketType value, out Int32 rval)
+               {
+                       return FromUnixSocketType (value, out rval) == 0;
+               }
+
+               public static Int32 FromUnixSocketType (UnixSocketType value)
+               {
+                       Int32 rval;
+                       if (FromUnixSocketType (value, out rval) == -1)
+                               ThrowArgumentException (value);
+                       return rval;
+               }
+
+               [DllImport (LIB, EntryPoint="Mono_Posix_ToUnixSocketType")]
+               private static extern int ToUnixSocketType (Int32 value, out UnixSocketType rval);
+
+               public static bool TryToUnixSocketType (Int32 value, out UnixSocketType rval)
+               {
+                       return ToUnixSocketType (value, out rval) == 0;
+               }
+
+               public static UnixSocketType ToUnixSocketType (Int32 value)
+               {
+                       UnixSocketType rval;
+                       if (ToUnixSocketType (value, out rval) == -1)
+                               ThrowArgumentException (value);
+                       return rval;
+               }
+
                [DllImport (LIB, EntryPoint="Mono_Posix_FromUtimbuf")]
                private static extern int FromUtimbuf (ref Utimbuf source, IntPtr destination);
 
index c4ff89c0573826bf5b1b77b8f98053f071e0b0d8..8b1246e617eb839c15ca494ea28e54d4566ebeb8 100644 (file)
@@ -727,6 +727,186 @@ namespace Mono.Unix.Native {
                MREMAP_MAYMOVE = 0x1,
        }
 
+       [Map]
+       [CLSCompliant (false)]
+       public enum UnixSocketType : int {
+               SOCK_STREAM    =  1, // Byte-stream socket
+               SOCK_DGRAM     =  2, // Datagram socket
+               SOCK_RAW       =  3, // Raw protocol interface (linux specific)
+               SOCK_RDM       =  4, // Reliably-delivered messages (linux specific)
+               SOCK_SEQPACKET =  5, // Sequenced-packet socket
+               SOCK_DCCP      =  6, // Datagram Congestion Control Protocol (linux specific)
+               SOCK_PACKET    = 10, // Linux specific
+       }
+
+       [Map][Flags]
+       [CLSCompliant (false)]
+       public enum UnixSocketFlags : int {
+               SOCK_CLOEXEC  = 0x80000, /* Atomically set close-on-exec flag for the new descriptor(s). */
+               SOCK_NONBLOCK = 0x00800, /* Atomically mark descriptor(s) as non-blocking. */
+       }
+
+       [Map]
+       [CLSCompliant (false)]
+       public enum UnixSocketProtocol : int {
+               IPPROTO_ICMP    =    1, /* Internet Control Message Protocol */
+               IPPROTO_IGMP    =    2, /* Internet Group Management Protocol */
+               IPPROTO_IPIP    =    4, /* IPIP tunnels (older KA9Q tunnels use 94) */
+               IPPROTO_TCP     =    6, /* Transmission Control Protocol */
+               IPPROTO_EGP     =    8, /* Exterior Gateway Protocol */
+               IPPROTO_PUP     =   12, /* PUP protocol */
+               IPPROTO_UDP     =   17, /* User Datagram Protocol */
+               IPPROTO_IDP     =   22, /* XNS IDP protocol */
+               IPPROTO_TP      =   29, /* SO Transport Protocol Class 4 */
+               IPPROTO_DCCP    =   33, /* Datagram Congestion Control Protocol */
+               IPPROTO_IPV6    =   41, /* IPv6-in-IPv4 tunnelling */
+               IPPROTO_RSVP    =   46, /* RSVP Protocol */
+               IPPROTO_GRE     =   47, /* Cisco GRE tunnels (rfc 1701,1702) */
+               IPPROTO_ESP     =   50, /* Encapsulation Security Payload protocol */
+               IPPROTO_AH      =   51, /* Authentication Header protocol */
+               IPPROTO_MTP     =   92, /* Multicast Transport Protocol */
+               IPPROTO_BEETPH  =   94, /* IP option pseudo header for BEET */
+               IPPROTO_ENCAP   =   98, /* Encapsulation Header */
+               IPPROTO_PIM     =  103, /* Protocol Independent Multicast */
+               IPPROTO_COMP    =  108, /* Compression Header Protocol */
+               IPPROTO_SCTP    =  132, /* Stream Control Transport Protocol */
+               IPPROTO_UDPLITE =  136, /* UDP-Lite (RFC 3828) */
+               IPPROTO_RAW     =  255, /* Raw IP packets */
+
+               // Number used by linux (0) has a special meaning for socket()
+               IPPROTO_IP      = 1024, /* Dummy protocol for TCP */
+               // Number used by linux (1) clashes with IPPROTO_ICMP
+               SOL_SOCKET      = 2048, /* For setsockopt() / getsockopt(): Options to be accessed at socket level, not protocol level. */
+       }
+
+       [Map]
+       [CLSCompliant (false)]
+       public enum UnixAddressFamily : int {
+               AF_UNSPEC     =  0,  /* Unspecified. */
+               AF_UNIX       =  1,  /* Local to host (pipes and file-domain). */
+               AF_INET       =  2,  /* IP protocol family. */
+               AF_AX25       =  3,  /* Amateur Radio AX.25. */
+               AF_IPX        =  4,  /* Novell Internet Protocol. */
+               AF_APPLETALK  =  5,  /* Appletalk DDP. */
+               AF_NETROM     =  6,  /* Amateur radio NetROM. */
+               AF_BRIDGE     =  7,  /* Multiprotocol bridge. */
+               AF_ATMPVC     =  8,  /* ATM PVCs. */
+               AF_X25        =  9,  /* Reserved for X.25 project. */
+               AF_INET6      = 10,  /* IP version 6. */
+               AF_ROSE       = 11,  /* Amateur Radio X.25 PLP. */
+               AF_DECnet     = 12,  /* Reserved for DECnet project. */
+               AF_NETBEUI    = 13,  /* Reserved for 802.2LLC project. */
+               AF_SECURITY   = 14,  /* Security callback pseudo AF. */
+               AF_KEY        = 15,  /* PF_KEY key management API. */
+               AF_NETLINK    = 16,
+               AF_PACKET     = 17,  /* Packet family. */
+               AF_ASH        = 18,  /* Ash. */
+               AF_ECONET     = 19,  /* Acorn Econet. */
+               AF_ATMSVC     = 20,  /* ATM SVCs. */
+               AF_RDS        = 21,  /* RDS sockets. */
+               AF_SNA        = 22,  /* Linux SNA Project */
+               AF_IRDA       = 23,  /* IRDA sockets. */
+               AF_PPPOX      = 24,  /* PPPoX sockets. */
+               AF_WANPIPE    = 25,  /* Wanpipe API sockets. */
+               AF_LLC        = 26,  /* Linux LLC. */
+               AF_CAN        = 29,  /* Controller Area Network. */
+               AF_TIPC       = 30,  /* TIPC sockets. */
+               AF_BLUETOOTH  = 31,  /* Bluetooth sockets. */
+               AF_IUCV       = 32,  /* IUCV sockets. */
+               AF_RXRPC      = 33,  /* RxRPC sockets. */
+               AF_ISDN       = 34,  /* mISDN sockets. */
+               AF_PHONET     = 35,  /* Phonet sockets. */
+               AF_IEEE802154 = 36,  /* IEEE 802.15.4 sockets. */
+               AF_CAIF       = 37,  /* CAIF sockets. */
+               AF_ALG        = 38,  /* Algorithm sockets. */
+               AF_NFC        = 39,  /* NFC sockets. */
+               AF_VSOCK      = 40,  /* vSockets. */
+       }
+
+       [Map]
+       [CLSCompliant (false)]
+       public enum UnixSocketOptionName : int {
+               SO_DEBUG                         =  1,
+               SO_REUSEADDR                     =  2,
+               SO_TYPE                          =  3,
+               SO_ERROR                         =  4,
+               SO_DONTROUTE                     =  5,
+               SO_BROADCAST                     =  6,
+               SO_SNDBUF                        =  7,
+               SO_RCVBUF                        =  8,
+               SO_SNDBUFFORCE                   = 32,
+               SO_RCVBUFFORCE                   = 33,
+               SO_KEEPALIVE                     =  9,
+               SO_OOBINLINE                     = 10,
+               SO_NO_CHECK                      = 11,
+               SO_PRIORITY                      = 12,
+               SO_LINGER                        = 13,
+               SO_BSDCOMPAT                     = 14,
+               SO_REUSEPORT                     = 15,
+               SO_PASSCRED                      = 16,
+               SO_PEERCRED                      = 17,
+               SO_RCVLOWAT                      = 18,
+               SO_SNDLOWAT                      = 19,
+               SO_RCVTIMEO                      = 20,
+               SO_SNDTIMEO                      = 21,
+               SO_SECURITY_AUTHENTICATION       = 22,
+               SO_SECURITY_ENCRYPTION_TRANSPORT = 23,
+               SO_SECURITY_ENCRYPTION_NETWORK   = 24,
+               SO_BINDTODEVICE                  = 25,
+               SO_ATTACH_FILTER                 = 26,
+               SO_DETACH_FILTER                 = 27,
+               SO_PEERNAME                      = 28,
+               SO_TIMESTAMP                     = 29,
+               SO_ACCEPTCONN                    = 30,
+               SO_PEERSEC                       = 31,
+               SO_PASSSEC                       = 34,
+               SO_TIMESTAMPNS                   = 35,
+               SO_MARK                          = 36,
+               SO_TIMESTAMPING                  = 37,
+               SO_PROTOCOL                      = 38,
+               SO_DOMAIN                        = 39,
+               SO_RXQ_OVFL                      = 40,
+               SO_WIFI_STATUS                   = 41,
+               SO_PEEK_OFF                      = 42,
+               SO_NOFCS                         = 43,
+               SO_LOCK_FILTER                   = 44,
+               SO_SELECT_ERR_QUEUE              = 45,
+               SO_BUSY_POLL                     = 46,
+               SO_MAX_PACING_RATE               = 47,
+       }
+
+       [Flags][Map]
+       [CLSCompliant (false)]
+       public enum MessageFlags : int {
+               MSG_OOB          =       0x01, /* Process out-of-band data. */
+               MSG_PEEK         =       0x02, /* Peek at incoming messages. */
+               MSG_DONTROUTE    =       0x04, /* Don't use local routing. */
+               MSG_CTRUNC       =       0x08, /* Control data lost before delivery. */
+               MSG_PROXY        =       0x10, /* Supply or ask second address. */
+               MSG_TRUNC        =       0x20,
+               MSG_DONTWAIT     =       0x40, /* Nonblocking IO. */
+               MSG_EOR          =       0x80, /* End of record. */
+               MSG_WAITALL      =      0x100, /* Wait for a full request. */
+               MSG_FIN          =      0x200,
+               MSG_SYN          =      0x400,
+               MSG_CONFIRM      =      0x800, /* Confirm path validity. */
+               MSG_RST          =     0x1000,
+               MSG_ERRQUEUE     =     0x2000, /* Fetch message from error queue. */
+               MSG_NOSIGNAL     =     0x4000, /* Do not generate SIGPIPE. */
+               MSG_MORE         =     0x8000, /* Sender will send more. */
+               MSG_WAITFORONE   =    0x10000, /* Wait for at least one packet to return.*/
+               MSG_FASTOPEN     = 0x20000000, /* Send data in TCP SYN. */
+               MSG_CMSG_CLOEXEC = 0x40000000, /* Set close_on_exit for file descriptor received through SCM_RIGHTS. */
+       }
+
+       [Map]
+       [CLSCompliant (false)]
+       public enum ShutdownOption : int {
+               SHUT_RD   = 0x01,   /* No more receptions. */
+               SHUT_WR   = 0x02,   /* No more transmissions. */
+               SHUT_RDWR = 0x03,   /* No more receptions or transmissions. */
+       }
+
        #endregion
 
        #region Structures
@@ -1228,6 +1408,14 @@ namespace Mono.Unix.Native {
                [FieldOffset (4)]
                public ulong u64;
        }
+
+       [Map ("struct linger")]
+       [CLSCompliant (false)]
+       public struct Linger {
+               public int l_onoff;
+               public int l_linger;
+       }
+
        #endregion
 
        #region Classes
@@ -4356,6 +4544,243 @@ namespace Mono.Unix.Native {
                        return sys_pwritev (fd, iov, iov.Length, offset);
                }
                #endregion
+
+               #region <socket.h> Declarations
+               //
+               // <socket.h>
+               //
+
+               // socket(2)
+               //    int socket(int domain, int type, int protocol);
+               [DllImport (LIBC, SetLastError=true, 
+                               EntryPoint="socket")]
+               static extern int sys_socket (int domain, int type, int protocol);
+
+               public static int socket (UnixAddressFamily domain, UnixSocketType type, UnixSocketFlags flags, UnixSocketProtocol protocol)
+               {
+                       var _domain = NativeConvert.FromUnixAddressFamily (domain);
+                       var _type = NativeConvert.FromUnixSocketType (type);
+                       var _flags = NativeConvert.FromUnixSocketFlags (flags);
+                       // protocol == 0 is a special case (uses default protocol)
+                       var _protocol = protocol == 0 ? 0 : NativeConvert.FromUnixSocketProtocol (protocol);
+
+                       return sys_socket (_domain, _type | _flags, _protocol);
+               }
+
+               public static int socket (UnixAddressFamily domain, UnixSocketType type, UnixSocketProtocol protocol)
+               {
+                       return socket (domain, type, 0, protocol);
+               }
+
+               // socketpair(2)
+               //    int socketpair(int domain, int type, int protocol, int sv[2]);
+               [DllImport (MPH, SetLastError=true, 
+                               EntryPoint="Mono_Posix_Syscall_socketpair")]
+               static extern int sys_socketpair (int domain, int type, int protocol, out int socket1, out int socket2);
+
+               public static int socketpair (UnixAddressFamily domain, UnixSocketType type, UnixSocketFlags flags, UnixSocketProtocol protocol, out int socket1, out int socket2)
+               {
+                       var _domain = NativeConvert.FromUnixAddressFamily (domain);
+                       var _type = NativeConvert.FromUnixSocketType (type);
+                       var _flags = NativeConvert.FromUnixSocketFlags (flags);
+                       // protocol == 0 is a special case (uses default protocol)
+                       var _protocol = protocol == 0 ? 0 : NativeConvert.FromUnixSocketProtocol (protocol);
+
+                       return sys_socketpair (_domain, _type | _flags, _protocol, out socket1, out socket2);
+               }
+
+               public static int socketpair (UnixAddressFamily domain, UnixSocketType type, UnixSocketProtocol protocol, out int socket1, out int socket2)
+               {
+                       return socketpair (domain, type, 0, protocol, out socket1, out socket2);
+               }
+
+               // sockatmark(2)
+               //    int sockatmark(int sockfd);
+               [DllImport (LIBC, SetLastError=true)]
+               public static extern int sockatmark (int socket);
+
+               // listen(2)
+               //    int listen(int sockfd, int backlog);
+               [DllImport (LIBC, SetLastError=true)]
+               public static extern int listen (int socket, int backlog);
+
+               // getsockopt(2)
+               //    int getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen);
+               [DllImport (MPH, SetLastError=true, 
+                               EntryPoint="Mono_Posix_Syscall_getsockopt")]
+               static extern unsafe int sys_getsockopt (int socket, int level, int option_name, void *option_value, ref long option_len);
+
+               [DllImport (MPH, SetLastError=true, 
+                               EntryPoint="Mono_Posix_Syscall_getsockopt_timeval")]
+               static extern unsafe int sys_getsockopt_timeval (int socket, int level, int option_name, out Timeval option_value);
+
+               [DllImport (MPH, SetLastError=true, 
+                               EntryPoint="Mono_Posix_Syscall_getsockopt_linger")]
+               static extern unsafe int sys_getsockopt_linger (int socket, int level, int option_name, out Linger option_value);
+
+               public static unsafe int getsockopt (int socket, UnixSocketProtocol level, UnixSocketOptionName option_name, void *option_value, ref long option_len)
+               {
+                       var _level = NativeConvert.FromUnixSocketProtocol (level);
+                       var _option_name = NativeConvert.FromUnixSocketOptionName (option_name);
+                       return sys_getsockopt (socket, _level, _option_name, option_value, ref option_len);
+               }
+
+               public static unsafe int getsockopt (int socket, UnixSocketProtocol level, UnixSocketOptionName option_name, IntPtr option_value, ref long option_len)
+               {
+                       return getsockopt (socket, level, option_name, (void*) option_value, ref option_len);
+               }
+
+               public static unsafe int getsockopt (int socket, UnixSocketProtocol level, UnixSocketOptionName option_name, out int option_value)
+               {
+                       int value;
+                       long size = sizeof (int);
+                       int ret = getsockopt (socket, level, option_name, &value, ref size);
+                       if (ret != -1 && size != sizeof (int)) {
+                               SetLastError (Errno.EINVAL);
+                               ret = -1;
+                       }
+                       option_value = value;
+                       return ret;
+               }
+
+               public static unsafe int getsockopt (int socket, UnixSocketProtocol level, UnixSocketOptionName option_name, byte[] option_value, ref long option_len)
+               {
+                       if (option_len > (option_value == null ? 0 : option_value.Length))
+                               throw new ArgumentOutOfRangeException ("option_len", "option_len > (option_value == null ? 0 : option_value.Length)");
+                       fixed (byte* ptr = option_value)
+                               return getsockopt (socket, level, option_name, ptr, ref option_len);
+               }
+
+               public static unsafe int getsockopt (int socket, UnixSocketProtocol level, UnixSocketOptionName option_name, out Timeval option_value)
+               {
+                       var _level = NativeConvert.FromUnixSocketProtocol (level);
+                       var _option_name = NativeConvert.FromUnixSocketOptionName (option_name);
+                       return sys_getsockopt_timeval (socket, _level, _option_name, out option_value);
+               }
+
+               public static unsafe int getsockopt (int socket, UnixSocketProtocol level, UnixSocketOptionName option_name, out Linger option_value)
+               {
+                       var _level = NativeConvert.FromUnixSocketProtocol (level);
+                       var _option_name = NativeConvert.FromUnixSocketOptionName (option_name);
+                       return sys_getsockopt_linger (socket, _level, _option_name, out option_value);
+               }
+
+               // setsockopt(2)
+               //    int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen);
+               [DllImport (MPH, SetLastError=true, 
+                               EntryPoint="Mono_Posix_Syscall_setsockopt")]
+               static extern unsafe int sys_setsockopt (int socket, int level, int option_name, void *option_value, long option_len);
+
+               [DllImport (MPH, SetLastError=true, 
+                               EntryPoint="Mono_Posix_Syscall_setsockopt_timeval")]
+               static extern unsafe int sys_setsockopt_timeval (int socket, int level, int option_name, ref Timeval option_value);
+
+               [DllImport (MPH, SetLastError=true, 
+                               EntryPoint="Mono_Posix_Syscall_setsockopt_linger")]
+               static extern unsafe int sys_setsockopt_linger (int socket, int level, int option_name, ref Linger option_value);
+
+               public static unsafe int setsockopt (int socket, UnixSocketProtocol level, UnixSocketOptionName option_name, void *option_value, long option_len)
+               {
+                       var _level = NativeConvert.FromUnixSocketProtocol (level);
+                       var _option_name = NativeConvert.FromUnixSocketOptionName (option_name);
+                       return sys_setsockopt (socket, _level, _option_name, option_value, option_len);
+               }
+
+               public static unsafe int setsockopt (int socket, UnixSocketProtocol level, UnixSocketOptionName option_name, IntPtr option_value, long option_len)
+               {
+                       return setsockopt (socket, level, option_name, (void*) option_value, option_len);
+               }
+
+               public static unsafe int setsockopt (int socket, UnixSocketProtocol level, UnixSocketOptionName option_name, int option_value)
+               {
+                       return setsockopt (socket, level, option_name, &option_value, sizeof (int));
+               }
+
+               public static unsafe int setsockopt (int socket, UnixSocketProtocol level, UnixSocketOptionName option_name, byte[] option_value, long option_len)
+               {
+                       if (option_len > (option_value == null ? 0 : option_value.Length))
+                               throw new ArgumentOutOfRangeException ("option_len", "option_len > (option_value == null ? 0 : option_value.Length)");
+                       fixed (byte* ptr = option_value)
+                               return setsockopt (socket, level, option_name, ptr, option_len);
+               }
+
+               public static unsafe int setsockopt (int socket, UnixSocketProtocol level, UnixSocketOptionName option_name, Timeval option_value)
+               {
+                       var _level = NativeConvert.FromUnixSocketProtocol (level);
+                       var _option_name = NativeConvert.FromUnixSocketOptionName (option_name);
+                       return sys_setsockopt_timeval (socket, _level, _option_name, ref option_value);
+               }
+
+               public static unsafe int setsockopt (int socket, UnixSocketProtocol level, UnixSocketOptionName option_name, Linger option_value)
+               {
+                       var _level = NativeConvert.FromUnixSocketProtocol (level);
+                       var _option_name = NativeConvert.FromUnixSocketOptionName (option_name);
+                       return sys_setsockopt_linger (socket, _level, _option_name, ref option_value);
+               }
+
+               // shutdown(2)
+               //    int shutdown(int sockfd, int how);
+               [DllImport (LIBC, SetLastError=true, 
+                               EntryPoint="shutdown")]
+               static extern int sys_shutdown (int socket, int how);
+
+               public static int shutdown (int socket, ShutdownOption how)
+               {
+                       var _how = NativeConvert.FromShutdownOption (how);
+                       return sys_shutdown (socket, _how);
+               }
+
+               // recv(2)
+               //    ssize_t recv(int sockfd, void *buf, size_t len, int flags);
+               [DllImport (MPH, SetLastError=true, 
+                               EntryPoint="Mono_Posix_Syscall_recv")]
+               static extern unsafe long sys_recv (int socket, void *buffer, ulong length, int flags);
+
+               public static unsafe long recv (int socket, void *buffer, ulong length, MessageFlags flags)
+               {
+                       int _flags = NativeConvert.FromMessageFlags (flags);
+                       return sys_recv (socket, buffer, length, _flags);
+               }
+
+               public static unsafe long recv (int socket, IntPtr buffer, ulong length, MessageFlags flags)
+               {
+                       return recv (socket, (void*) buffer, length, flags);
+               }
+
+               public static unsafe long recv (int socket, byte[] buffer, ulong length, MessageFlags flags)
+               {
+                       if (length > (ulong) (buffer == null ? 0 : buffer.LongLength))
+                               throw new ArgumentOutOfRangeException ("length", "length > (buffer == null ? 0 : buffer.LongLength)");
+                       fixed (byte* ptr = buffer)
+                               return recv (socket, ptr, length, flags);
+               }
+
+               // send(2)
+               //    ssize_t send(int sockfd, const void *buf, size_t len, int flags);
+               [DllImport (MPH, SetLastError=true, 
+                               EntryPoint="Mono_Posix_Syscall_send")]
+               static extern unsafe long sys_send (int socket, void *message, ulong length, int flags);
+
+               public static unsafe long send (int socket, void *message, ulong length, MessageFlags flags)
+               {
+                       int _flags = NativeConvert.FromMessageFlags (flags);
+                       return sys_send (socket, message, length, _flags);
+               }
+
+               public static unsafe long send (int socket, IntPtr message, ulong length, MessageFlags flags)
+               {
+                       return send (socket, (void*) message, length, flags);
+               }
+
+               public static unsafe long send (int socket, byte[] message, ulong length, MessageFlags flags)
+               {
+                       if (length > (ulong) (message == null ? 0 : message.LongLength))
+                               throw new ArgumentOutOfRangeException ("length", "length > (message == null ? 0 : message.LongLength)");
+                       fixed (byte* ptr = message)
+                               return send (socket, ptr, length, flags);
+               }
+
+               #endregion
        }
 
        #endregion
diff --git a/mcs/class/Mono.Posix/Test/Mono.Unix.Native/SocketTest.cs b/mcs/class/Mono.Posix/Test/Mono.Unix.Native/SocketTest.cs
new file mode 100644 (file)
index 0000000..36a8d23
--- /dev/null
@@ -0,0 +1,217 @@
+//
+// socket-related test cases
+//
+// Authors:
+//  Steffen Kiess (s-kiess@web.de)
+//
+// Copyright (C) 2015 Steffen Kiess
+//
+
+using System;
+using System.IO;
+using System.Net;
+using System.Net.Sockets;
+using System.Runtime.InteropServices;
+
+using Mono.Unix;
+using Mono.Unix.Native;
+
+using NUnit.Framework;
+
+namespace MonoTests.Mono.Unix.Native
+{
+       [TestFixture, Category ("NotDotNet")]
+       public class SocketTest {
+
+               string TempFolder;
+
+               [SetUp]
+               public void SetUp ()
+               {
+                       TempFolder = Path.Combine (Path.GetTempPath (), this.GetType ().FullName);
+
+                       if (Directory.Exists (TempFolder))
+                               Directory.Delete (TempFolder, true);
+
+                       Directory.CreateDirectory (TempFolder);
+               }
+
+               [TearDown]
+               public void TearDown()
+               {
+                       if (Directory.Exists (TempFolder))
+                               Directory.Delete (TempFolder, true);
+               }
+
+               // Set a timeout on all sockets to make sure that if a test fails it
+               // won't cause the program to hang
+               void SetTimeout (int socket)
+               {
+                       var timeout = new Timeval {
+                               tv_sec = 0,
+                               tv_usec = 500000,
+                       };
+                       if (Syscall.setsockopt (socket, UnixSocketProtocol.SOL_SOCKET, UnixSocketOptionName.SO_RCVTIMEO, timeout) < 0 ||
+                                       Syscall.setsockopt (socket, UnixSocketProtocol.SOL_SOCKET, UnixSocketOptionName.SO_SNDTIMEO, timeout) < 0)
+                               UnixMarshal.ThrowExceptionForLastError ();
+               }
+
+               void WithSocketPair (Action<int, int> f)
+               {
+                       int socket1, socket2;
+                       if (Syscall.socketpair (UnixAddressFamily.AF_UNIX, UnixSocketType.SOCK_STREAM, 0, out socket1, out socket2) < 0)
+                               UnixMarshal.ThrowExceptionForLastError ();
+                       try {
+                               SetTimeout (socket1);
+                               SetTimeout (socket2);
+
+                               f (socket1, socket2);
+                       } finally {
+                               int r0 = Syscall.close (socket1);
+                               int r1 = Syscall.close (socket2);
+                               if (r0 < 0 || r1 < 0)
+                                       UnixMarshal.ThrowExceptionForLastError ();
+                       }
+               }
+
+               void WithSockets (UnixAddressFamily af, UnixSocketType type, UnixSocketProtocol protocol, Action<int, int> f)
+               {
+                       int so1, so2;
+                       if ((so1 = Syscall.socket (af, type, protocol)) < 0)
+                               UnixMarshal.ThrowExceptionForLastError ();
+                       try {
+                               if ((so2 = Syscall.socket (af, type, protocol)) < 0)
+                                       UnixMarshal.ThrowExceptionForLastError ();
+                               try {
+                                       SetTimeout (so1);
+                                       SetTimeout (so2);
+
+                                       f (so1, so2);
+                               } finally {
+                                       if (Syscall.close (so2) < 0)
+                                               UnixMarshal.ThrowExceptionForLastError ();
+                               }
+                       } finally {
+                               if (Syscall.close (so1) < 0)
+                                       UnixMarshal.ThrowExceptionForLastError ();
+                       }
+               }
+
+               [Test]
+               public void Socket ()
+               {
+                       int socket;
+                       if ((socket = Syscall.socket (UnixAddressFamily.AF_UNIX, UnixSocketType.SOCK_STREAM, 0)) < 0)
+                               UnixMarshal.ThrowExceptionForLastError ();
+
+                       if (Syscall.close (socket) < 0)
+                               UnixMarshal.ThrowExceptionForLastError ();
+               }
+
+               [Test]
+               public void SocketPair ()
+               {
+                       int socket1, socket2;
+                       if (Syscall.socketpair (UnixAddressFamily.AF_UNIX, UnixSocketType.SOCK_STREAM, 0, out socket1, out socket2) < 0)
+                               UnixMarshal.ThrowExceptionForLastError ();
+
+                       int r0 = Syscall.close (socket1);
+                       int r1 = Syscall.close (socket2);
+                       if (r0 < 0 || r1 < 0)
+                               UnixMarshal.ThrowExceptionForLastError ();
+               }
+
+               [Test]
+               public void SendRecv ()
+               {
+                       WithSocketPair ((so1, so2) => {
+                               long ret;
+                               var buffer1 = new byte[] { 42, 43, 44 };
+                               ret = Syscall.send (so1, buffer1, (ulong) buffer1.Length, 0);
+                               if (ret < 0)
+                                       UnixMarshal.ThrowExceptionForLastError ();
+
+                               var buffer2 = new byte[1024];
+                               ret = Syscall.recv (so2, buffer2, (ulong) buffer2.Length, 0);
+                               if (ret < 0)
+                                       UnixMarshal.ThrowExceptionForLastError ();
+
+                               Assert.AreEqual (buffer1.Length, ret);
+                               for (int i = 0; i < buffer1.Length; i++)
+                                       Assert.AreEqual (buffer1[i], buffer2[i]);
+                       });
+               }
+
+               [Test]
+               public void SockOpt ()
+               {
+                       WithSockets (UnixAddressFamily.AF_UNIX, UnixSocketType.SOCK_STREAM, 0, (so1, so2) => {
+                               // Set SO_REUSEADDR to 1
+                               if (Syscall.setsockopt (so1, UnixSocketProtocol.SOL_SOCKET, UnixSocketOptionName.SO_REUSEADDR, 1) < 0)
+                                       UnixMarshal.ThrowExceptionForLastError ();
+
+                               // Get and check SO_REUSEADDR
+                               int value;
+                               if (Syscall.getsockopt (so1, UnixSocketProtocol.SOL_SOCKET, UnixSocketOptionName.SO_REUSEADDR, out value) < 0)
+                                       UnixMarshal.ThrowExceptionForLastError ();
+                               Assert.AreEqual (value, 1);
+
+                               // Set SO_REUSEADDR to 0
+                               if (Syscall.setsockopt (so1, UnixSocketProtocol.SOL_SOCKET, UnixSocketOptionName.SO_REUSEADDR, new byte[10], 4) < 0)
+                                       UnixMarshal.ThrowExceptionForLastError ();
+
+                               // Get and check SO_REUSEADDR
+                               var buffer = new byte[15];
+                               long size = 12;
+                               if (Syscall.getsockopt (so1, UnixSocketProtocol.SOL_SOCKET, UnixSocketOptionName.SO_REUSEADDR, buffer, ref size) < 0)
+                                       UnixMarshal.ThrowExceptionForLastError ();
+                               Assert.AreEqual (size, 4);
+                               for (int i = 0; i < size; i++)
+                                       Assert.AreEqual (buffer[i], 0);
+                       });
+               }
+
+               [Test]
+               public void SockOptLinger ()
+               {
+                       WithSockets (UnixAddressFamily.AF_INET, UnixSocketType.SOCK_STREAM, UnixSocketProtocol.IPPROTO_TCP, (so1, so2) => {
+                               Linger linger = new Linger {
+                                       l_onoff = 1,
+                                       l_linger = 42,
+                               };
+                               // Set SO_LINGER
+                               if (Syscall.setsockopt (so1, UnixSocketProtocol.SOL_SOCKET, UnixSocketOptionName.SO_LINGER, linger) < 0)
+                                       UnixMarshal.ThrowExceptionForLastError ();
+
+                               // Get and check SO_LINGER
+                               Linger value;
+                               if (Syscall.getsockopt (so1, UnixSocketProtocol.SOL_SOCKET, UnixSocketOptionName.SO_LINGER, out value) < 0)
+                                       UnixMarshal.ThrowExceptionForLastError ();
+                               Assert.AreEqual (linger, value);
+                       });
+               }
+
+               [Test]
+               public void Shutdown ()
+               {
+                       WithSocketPair ((so1, so2) => {
+                               if (Syscall.shutdown (so1, ShutdownOption.SHUT_WR) < 0)
+                                       UnixMarshal.ThrowExceptionForLastError ();
+
+                               var buffer2 = new byte[1024];
+                               long ret = Syscall.recv (so2, buffer2, (ulong) buffer2.Length, 0);
+                               if (ret < 0)
+                                       UnixMarshal.ThrowExceptionForLastError ();
+
+                               Assert.AreEqual (ret, 0);
+                       });
+               }
+       }
+}
+
+// vim: noexpandtab
+// Local Variables: 
+// tab-width: 4
+// c-basic-offset: 4
+// indent-tabs-mode: t
+// End: 
index c91511cf0e24d3f70f944a3e2676c44b92c2f01a..79154fc99bbd9b232eb8c4bd1e16119b07d9bb45 100644 (file)
@@ -39,6 +39,7 @@ MPH_UNIX_SOURCE =                             \
        serial.c                                \
        sys-mman.c                              \
        sys-sendfile.c                          \
+       sys-socket.c                            \
        sys-stat.c                              \
        sys-statvfs.c                           \
        sys-time.c                              \
@@ -135,12 +136,14 @@ refresh:
        --impl-macro=_GNU_SOURCE --impl-macro=_XOPEN_SOURCE   \
        --impl-header="<sys/types.h>"                         \
        --impl-header="<sys/stat.h>"                          \
+       --autoconf-header="<netinet/in.h>"                    \
        --autoconf-header="<sys/time.h>"                      \
        --autoconf-header="<sys/poll.h>"                      \
        --autoconf-header="<sys/wait.h>"                      \
        --autoconf-header="<sys/statvfs.h>"                   \
        --autoconf-header="<sys/xattr.h>"                     \
        --autoconf-header="<sys/mman.h>"                      \
+       --autoconf-header="<sys/socket.h>"                    \
        --autoconf-header="<sys/uio.h>"                       \
        --autoconf-header="<unistd.h>"                        \
        --impl-header="<fcntl.h>"                             \
@@ -158,7 +161,7 @@ refresh:
        --rename-member=st_mtime=st_mtime_                    \
        --rename-namespace=Mono.Unix.Native=Mono.Posix        \
        --library=MonoPosixHelper                             \
-       $(mcs_topdir)/class/lib/net_4_5/Mono.Posix.dll map
+       $(mcs_topdir)/class/lib/net_4_x/Mono.Posix.dll map
 
 # Useful if mono is compiled with --enable-shared=no
 patch-libtool:
index 737c217727585521e981daf3f93ed8c7b5eb1f7b..ee61ae661d9be7e741c0997fdf7e6de54ccc5d9a 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 /home/kiesssn/prog/mono/mono/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 */
@@ -3115,6 +3121,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 +3257,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;
@@ -4491,6 +4737,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;
@@ -7373,6 +7665,1286 @@ 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 == 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 */
+       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)
index 9c170eac0dc5faf2d525c4e40aa2121080901830..34cdb68ab4da8bab5ff81cddbf5c53e4e976b712 100644 (file)
@@ -621,6 +621,49 @@ enum Mono_Posix_LockfCommand {
 int Mono_Posix_FromLockfCommand (int x, int *r);
 int Mono_Posix_ToLockfCommand (int x, int *r);
 
+enum Mono_Posix_MessageFlags {
+       Mono_Posix_MessageFlags_MSG_CMSG_CLOEXEC       = 0x40000000,
+       #define Mono_Posix_MessageFlags_MSG_CMSG_CLOEXEC Mono_Posix_MessageFlags_MSG_CMSG_CLOEXEC
+       Mono_Posix_MessageFlags_MSG_CONFIRM            = 0x00000800,
+       #define Mono_Posix_MessageFlags_MSG_CONFIRM      Mono_Posix_MessageFlags_MSG_CONFIRM
+       Mono_Posix_MessageFlags_MSG_CTRUNC             = 0x00000008,
+       #define Mono_Posix_MessageFlags_MSG_CTRUNC       Mono_Posix_MessageFlags_MSG_CTRUNC
+       Mono_Posix_MessageFlags_MSG_DONTROUTE          = 0x00000004,
+       #define Mono_Posix_MessageFlags_MSG_DONTROUTE    Mono_Posix_MessageFlags_MSG_DONTROUTE
+       Mono_Posix_MessageFlags_MSG_DONTWAIT           = 0x00000040,
+       #define Mono_Posix_MessageFlags_MSG_DONTWAIT     Mono_Posix_MessageFlags_MSG_DONTWAIT
+       Mono_Posix_MessageFlags_MSG_EOR                = 0x00000080,
+       #define Mono_Posix_MessageFlags_MSG_EOR          Mono_Posix_MessageFlags_MSG_EOR
+       Mono_Posix_MessageFlags_MSG_ERRQUEUE           = 0x00002000,
+       #define Mono_Posix_MessageFlags_MSG_ERRQUEUE     Mono_Posix_MessageFlags_MSG_ERRQUEUE
+       Mono_Posix_MessageFlags_MSG_FASTOPEN           = 0x20000000,
+       #define Mono_Posix_MessageFlags_MSG_FASTOPEN     Mono_Posix_MessageFlags_MSG_FASTOPEN
+       Mono_Posix_MessageFlags_MSG_FIN                = 0x00000200,
+       #define Mono_Posix_MessageFlags_MSG_FIN          Mono_Posix_MessageFlags_MSG_FIN
+       Mono_Posix_MessageFlags_MSG_MORE               = 0x00008000,
+       #define Mono_Posix_MessageFlags_MSG_MORE         Mono_Posix_MessageFlags_MSG_MORE
+       Mono_Posix_MessageFlags_MSG_NOSIGNAL           = 0x00004000,
+       #define Mono_Posix_MessageFlags_MSG_NOSIGNAL     Mono_Posix_MessageFlags_MSG_NOSIGNAL
+       Mono_Posix_MessageFlags_MSG_OOB                = 0x00000001,
+       #define Mono_Posix_MessageFlags_MSG_OOB          Mono_Posix_MessageFlags_MSG_OOB
+       Mono_Posix_MessageFlags_MSG_PEEK               = 0x00000002,
+       #define Mono_Posix_MessageFlags_MSG_PEEK         Mono_Posix_MessageFlags_MSG_PEEK
+       Mono_Posix_MessageFlags_MSG_PROXY              = 0x00000010,
+       #define Mono_Posix_MessageFlags_MSG_PROXY        Mono_Posix_MessageFlags_MSG_PROXY
+       Mono_Posix_MessageFlags_MSG_RST                = 0x00001000,
+       #define Mono_Posix_MessageFlags_MSG_RST          Mono_Posix_MessageFlags_MSG_RST
+       Mono_Posix_MessageFlags_MSG_SYN                = 0x00000400,
+       #define Mono_Posix_MessageFlags_MSG_SYN          Mono_Posix_MessageFlags_MSG_SYN
+       Mono_Posix_MessageFlags_MSG_TRUNC              = 0x00000020,
+       #define Mono_Posix_MessageFlags_MSG_TRUNC        Mono_Posix_MessageFlags_MSG_TRUNC
+       Mono_Posix_MessageFlags_MSG_WAITALL            = 0x00000100,
+       #define Mono_Posix_MessageFlags_MSG_WAITALL      Mono_Posix_MessageFlags_MSG_WAITALL
+       Mono_Posix_MessageFlags_MSG_WAITFORONE         = 0x00010000,
+       #define Mono_Posix_MessageFlags_MSG_WAITFORONE   Mono_Posix_MessageFlags_MSG_WAITFORONE
+};
+int Mono_Posix_FromMessageFlags (int x, int *r);
+int Mono_Posix_ToMessageFlags (int x, int *r);
+
 enum Mono_Posix_MlockallFlags {
        Mono_Posix_MlockallFlags_MCL_CURRENT       = 0x00000001,
        #define Mono_Posix_MlockallFlags_MCL_CURRENT Mono_Posix_MlockallFlags_MCL_CURRENT
@@ -889,6 +932,17 @@ enum Mono_Posix_SeekFlags {
 int Mono_Posix_FromSeekFlags (short x, short *r);
 int Mono_Posix_ToSeekFlags (short x, short *r);
 
+enum Mono_Posix_ShutdownOption {
+       Mono_Posix_ShutdownOption_SHUT_RD         = 0x00000001,
+       #define Mono_Posix_ShutdownOption_SHUT_RD   Mono_Posix_ShutdownOption_SHUT_RD
+       Mono_Posix_ShutdownOption_SHUT_RDWR       = 0x00000003,
+       #define Mono_Posix_ShutdownOption_SHUT_RDWR Mono_Posix_ShutdownOption_SHUT_RDWR
+       Mono_Posix_ShutdownOption_SHUT_WR         = 0x00000002,
+       #define Mono_Posix_ShutdownOption_SHUT_WR   Mono_Posix_ShutdownOption_SHUT_WR
+};
+int Mono_Posix_FromShutdownOption (int x, int *r);
+int Mono_Posix_ToShutdownOption (int x, int *r);
+
 enum Mono_Posix_Signum {
        Mono_Posix_Signum_SIGABRT         = 0x00000006,
        #define Mono_Posix_Signum_SIGABRT   Mono_Posix_Signum_SIGABRT
@@ -1454,6 +1508,271 @@ enum Mono_Posix_SyslogOptions {
 int Mono_Posix_FromSyslogOptions (int x, int *r);
 int Mono_Posix_ToSyslogOptions (int x, int *r);
 
+enum Mono_Posix_UnixAddressFamily {
+       Mono_Posix_UnixAddressFamily_AF_ALG              = 0x00000026,
+       #define Mono_Posix_UnixAddressFamily_AF_ALG        Mono_Posix_UnixAddressFamily_AF_ALG
+       Mono_Posix_UnixAddressFamily_AF_APPLETALK        = 0x00000005,
+       #define Mono_Posix_UnixAddressFamily_AF_APPLETALK  Mono_Posix_UnixAddressFamily_AF_APPLETALK
+       Mono_Posix_UnixAddressFamily_AF_ASH              = 0x00000012,
+       #define Mono_Posix_UnixAddressFamily_AF_ASH        Mono_Posix_UnixAddressFamily_AF_ASH
+       Mono_Posix_UnixAddressFamily_AF_ATMPVC           = 0x00000008,
+       #define Mono_Posix_UnixAddressFamily_AF_ATMPVC     Mono_Posix_UnixAddressFamily_AF_ATMPVC
+       Mono_Posix_UnixAddressFamily_AF_ATMSVC           = 0x00000014,
+       #define Mono_Posix_UnixAddressFamily_AF_ATMSVC     Mono_Posix_UnixAddressFamily_AF_ATMSVC
+       Mono_Posix_UnixAddressFamily_AF_AX25             = 0x00000003,
+       #define Mono_Posix_UnixAddressFamily_AF_AX25       Mono_Posix_UnixAddressFamily_AF_AX25
+       Mono_Posix_UnixAddressFamily_AF_BLUETOOTH        = 0x0000001f,
+       #define Mono_Posix_UnixAddressFamily_AF_BLUETOOTH  Mono_Posix_UnixAddressFamily_AF_BLUETOOTH
+       Mono_Posix_UnixAddressFamily_AF_BRIDGE           = 0x00000007,
+       #define Mono_Posix_UnixAddressFamily_AF_BRIDGE     Mono_Posix_UnixAddressFamily_AF_BRIDGE
+       Mono_Posix_UnixAddressFamily_AF_CAIF             = 0x00000025,
+       #define Mono_Posix_UnixAddressFamily_AF_CAIF       Mono_Posix_UnixAddressFamily_AF_CAIF
+       Mono_Posix_UnixAddressFamily_AF_CAN              = 0x0000001d,
+       #define Mono_Posix_UnixAddressFamily_AF_CAN        Mono_Posix_UnixAddressFamily_AF_CAN
+       Mono_Posix_UnixAddressFamily_AF_DECnet           = 0x0000000c,
+       #define Mono_Posix_UnixAddressFamily_AF_DECnet     Mono_Posix_UnixAddressFamily_AF_DECnet
+       Mono_Posix_UnixAddressFamily_AF_ECONET           = 0x00000013,
+       #define Mono_Posix_UnixAddressFamily_AF_ECONET     Mono_Posix_UnixAddressFamily_AF_ECONET
+       Mono_Posix_UnixAddressFamily_AF_IEEE802154       = 0x00000024,
+       #define Mono_Posix_UnixAddressFamily_AF_IEEE802154 Mono_Posix_UnixAddressFamily_AF_IEEE802154
+       Mono_Posix_UnixAddressFamily_AF_INET             = 0x00000002,
+       #define Mono_Posix_UnixAddressFamily_AF_INET       Mono_Posix_UnixAddressFamily_AF_INET
+       Mono_Posix_UnixAddressFamily_AF_INET6            = 0x0000000a,
+       #define Mono_Posix_UnixAddressFamily_AF_INET6      Mono_Posix_UnixAddressFamily_AF_INET6
+       Mono_Posix_UnixAddressFamily_AF_IPX              = 0x00000004,
+       #define Mono_Posix_UnixAddressFamily_AF_IPX        Mono_Posix_UnixAddressFamily_AF_IPX
+       Mono_Posix_UnixAddressFamily_AF_IRDA             = 0x00000017,
+       #define Mono_Posix_UnixAddressFamily_AF_IRDA       Mono_Posix_UnixAddressFamily_AF_IRDA
+       Mono_Posix_UnixAddressFamily_AF_ISDN             = 0x00000022,
+       #define Mono_Posix_UnixAddressFamily_AF_ISDN       Mono_Posix_UnixAddressFamily_AF_ISDN
+       Mono_Posix_UnixAddressFamily_AF_IUCV             = 0x00000020,
+       #define Mono_Posix_UnixAddressFamily_AF_IUCV       Mono_Posix_UnixAddressFamily_AF_IUCV
+       Mono_Posix_UnixAddressFamily_AF_KEY              = 0x0000000f,
+       #define Mono_Posix_UnixAddressFamily_AF_KEY        Mono_Posix_UnixAddressFamily_AF_KEY
+       Mono_Posix_UnixAddressFamily_AF_LLC              = 0x0000001a,
+       #define Mono_Posix_UnixAddressFamily_AF_LLC        Mono_Posix_UnixAddressFamily_AF_LLC
+       Mono_Posix_UnixAddressFamily_AF_NETBEUI          = 0x0000000d,
+       #define Mono_Posix_UnixAddressFamily_AF_NETBEUI    Mono_Posix_UnixAddressFamily_AF_NETBEUI
+       Mono_Posix_UnixAddressFamily_AF_NETLINK          = 0x00000010,
+       #define Mono_Posix_UnixAddressFamily_AF_NETLINK    Mono_Posix_UnixAddressFamily_AF_NETLINK
+       Mono_Posix_UnixAddressFamily_AF_NETROM           = 0x00000006,
+       #define Mono_Posix_UnixAddressFamily_AF_NETROM     Mono_Posix_UnixAddressFamily_AF_NETROM
+       Mono_Posix_UnixAddressFamily_AF_NFC              = 0x00000027,
+       #define Mono_Posix_UnixAddressFamily_AF_NFC        Mono_Posix_UnixAddressFamily_AF_NFC
+       Mono_Posix_UnixAddressFamily_AF_PACKET           = 0x00000011,
+       #define Mono_Posix_UnixAddressFamily_AF_PACKET     Mono_Posix_UnixAddressFamily_AF_PACKET
+       Mono_Posix_UnixAddressFamily_AF_PHONET           = 0x00000023,
+       #define Mono_Posix_UnixAddressFamily_AF_PHONET     Mono_Posix_UnixAddressFamily_AF_PHONET
+       Mono_Posix_UnixAddressFamily_AF_PPPOX            = 0x00000018,
+       #define Mono_Posix_UnixAddressFamily_AF_PPPOX      Mono_Posix_UnixAddressFamily_AF_PPPOX
+       Mono_Posix_UnixAddressFamily_AF_RDS              = 0x00000015,
+       #define Mono_Posix_UnixAddressFamily_AF_RDS        Mono_Posix_UnixAddressFamily_AF_RDS
+       Mono_Posix_UnixAddressFamily_AF_ROSE             = 0x0000000b,
+       #define Mono_Posix_UnixAddressFamily_AF_ROSE       Mono_Posix_UnixAddressFamily_AF_ROSE
+       Mono_Posix_UnixAddressFamily_AF_RXRPC            = 0x00000021,
+       #define Mono_Posix_UnixAddressFamily_AF_RXRPC      Mono_Posix_UnixAddressFamily_AF_RXRPC
+       Mono_Posix_UnixAddressFamily_AF_SECURITY         = 0x0000000e,
+       #define Mono_Posix_UnixAddressFamily_AF_SECURITY   Mono_Posix_UnixAddressFamily_AF_SECURITY
+       Mono_Posix_UnixAddressFamily_AF_SNA              = 0x00000016,
+       #define Mono_Posix_UnixAddressFamily_AF_SNA        Mono_Posix_UnixAddressFamily_AF_SNA
+       Mono_Posix_UnixAddressFamily_AF_TIPC             = 0x0000001e,
+       #define Mono_Posix_UnixAddressFamily_AF_TIPC       Mono_Posix_UnixAddressFamily_AF_TIPC
+       Mono_Posix_UnixAddressFamily_AF_UNIX             = 0x00000001,
+       #define Mono_Posix_UnixAddressFamily_AF_UNIX       Mono_Posix_UnixAddressFamily_AF_UNIX
+       Mono_Posix_UnixAddressFamily_AF_UNSPEC           = 0x00000000,
+       #define Mono_Posix_UnixAddressFamily_AF_UNSPEC     Mono_Posix_UnixAddressFamily_AF_UNSPEC
+       Mono_Posix_UnixAddressFamily_AF_VSOCK            = 0x00000028,
+       #define Mono_Posix_UnixAddressFamily_AF_VSOCK      Mono_Posix_UnixAddressFamily_AF_VSOCK
+       Mono_Posix_UnixAddressFamily_AF_WANPIPE          = 0x00000019,
+       #define Mono_Posix_UnixAddressFamily_AF_WANPIPE    Mono_Posix_UnixAddressFamily_AF_WANPIPE
+       Mono_Posix_UnixAddressFamily_AF_X25              = 0x00000009,
+       #define Mono_Posix_UnixAddressFamily_AF_X25        Mono_Posix_UnixAddressFamily_AF_X25
+};
+int Mono_Posix_FromUnixAddressFamily (int x, int *r);
+int Mono_Posix_ToUnixAddressFamily (int x, int *r);
+
+enum Mono_Posix_UnixSocketFlags {
+       Mono_Posix_UnixSocketFlags_SOCK_CLOEXEC        = 0x00080000,
+       #define Mono_Posix_UnixSocketFlags_SOCK_CLOEXEC  Mono_Posix_UnixSocketFlags_SOCK_CLOEXEC
+       Mono_Posix_UnixSocketFlags_SOCK_NONBLOCK       = 0x00000800,
+       #define Mono_Posix_UnixSocketFlags_SOCK_NONBLOCK Mono_Posix_UnixSocketFlags_SOCK_NONBLOCK
+};
+int Mono_Posix_FromUnixSocketFlags (int x, int *r);
+int Mono_Posix_ToUnixSocketFlags (int x, int *r);
+
+enum Mono_Posix_UnixSocketOptionName {
+       Mono_Posix_UnixSocketOptionName_SO_ACCEPTCONN                          = 0x0000001e,
+       #define Mono_Posix_UnixSocketOptionName_SO_ACCEPTCONN                    Mono_Posix_UnixSocketOptionName_SO_ACCEPTCONN
+       Mono_Posix_UnixSocketOptionName_SO_ATTACH_FILTER                       = 0x0000001a,
+       #define Mono_Posix_UnixSocketOptionName_SO_ATTACH_FILTER                 Mono_Posix_UnixSocketOptionName_SO_ATTACH_FILTER
+       Mono_Posix_UnixSocketOptionName_SO_BINDTODEVICE                        = 0x00000019,
+       #define Mono_Posix_UnixSocketOptionName_SO_BINDTODEVICE                  Mono_Posix_UnixSocketOptionName_SO_BINDTODEVICE
+       Mono_Posix_UnixSocketOptionName_SO_BROADCAST                           = 0x00000006,
+       #define Mono_Posix_UnixSocketOptionName_SO_BROADCAST                     Mono_Posix_UnixSocketOptionName_SO_BROADCAST
+       Mono_Posix_UnixSocketOptionName_SO_BSDCOMPAT                           = 0x0000000e,
+       #define Mono_Posix_UnixSocketOptionName_SO_BSDCOMPAT                     Mono_Posix_UnixSocketOptionName_SO_BSDCOMPAT
+       Mono_Posix_UnixSocketOptionName_SO_BUSY_POLL                           = 0x0000002e,
+       #define Mono_Posix_UnixSocketOptionName_SO_BUSY_POLL                     Mono_Posix_UnixSocketOptionName_SO_BUSY_POLL
+       Mono_Posix_UnixSocketOptionName_SO_DEBUG                               = 0x00000001,
+       #define Mono_Posix_UnixSocketOptionName_SO_DEBUG                         Mono_Posix_UnixSocketOptionName_SO_DEBUG
+       Mono_Posix_UnixSocketOptionName_SO_DETACH_FILTER                       = 0x0000001b,
+       #define Mono_Posix_UnixSocketOptionName_SO_DETACH_FILTER                 Mono_Posix_UnixSocketOptionName_SO_DETACH_FILTER
+       Mono_Posix_UnixSocketOptionName_SO_DOMAIN                              = 0x00000027,
+       #define Mono_Posix_UnixSocketOptionName_SO_DOMAIN                        Mono_Posix_UnixSocketOptionName_SO_DOMAIN
+       Mono_Posix_UnixSocketOptionName_SO_DONTROUTE                           = 0x00000005,
+       #define Mono_Posix_UnixSocketOptionName_SO_DONTROUTE                     Mono_Posix_UnixSocketOptionName_SO_DONTROUTE
+       Mono_Posix_UnixSocketOptionName_SO_ERROR                               = 0x00000004,
+       #define Mono_Posix_UnixSocketOptionName_SO_ERROR                         Mono_Posix_UnixSocketOptionName_SO_ERROR
+       Mono_Posix_UnixSocketOptionName_SO_KEEPALIVE                           = 0x00000009,
+       #define Mono_Posix_UnixSocketOptionName_SO_KEEPALIVE                     Mono_Posix_UnixSocketOptionName_SO_KEEPALIVE
+       Mono_Posix_UnixSocketOptionName_SO_LINGER                              = 0x0000000d,
+       #define Mono_Posix_UnixSocketOptionName_SO_LINGER                        Mono_Posix_UnixSocketOptionName_SO_LINGER
+       Mono_Posix_UnixSocketOptionName_SO_LOCK_FILTER                         = 0x0000002c,
+       #define Mono_Posix_UnixSocketOptionName_SO_LOCK_FILTER                   Mono_Posix_UnixSocketOptionName_SO_LOCK_FILTER
+       Mono_Posix_UnixSocketOptionName_SO_MARK                                = 0x00000024,
+       #define Mono_Posix_UnixSocketOptionName_SO_MARK                          Mono_Posix_UnixSocketOptionName_SO_MARK
+       Mono_Posix_UnixSocketOptionName_SO_MAX_PACING_RATE                     = 0x0000002f,
+       #define Mono_Posix_UnixSocketOptionName_SO_MAX_PACING_RATE               Mono_Posix_UnixSocketOptionName_SO_MAX_PACING_RATE
+       Mono_Posix_UnixSocketOptionName_SO_NOFCS                               = 0x0000002b,
+       #define Mono_Posix_UnixSocketOptionName_SO_NOFCS                         Mono_Posix_UnixSocketOptionName_SO_NOFCS
+       Mono_Posix_UnixSocketOptionName_SO_NO_CHECK                            = 0x0000000b,
+       #define Mono_Posix_UnixSocketOptionName_SO_NO_CHECK                      Mono_Posix_UnixSocketOptionName_SO_NO_CHECK
+       Mono_Posix_UnixSocketOptionName_SO_OOBINLINE                           = 0x0000000a,
+       #define Mono_Posix_UnixSocketOptionName_SO_OOBINLINE                     Mono_Posix_UnixSocketOptionName_SO_OOBINLINE
+       Mono_Posix_UnixSocketOptionName_SO_PASSCRED                            = 0x00000010,
+       #define Mono_Posix_UnixSocketOptionName_SO_PASSCRED                      Mono_Posix_UnixSocketOptionName_SO_PASSCRED
+       Mono_Posix_UnixSocketOptionName_SO_PASSSEC                             = 0x00000022,
+       #define Mono_Posix_UnixSocketOptionName_SO_PASSSEC                       Mono_Posix_UnixSocketOptionName_SO_PASSSEC
+       Mono_Posix_UnixSocketOptionName_SO_PEEK_OFF                            = 0x0000002a,
+       #define Mono_Posix_UnixSocketOptionName_SO_PEEK_OFF                      Mono_Posix_UnixSocketOptionName_SO_PEEK_OFF
+       Mono_Posix_UnixSocketOptionName_SO_PEERCRED                            = 0x00000011,
+       #define Mono_Posix_UnixSocketOptionName_SO_PEERCRED                      Mono_Posix_UnixSocketOptionName_SO_PEERCRED
+       Mono_Posix_UnixSocketOptionName_SO_PEERNAME                            = 0x0000001c,
+       #define Mono_Posix_UnixSocketOptionName_SO_PEERNAME                      Mono_Posix_UnixSocketOptionName_SO_PEERNAME
+       Mono_Posix_UnixSocketOptionName_SO_PEERSEC                             = 0x0000001f,
+       #define Mono_Posix_UnixSocketOptionName_SO_PEERSEC                       Mono_Posix_UnixSocketOptionName_SO_PEERSEC
+       Mono_Posix_UnixSocketOptionName_SO_PRIORITY                            = 0x0000000c,
+       #define Mono_Posix_UnixSocketOptionName_SO_PRIORITY                      Mono_Posix_UnixSocketOptionName_SO_PRIORITY
+       Mono_Posix_UnixSocketOptionName_SO_PROTOCOL                            = 0x00000026,
+       #define Mono_Posix_UnixSocketOptionName_SO_PROTOCOL                      Mono_Posix_UnixSocketOptionName_SO_PROTOCOL
+       Mono_Posix_UnixSocketOptionName_SO_RCVBUF                              = 0x00000008,
+       #define Mono_Posix_UnixSocketOptionName_SO_RCVBUF                        Mono_Posix_UnixSocketOptionName_SO_RCVBUF
+       Mono_Posix_UnixSocketOptionName_SO_RCVBUFFORCE                         = 0x00000021,
+       #define Mono_Posix_UnixSocketOptionName_SO_RCVBUFFORCE                   Mono_Posix_UnixSocketOptionName_SO_RCVBUFFORCE
+       Mono_Posix_UnixSocketOptionName_SO_RCVLOWAT                            = 0x00000012,
+       #define Mono_Posix_UnixSocketOptionName_SO_RCVLOWAT                      Mono_Posix_UnixSocketOptionName_SO_RCVLOWAT
+       Mono_Posix_UnixSocketOptionName_SO_RCVTIMEO                            = 0x00000014,
+       #define Mono_Posix_UnixSocketOptionName_SO_RCVTIMEO                      Mono_Posix_UnixSocketOptionName_SO_RCVTIMEO
+       Mono_Posix_UnixSocketOptionName_SO_REUSEADDR                           = 0x00000002,
+       #define Mono_Posix_UnixSocketOptionName_SO_REUSEADDR                     Mono_Posix_UnixSocketOptionName_SO_REUSEADDR
+       Mono_Posix_UnixSocketOptionName_SO_REUSEPORT                           = 0x0000000f,
+       #define Mono_Posix_UnixSocketOptionName_SO_REUSEPORT                     Mono_Posix_UnixSocketOptionName_SO_REUSEPORT
+       Mono_Posix_UnixSocketOptionName_SO_RXQ_OVFL                            = 0x00000028,
+       #define Mono_Posix_UnixSocketOptionName_SO_RXQ_OVFL                      Mono_Posix_UnixSocketOptionName_SO_RXQ_OVFL
+       Mono_Posix_UnixSocketOptionName_SO_SECURITY_AUTHENTICATION             = 0x00000016,
+       #define Mono_Posix_UnixSocketOptionName_SO_SECURITY_AUTHENTICATION       Mono_Posix_UnixSocketOptionName_SO_SECURITY_AUTHENTICATION
+       Mono_Posix_UnixSocketOptionName_SO_SECURITY_ENCRYPTION_NETWORK         = 0x00000018,
+       #define Mono_Posix_UnixSocketOptionName_SO_SECURITY_ENCRYPTION_NETWORK   Mono_Posix_UnixSocketOptionName_SO_SECURITY_ENCRYPTION_NETWORK
+       Mono_Posix_UnixSocketOptionName_SO_SECURITY_ENCRYPTION_TRANSPORT       = 0x00000017,
+       #define Mono_Posix_UnixSocketOptionName_SO_SECURITY_ENCRYPTION_TRANSPORT Mono_Posix_UnixSocketOptionName_SO_SECURITY_ENCRYPTION_TRANSPORT
+       Mono_Posix_UnixSocketOptionName_SO_SELECT_ERR_QUEUE                    = 0x0000002d,
+       #define Mono_Posix_UnixSocketOptionName_SO_SELECT_ERR_QUEUE              Mono_Posix_UnixSocketOptionName_SO_SELECT_ERR_QUEUE
+       Mono_Posix_UnixSocketOptionName_SO_SNDBUF                              = 0x00000007,
+       #define Mono_Posix_UnixSocketOptionName_SO_SNDBUF                        Mono_Posix_UnixSocketOptionName_SO_SNDBUF
+       Mono_Posix_UnixSocketOptionName_SO_SNDBUFFORCE                         = 0x00000020,
+       #define Mono_Posix_UnixSocketOptionName_SO_SNDBUFFORCE                   Mono_Posix_UnixSocketOptionName_SO_SNDBUFFORCE
+       Mono_Posix_UnixSocketOptionName_SO_SNDLOWAT                            = 0x00000013,
+       #define Mono_Posix_UnixSocketOptionName_SO_SNDLOWAT                      Mono_Posix_UnixSocketOptionName_SO_SNDLOWAT
+       Mono_Posix_UnixSocketOptionName_SO_SNDTIMEO                            = 0x00000015,
+       #define Mono_Posix_UnixSocketOptionName_SO_SNDTIMEO                      Mono_Posix_UnixSocketOptionName_SO_SNDTIMEO
+       Mono_Posix_UnixSocketOptionName_SO_TIMESTAMP                           = 0x0000001d,
+       #define Mono_Posix_UnixSocketOptionName_SO_TIMESTAMP                     Mono_Posix_UnixSocketOptionName_SO_TIMESTAMP
+       Mono_Posix_UnixSocketOptionName_SO_TIMESTAMPING                        = 0x00000025,
+       #define Mono_Posix_UnixSocketOptionName_SO_TIMESTAMPING                  Mono_Posix_UnixSocketOptionName_SO_TIMESTAMPING
+       Mono_Posix_UnixSocketOptionName_SO_TIMESTAMPNS                         = 0x00000023,
+       #define Mono_Posix_UnixSocketOptionName_SO_TIMESTAMPNS                   Mono_Posix_UnixSocketOptionName_SO_TIMESTAMPNS
+       Mono_Posix_UnixSocketOptionName_SO_TYPE                                = 0x00000003,
+       #define Mono_Posix_UnixSocketOptionName_SO_TYPE                          Mono_Posix_UnixSocketOptionName_SO_TYPE
+       Mono_Posix_UnixSocketOptionName_SO_WIFI_STATUS                         = 0x00000029,
+       #define Mono_Posix_UnixSocketOptionName_SO_WIFI_STATUS                   Mono_Posix_UnixSocketOptionName_SO_WIFI_STATUS
+};
+int Mono_Posix_FromUnixSocketOptionName (int x, int *r);
+int Mono_Posix_ToUnixSocketOptionName (int x, int *r);
+
+enum Mono_Posix_UnixSocketProtocol {
+       Mono_Posix_UnixSocketProtocol_IPPROTO_AH            = 0x00000033,
+       #define Mono_Posix_UnixSocketProtocol_IPPROTO_AH      Mono_Posix_UnixSocketProtocol_IPPROTO_AH
+       Mono_Posix_UnixSocketProtocol_IPPROTO_BEETPH        = 0x0000005e,
+       #define Mono_Posix_UnixSocketProtocol_IPPROTO_BEETPH  Mono_Posix_UnixSocketProtocol_IPPROTO_BEETPH
+       Mono_Posix_UnixSocketProtocol_IPPROTO_COMP          = 0x0000006c,
+       #define Mono_Posix_UnixSocketProtocol_IPPROTO_COMP    Mono_Posix_UnixSocketProtocol_IPPROTO_COMP
+       Mono_Posix_UnixSocketProtocol_IPPROTO_DCCP          = 0x00000021,
+       #define Mono_Posix_UnixSocketProtocol_IPPROTO_DCCP    Mono_Posix_UnixSocketProtocol_IPPROTO_DCCP
+       Mono_Posix_UnixSocketProtocol_IPPROTO_EGP           = 0x00000008,
+       #define Mono_Posix_UnixSocketProtocol_IPPROTO_EGP     Mono_Posix_UnixSocketProtocol_IPPROTO_EGP
+       Mono_Posix_UnixSocketProtocol_IPPROTO_ENCAP         = 0x00000062,
+       #define Mono_Posix_UnixSocketProtocol_IPPROTO_ENCAP   Mono_Posix_UnixSocketProtocol_IPPROTO_ENCAP
+       Mono_Posix_UnixSocketProtocol_IPPROTO_ESP           = 0x00000032,
+       #define Mono_Posix_UnixSocketProtocol_IPPROTO_ESP     Mono_Posix_UnixSocketProtocol_IPPROTO_ESP
+       Mono_Posix_UnixSocketProtocol_IPPROTO_GRE           = 0x0000002f,
+       #define Mono_Posix_UnixSocketProtocol_IPPROTO_GRE     Mono_Posix_UnixSocketProtocol_IPPROTO_GRE
+       Mono_Posix_UnixSocketProtocol_IPPROTO_ICMP          = 0x00000001,
+       #define Mono_Posix_UnixSocketProtocol_IPPROTO_ICMP    Mono_Posix_UnixSocketProtocol_IPPROTO_ICMP
+       Mono_Posix_UnixSocketProtocol_IPPROTO_IDP           = 0x00000016,
+       #define Mono_Posix_UnixSocketProtocol_IPPROTO_IDP     Mono_Posix_UnixSocketProtocol_IPPROTO_IDP
+       Mono_Posix_UnixSocketProtocol_IPPROTO_IGMP          = 0x00000002,
+       #define Mono_Posix_UnixSocketProtocol_IPPROTO_IGMP    Mono_Posix_UnixSocketProtocol_IPPROTO_IGMP
+       Mono_Posix_UnixSocketProtocol_IPPROTO_IP            = 0x00000400,
+       #define Mono_Posix_UnixSocketProtocol_IPPROTO_IP      Mono_Posix_UnixSocketProtocol_IPPROTO_IP
+       Mono_Posix_UnixSocketProtocol_IPPROTO_IPIP          = 0x00000004,
+       #define Mono_Posix_UnixSocketProtocol_IPPROTO_IPIP    Mono_Posix_UnixSocketProtocol_IPPROTO_IPIP
+       Mono_Posix_UnixSocketProtocol_IPPROTO_IPV6          = 0x00000029,
+       #define Mono_Posix_UnixSocketProtocol_IPPROTO_IPV6    Mono_Posix_UnixSocketProtocol_IPPROTO_IPV6
+       Mono_Posix_UnixSocketProtocol_IPPROTO_MTP           = 0x0000005c,
+       #define Mono_Posix_UnixSocketProtocol_IPPROTO_MTP     Mono_Posix_UnixSocketProtocol_IPPROTO_MTP
+       Mono_Posix_UnixSocketProtocol_IPPROTO_PIM           = 0x00000067,
+       #define Mono_Posix_UnixSocketProtocol_IPPROTO_PIM     Mono_Posix_UnixSocketProtocol_IPPROTO_PIM
+       Mono_Posix_UnixSocketProtocol_IPPROTO_PUP           = 0x0000000c,
+       #define Mono_Posix_UnixSocketProtocol_IPPROTO_PUP     Mono_Posix_UnixSocketProtocol_IPPROTO_PUP
+       Mono_Posix_UnixSocketProtocol_IPPROTO_RAW           = 0x000000ff,
+       #define Mono_Posix_UnixSocketProtocol_IPPROTO_RAW     Mono_Posix_UnixSocketProtocol_IPPROTO_RAW
+       Mono_Posix_UnixSocketProtocol_IPPROTO_RSVP          = 0x0000002e,
+       #define Mono_Posix_UnixSocketProtocol_IPPROTO_RSVP    Mono_Posix_UnixSocketProtocol_IPPROTO_RSVP
+       Mono_Posix_UnixSocketProtocol_IPPROTO_SCTP          = 0x00000084,
+       #define Mono_Posix_UnixSocketProtocol_IPPROTO_SCTP    Mono_Posix_UnixSocketProtocol_IPPROTO_SCTP
+       Mono_Posix_UnixSocketProtocol_IPPROTO_TCP           = 0x00000006,
+       #define Mono_Posix_UnixSocketProtocol_IPPROTO_TCP     Mono_Posix_UnixSocketProtocol_IPPROTO_TCP
+       Mono_Posix_UnixSocketProtocol_IPPROTO_TP            = 0x0000001d,
+       #define Mono_Posix_UnixSocketProtocol_IPPROTO_TP      Mono_Posix_UnixSocketProtocol_IPPROTO_TP
+       Mono_Posix_UnixSocketProtocol_IPPROTO_UDP           = 0x00000011,
+       #define Mono_Posix_UnixSocketProtocol_IPPROTO_UDP     Mono_Posix_UnixSocketProtocol_IPPROTO_UDP
+       Mono_Posix_UnixSocketProtocol_IPPROTO_UDPLITE       = 0x00000088,
+       #define Mono_Posix_UnixSocketProtocol_IPPROTO_UDPLITE Mono_Posix_UnixSocketProtocol_IPPROTO_UDPLITE
+       Mono_Posix_UnixSocketProtocol_SOL_SOCKET            = 0x00000800,
+       #define Mono_Posix_UnixSocketProtocol_SOL_SOCKET      Mono_Posix_UnixSocketProtocol_SOL_SOCKET
+};
+int Mono_Posix_FromUnixSocketProtocol (int x, int *r);
+int Mono_Posix_ToUnixSocketProtocol (int x, int *r);
+
+enum Mono_Posix_UnixSocketType {
+       Mono_Posix_UnixSocketType_SOCK_DCCP            = 0x00000006,
+       #define Mono_Posix_UnixSocketType_SOCK_DCCP      Mono_Posix_UnixSocketType_SOCK_DCCP
+       Mono_Posix_UnixSocketType_SOCK_DGRAM           = 0x00000002,
+       #define Mono_Posix_UnixSocketType_SOCK_DGRAM     Mono_Posix_UnixSocketType_SOCK_DGRAM
+       Mono_Posix_UnixSocketType_SOCK_PACKET          = 0x0000000a,
+       #define Mono_Posix_UnixSocketType_SOCK_PACKET    Mono_Posix_UnixSocketType_SOCK_PACKET
+       Mono_Posix_UnixSocketType_SOCK_RAW             = 0x00000003,
+       #define Mono_Posix_UnixSocketType_SOCK_RAW       Mono_Posix_UnixSocketType_SOCK_RAW
+       Mono_Posix_UnixSocketType_SOCK_RDM             = 0x00000004,
+       #define Mono_Posix_UnixSocketType_SOCK_RDM       Mono_Posix_UnixSocketType_SOCK_RDM
+       Mono_Posix_UnixSocketType_SOCK_SEQPACKET       = 0x00000005,
+       #define Mono_Posix_UnixSocketType_SOCK_SEQPACKET Mono_Posix_UnixSocketType_SOCK_SEQPACKET
+       Mono_Posix_UnixSocketType_SOCK_STREAM          = 0x00000001,
+       #define Mono_Posix_UnixSocketType_SOCK_STREAM    Mono_Posix_UnixSocketType_SOCK_STREAM
+};
+int Mono_Posix_FromUnixSocketType (int x, int *r);
+int Mono_Posix_ToUnixSocketType (int x, int *r);
+
 enum Mono_Posix_WaitOptions {
        Mono_Posix_WaitOptions_WNOHANG         = 0x00000001,
        #define Mono_Posix_WaitOptions_WNOHANG   Mono_Posix_WaitOptions_WNOHANG
@@ -1481,6 +1800,7 @@ int Mono_Posix_ToXattrFlags (int x, int *r);
 
 struct Mono_Posix_Flock;
 struct Mono_Posix_Iovec;
+struct Mono_Posix_Linger;
 struct Mono_Posix_Pollfd;
 struct Mono_Posix_Stat;
 struct Mono_Posix_Statvfs;
@@ -1501,6 +1821,7 @@ struct Mono_Unix_UnixSignal_SignalInfo;
 
 struct flock;
 struct iovec;
+struct linger;
 struct pollfd;
 struct timespec;
 struct timeval;
@@ -1542,6 +1863,17 @@ int
 Mono_Posix_ToIovec (struct iovec *from, struct Mono_Posix_Iovec* to);
 
 
+struct Mono_Posix_Linger {
+       int l_onoff;
+       int l_linger;
+};
+
+int
+Mono_Posix_FromLinger (struct Mono_Posix_Linger* from, struct linger *to);
+int
+Mono_Posix_ToLinger (struct linger *from, struct Mono_Posix_Linger* to);
+
+
 struct Mono_Posix_Pollfd {
        int   fd;
        short events;
@@ -1755,6 +2087,8 @@ int Mono_Posix_Syscall_endpwent (void);
 int Mono_Posix_Syscall_endusershell (void);
 int Mono_Posix_Syscall_fcntl (int fd, int cmd);
 int Mono_Posix_Syscall_fcntl_arg (int fd, int cmd, gint64 arg);
+int Mono_Posix_Syscall_fcntl_arg_int (int fd, int cmd, int arg);
+int Mono_Posix_Syscall_fcntl_arg_ptr (int fd, int cmd, void* ptr);
 int Mono_Posix_Syscall_fcntl_lock (int fd, int cmd, struct Mono_Posix_Flock* lock);
 int Mono_Posix_Syscall_fgetgrent (void* stream, struct Mono_Posix_Syscall__Group* grbuf);
 int Mono_Posix_Syscall_fgetpwent (void* stream, struct Mono_Posix_Syscall__Passwd* pwbuf);
@@ -1790,6 +2124,9 @@ int Mono_Posix_Syscall_getpwnam (const char* name, struct Mono_Posix_Syscall__Pa
 int Mono_Posix_Syscall_getpwnam_r (const char* name, struct Mono_Posix_Syscall__Passwd* pwbuf, void** pwbufp);
 int Mono_Posix_Syscall_getpwuid (unsigned int uid, struct Mono_Posix_Syscall__Passwd* passwd);
 int Mono_Posix_Syscall_getpwuid_r (unsigned int uid, struct Mono_Posix_Syscall__Passwd* pwbuf, void** pwbufp);
+int Mono_Posix_Syscall_getsockopt (int socket, int level, int option_name, void* option_value, gint64* option_len);
+int Mono_Posix_Syscall_getsockopt_linger (int socket, int level, int option_name, struct Mono_Posix_Linger* option_value);
+int Mono_Posix_Syscall_getsockopt_timeval (int socket, int level, int option_name, struct Mono_Posix_Timeval* option_value);
 int Mono_Posix_Syscall_gettimeofday (struct Mono_Posix_Timeval* tv, void* ignore);
 gint64 Mono_Posix_Syscall_getxattr (const char* path, const char* name, unsigned char* value, guint64 size);
 int Mono_Posix_Syscall_L_ctermid (void);
@@ -1833,10 +2170,12 @@ int Mono_Posix_Syscall_readdir_r (void* dirp, struct Mono_Posix_Syscall__Dirent*
 gint64 Mono_Posix_Syscall_readlink (const char* path, unsigned char* buf, guint64 bufsiz);
 gint64 Mono_Posix_Syscall_readlinkat (int dirfd, const char* pathname, unsigned char* buf, guint64 bufsiz);
 gint64 Mono_Posix_Syscall_readv (int fd, struct Mono_Posix_Iovec* iov, int iovcnt);
+gint64 Mono_Posix_Syscall_recv (int socket, void* buffer, guint64 length, int flags);
 int Mono_Posix_Syscall_remap_file_pages (void* start, guint64 size, int prot, gint64 pgoff, int flags);
 int Mono_Posix_Syscall_removexattr (const char* path, const char* name);
 int Mono_Posix_Syscall_rewinddir (void* dir);
 int Mono_Posix_Syscall_seekdir (void* dir, gint64 offset);
+gint64 Mono_Posix_Syscall_send (int socket, void* message, guint64 length, int flags);
 gint64 Mono_Posix_Syscall_sendfile (int out_fd, int in_fd, gint64* offset, guint64 count);
 int Mono_Posix_Syscall_setdomainname (const char* name, guint64 len);
 int Mono_Posix_Syscall_setfsent (void);
@@ -1845,9 +2184,13 @@ int Mono_Posix_Syscall_setgroups (guint64 size, unsigned int* list);
 int Mono_Posix_Syscall_sethostid (gint64 hostid);
 int Mono_Posix_Syscall_sethostname (const char* name, guint64 len);
 int Mono_Posix_Syscall_setpwent (void);
+int Mono_Posix_Syscall_setsockopt (int socket, int level, int option_name, void* option_value, gint64 option_len);
+int Mono_Posix_Syscall_setsockopt_linger (int socket, int level, int option_name, struct Mono_Posix_Linger* option_value);
+int Mono_Posix_Syscall_setsockopt_timeval (int socket, int level, int option_name, struct Mono_Posix_Timeval* option_value);
 int Mono_Posix_Syscall_settimeofday (struct Mono_Posix_Timeval* tv, struct Mono_Posix_Timezone* tz);
 int Mono_Posix_Syscall_setusershell (void);
 int Mono_Posix_Syscall_setxattr (const char* path, const char* name, unsigned char* value, guint64 size, int flags);
+int Mono_Posix_Syscall_socketpair (int domain, int type, int protocol, int* socket1, int* socket2);
 int Mono_Posix_Syscall_stat (const char* file_name, struct Mono_Posix_Stat* buf);
 int Mono_Posix_Syscall_statvfs (const char* path, struct Mono_Posix_Statvfs* buf);
 int Mono_Posix_Syscall_stime (gint64* t);
index aedff01b7f32d6f8ce7f2a570c0472afa6e48c6e..cb5d94131da010bec4af329b7495109199948641 100644 (file)
@@ -149,6 +149,13 @@ typedef gint64 suseconds_t;
                return ret; \
        }}G_STMT_END
 
+#define mph_have_uint_overflow(var) ((var) < 0 || (var) > UINT_MAX)
+
+#define mph_return_val_if_uint_overflow(var, ret) \
+       _mph_return_val_if_cb_(var, ret, mph_have_uint_overflow)
+
+#define mph_return_if_uint_overflow(var) mph_return_val_if_uint_overflow(var, -1)
+
 #define mph_have_long_overflow(var) ((var) > LONG_MAX || (var) < LONG_MIN)
 
 #define mph_return_val_if_long_overflow(var, ret) \
@@ -156,14 +163,14 @@ typedef gint64 suseconds_t;
 
 #define mph_return_if_long_overflow(var) mph_return_val_if_long_overflow(var, -1)
 
-#define mph_have_ulong_overflow(var) ((var) > ULONG_MAX)
+#define mph_have_ulong_overflow(var) (var) < 0 || ((var) > ULONG_MAX)
 
 #define mph_return_val_if_ulong_overflow(var, ret) \
        _mph_return_val_if_cb_(var, ret, mph_have_ulong_overflow)
 
 #define mph_return_if_ulong_overflow(var) mph_return_val_if_ulong_overflow(var, -1)
 
-#define mph_have_size_t_overflow(var) ((var) > MPH_SIZE_T_MAX)
+#define mph_have_size_t_overflow(var) ((var) < 0 || (var) > MPH_SIZE_T_MAX)
 
 #define mph_return_val_if_size_t_overflow(var, ret) \
        _mph_return_val_if_cb_(var, ret, mph_have_size_t_overflow)
@@ -185,6 +192,8 @@ typedef gint64 suseconds_t;
 
 #define mph_return_if_time_t_overflow(var) mph_return_if_long_overflow(var)
 
+#define mph_return_if_socklen_t_overflow(var) mph_return_if_uint_overflow(var)
+
 #define mph_return_if_val_in_list5(var,a,b,c,d,e) \
        do {                                                            \
                int v = (var);                                                \
diff --git a/support/sys-socket.c b/support/sys-socket.c
new file mode 100644 (file)
index 0000000..e6da720
--- /dev/null
@@ -0,0 +1,139 @@
+/*
+ * <sys/socket.h> wrapper functions.
+ *
+ * Authors:
+ *   Steffen Kiess (s-kiess@web.de)
+ *
+ * Copyright (C) 2015 Steffen Kiess
+ */
+
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <sys/un.h>
+
+#include <stddef.h>
+
+#include "map.h"
+#include "mph.h"
+
+G_BEGIN_DECLS
+
+int
+Mono_Posix_Syscall_socketpair (int domain, int type, int protocol, int* socket1, int* socket2)
+{
+       int filedes[2] = {-1, -1};
+       int r;
+
+       r = socketpair (domain, type, protocol, filedes);
+
+       *socket1 = filedes[0];
+       *socket2 = filedes[1];
+       return r;
+}
+
+int
+Mono_Posix_Syscall_getsockopt (int socket, int level, int option_name, void* option_value, gint64* option_len)
+{
+       socklen_t len;
+       int r;
+
+       mph_return_if_socklen_t_overflow (*option_len);
+
+       len = *option_len;
+
+       r = getsockopt (socket, level, option_name, option_value, &len);
+
+       *option_len = len;
+
+       return r;
+}
+
+int
+Mono_Posix_Syscall_getsockopt_timeval (int socket, int level, int option_name, struct Mono_Posix_Timeval* option_value)
+{
+       struct timeval tv;
+       int r;
+       socklen_t size;
+
+       size = sizeof (struct timeval);
+       r = getsockopt (socket, level, option_name, &tv, &size);
+
+       if (r != -1 && size == sizeof (struct timeval)) {
+               if (Mono_Posix_ToTimeval (&tv, option_value) != 0)
+                       return -1;
+       } else {
+               memset (option_value, 0, sizeof (struct Mono_Posix_Timeval));
+               if (r != -1)
+                       errno = EINVAL;
+       }
+
+       return r;
+}
+
+int
+Mono_Posix_Syscall_getsockopt_linger (int socket, int level, int option_name, struct Mono_Posix_Linger* option_value)
+{
+       struct linger ling;
+       int r;
+       socklen_t size;
+
+       size = sizeof (struct linger);
+       r = getsockopt (socket, level, option_name, &ling, &size);
+
+       if (r != -1 && size == sizeof (struct linger)) {
+               if (Mono_Posix_ToLinger (&ling, option_value) != 0)
+                       return -1;
+       } else {
+               memset (option_value, 0, sizeof (struct Mono_Posix_Linger));
+               if (r != -1)
+                       errno = EINVAL;
+       }
+
+       return r;
+}
+
+int
+Mono_Posix_Syscall_setsockopt (int socket, int level, int option_name, void* option_value, gint64 option_len)
+{
+       mph_return_if_socklen_t_overflow (option_len);
+
+       return setsockopt (socket, level, option_name, option_value, option_len);
+}
+
+int
+Mono_Posix_Syscall_setsockopt_timeval (int socket, int level, int option_name, struct Mono_Posix_Timeval* option_value)
+{
+       struct timeval tv;
+
+       if (Mono_Posix_FromTimeval (option_value, &tv) != 0)
+               return -1;
+
+       return setsockopt (socket, level, option_name, &tv, sizeof (struct timeval));
+}
+
+int
+Mono_Posix_Syscall_setsockopt_linger (int socket, int level, int option_name, struct Mono_Posix_Linger* option_value)
+{
+       struct linger ling;
+
+       if (Mono_Posix_FromLinger (option_value, &ling) != 0)
+               return -1;
+
+       return setsockopt (socket, level, option_name, &ling, sizeof (struct linger));
+}
+
+gint64
+Mono_Posix_Syscall_recv (int socket, void* message, guint64 length, int flags)
+{
+       mph_return_if_size_t_overflow (length);
+
+       return recv (socket, message, length, flags);
+}
+
+gint64
+Mono_Posix_Syscall_send (int socket, void* message, guint64 length, int flags)
+{
+       mph_return_if_size_t_overflow (length);
+
+       return send (socket, message, length, flags);
+}