+# Level on which to set options
+extern class NativeSocketOptLevels `{ int `}
+
+ # Dummy for IP (As defined in C)
+ new ip `{ return IPPROTO_IP;`}
+
+ # Control message protocol
+ new icmp `{ return IPPROTO_ICMP;`}
+
+ # Use TCP
+ new tcp `{ return IPPROTO_TCP; `}
+
+ # Socket level options
+ new socket `{ return SOL_SOCKET; `}
+end
+
+# Options for socket, use with setsockopt
+extern class NativeSocketOptNames `{ int `}
+
+ # Enables debugging information
+ new debug `{ return SO_DEBUG; `}
+
+ # Authorizes the broadcasting of messages
+ new broadcast `{ return SO_BROADCAST; `}
+
+ # Authorizes the reuse of the local address
+ new reuseaddr `{ return SO_REUSEADDR; `}
+
+ # Authorizes the use of keep-alive packets in a connection
+ new keepalive `{ return SO_KEEPALIVE; `}
+
+ # Disable the Nagle algorithm and send data as soon as possible, in smaller packets
+ new tcp_nodelay `{ return TCP_NODELAY; `}
+end
+
+# Used for the poll function of a socket, mix several Poll values to check for events on more than one type of event
+extern class NativeSocketPollValues `{ int `}
+
+ # Data other than high-priority data may be read without blocking.
+ new pollin `{ return POLLIN; `}
+
+ # Normal data may be read without blocking.
+ new pollrdnorm `{ return POLLRDNORM; `}
+
+ # Priority data may be read without blocking.
+ new pollrdband `{ return POLLRDBAND; `}
+
+ # High-priority data may be read without blocking.
+ new pollpri `{ return POLLPRI; `}
+
+ # Normal data may be written without blocking.
+ new pollout `{ return POLLOUT; `}
+
+ # Equivalent to POLLOUT
+ new pollwrnorm `{ return POLLWRNORM; `}
+
+ # Priority data may be written.
+ new pollwrband `{ return POLLWRBAND; `}
+
+ # An error has occurred on the device or stream.
+ #
+ # This flag is only valid in the revents bitmask; it shall be ignored in the events member.
+ new pollerr `{ return POLLERR; `}
+
+ # The device has been disconnected.
+ #
+ # This event and POLLOUT are mutually-exclusive; a stream can never be
+ # writable if a hangup has occurred. However, this event and POLLIN,
+ # POLLRDNORM, POLLRDBAND, or POLLPRI are not mutually-exclusive.
+ #
+ # This flag is only valid in the revents bitmask; it shall be ignored in the events member.
+ new pollhup `{ return POLLHUP; `}
+
+ # The specified fd value is invalid.
+ #
+ # This flag is only valid in the revents member; it shall ignored in the events member.
+ new pollnval `{ return POLLNVAL; `}
+
+ # Combines two NativeSocketPollValues
+ private fun +(other: NativeSocketPollValues): NativeSocketPollValues `{
+ return self | other;
+ `}
+end
+
+redef class Sys
+ # Get network host entry
+ fun gethostbyname(name: NativeString): NativeSocketHostent `{
+ return gethostbyname(name);
+ `}
+
+ # Last error raised by `gethostbyname`
+ fun h_errno: HErrno `{ return h_errno; `}
+end
+
+# Error code of `Sys::h_errno`
+extern class HErrno `{ int `}
+ # The specified host is unknown
+ fun host_not_found: Bool `{ return self == HOST_NOT_FOUND; `}
+
+ # The requested name is valid but does not have an IP address
+ #
+ # Same as `no_data`.
+ fun no_address: Bool `{ return self == NO_ADDRESS; `}
+
+ # The requested name is valid byt does not have an IP address
+ #
+ # Same as `no_address`.
+ fun no_data: Bool `{ return self == NO_DATA; `}
+
+ # A nonrecoverable name server error occurred
+ fun no_recovery: Bool `{ return self == NO_RECOVERY; `}
+
+ # A temporary error occurred on an authoritative name server, try again later
+ fun try_again: Bool `{ return self == TRY_AGAIN; `}
+
+ redef fun to_s
+ do
+ if host_not_found then
+ return "The specified host is unknown"
+ else if no_address then
+ return "The requested name is valid but does not have an IP address"
+ else if no_recovery then
+ return "A nonrecoverable name server error occurred"
+ else if try_again then
+ return "A temporary error occurred on an authoritative name server, try again later"
+ else
+ # This may happen if another call was made to `gethostbyname`
+ # before we fetch the error code.
+ return "Unknown error on `gethostbyname`"
+ end
+ end
+end