require 'natalie/inline'

__inline__ <<END
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
#include <sys/socket.h>
END

class Socket < BasicSocket
  module Constants
    __constant__('AF_APPLETALK', 'unsigned short')
    __constant__('AF_AX25', 'unsigned short')
    __constant__('AF_INET', 'unsigned short')
    __constant__('AF_INET6', 'unsigned short')
    __constant__('AF_IPX', 'unsigned short')
    __constant__('AF_ISDN', 'unsigned short')
    __constant__('AF_LOCAL', 'unsigned short')
    __constant__('AF_MAX', 'unsigned short')
    __constant__('AF_PACKET', 'unsigned short')
    __constant__('AF_ROUTE', 'unsigned short')
    __constant__('AF_SNA', 'unsigned short')
    __constant__('AF_UNIX', 'unsigned short')
    __constant__('AF_UNSPEC', 'unsigned short')
    __constant__('AI_ADDRCONFIG', 'unsigned short')
    __constant__('AI_ALL', 'unsigned short')
    __constant__('AI_CANONNAME', 'unsigned short')
    __constant__('AI_NUMERICHOST', 'unsigned short')
    __constant__('AI_NUMERICSERV', 'unsigned short')
    __constant__('AI_PASSIVE', 'unsigned short')
    __constant__('AI_V4MAPPED', 'unsigned short')
    __constant__('EAI_ADDRFAMILY', 'unsigned short')
    __constant__('EAI_AGAIN', 'unsigned short')
    __constant__('EAI_BADFLAGS', 'unsigned short')
    __constant__('EAI_FAIL', 'unsigned short')
    __constant__('EAI_FAMILY', 'unsigned short')
    __constant__('EAI_MEMORY', 'unsigned short')
    __constant__('EAI_NODATA', 'unsigned short')
    __constant__('EAI_NONAME', 'unsigned short')
    __constant__('EAI_OVERFLOW', 'unsigned short')
    __constant__('EAI_SERVICE', 'unsigned short')
    __constant__('EAI_SOCKTYPE', 'unsigned short')
    __constant__('EAI_SYSTEM', 'unsigned short')
    __constant__('IFF_ALLMULTI', 'unsigned short')
    __constant__('IFF_AUTOMEDIA', 'unsigned short')
    __constant__('IFF_BROADCAST', 'unsigned short')
    __constant__('IFF_DEBUG', 'unsigned short')
    __constant__('IFF_DYNAMIC', 'unsigned short')
    __constant__('IFF_LOOPBACK', 'unsigned short')
    __constant__('IFF_MASTER', 'unsigned short')
    __constant__('IFF_MULTICAST', 'unsigned short')
    __constant__('IFF_NOARP', 'unsigned short')
    __constant__('IFF_NOTRAILERS', 'unsigned short')
    __constant__('IFF_POINTOPOINT', 'unsigned short')
    __constant__('IFF_PORTSEL', 'unsigned short')
    __constant__('IFF_PROMISC', 'unsigned short')
    __constant__('IFF_RUNNING', 'unsigned short')
    __constant__('IFF_SLAVE', 'unsigned short')
    __constant__('IFF_UP', 'unsigned short')
    __constant__('IFNAMSIZ', 'unsigned short')
    __constant__('IF_NAMESIZE', 'unsigned short')
    __constant__('INADDR_ALLHOSTS_GROUP', 'unsigned short')
    __constant__('INADDR_ANY', 'unsigned short')
    __constant__('INADDR_BROADCAST', 'unsigned short')
    __constant__('INADDR_LOOPBACK', 'unsigned short')
    __constant__('INADDR_MAX_LOCAL_GROUP', 'unsigned short')
    __constant__('INADDR_NONE', 'unsigned short')
    __constant__('INADDR_UNSPEC_GROUP', 'unsigned short')
    __constant__('INET6_ADDRSTRLEN', 'unsigned short')
    __constant__('INET_ADDRSTRLEN', 'unsigned short')
    __constant__('IPPORT_RESERVED', 'unsigned short')
    __constant__('IPPORT_USERRESERVED', 'unsigned short')
    __constant__('IPPROTO_AH', 'unsigned short')
    __constant__('IPPROTO_DSTOPTS', 'unsigned short')
    __constant__('IPPROTO_EGP', 'unsigned short')
    __constant__('IPPROTO_ESP', 'unsigned short')
    __constant__('IPPROTO_FRAGMENT', 'unsigned short')
    __constant__('IPPROTO_HOPOPTS', 'unsigned short')
    __constant__('IPPROTO_ICMP', 'unsigned short')
    __constant__('IPPROTO_ICMPV6', 'unsigned short')
    __constant__('IPPROTO_IDP', 'unsigned short')
    __constant__('IPPROTO_IGMP', 'unsigned short')
    __constant__('IPPROTO_IP', 'unsigned short')
    __constant__('IPPROTO_IPV6', 'unsigned short')
    __constant__('IPPROTO_NONE', 'unsigned short')
    __constant__('IPPROTO_PUP', 'unsigned short')
    __constant__('IPPROTO_RAW', 'unsigned short')
    __constant__('IPPROTO_ROUTING', 'unsigned short')
    __constant__('IPPROTO_TCP', 'unsigned short')
    __constant__('IPPROTO_TP', 'unsigned short')
    __constant__('IPPROTO_UDP', 'unsigned short')
    __constant__('IPV6_CHECKSUM', 'unsigned short')
    __constant__('IPV6_DONTFRAG', 'unsigned short')
    __constant__('IPV6_DSTOPTS', 'unsigned short')
    __constant__('IPV6_HOPLIMIT', 'unsigned short')
    __constant__('IPV6_HOPOPTS', 'unsigned short')
    __constant__('IPV6_JOIN_GROUP', 'unsigned short')
    __constant__('IPV6_LEAVE_GROUP', 'unsigned short')
    __constant__('IPV6_MULTICAST_HOPS', 'unsigned short')
    __constant__('IPV6_MULTICAST_IF', 'unsigned short')
    __constant__('IPV6_MULTICAST_LOOP', 'unsigned short')
    __constant__('IPV6_NEXTHOP', 'unsigned short')
    __constant__('IPV6_PATHMTU', 'unsigned short')
    __constant__('IPV6_PKTINFO', 'unsigned short')
    __constant__('IPV6_RECVDSTOPTS', 'unsigned short')
    __constant__('IPV6_RECVHOPLIMIT', 'unsigned short')
    __constant__('IPV6_RECVHOPOPTS', 'unsigned short')
    __constant__('IPV6_RECVPATHMTU', 'unsigned short')
    __constant__('IPV6_RECVPKTINFO', 'unsigned short')
    __constant__('IPV6_RECVRTHDR', 'unsigned short')
    __constant__('IPV6_RECVTCLASS', 'unsigned short')
    __constant__('IPV6_RTHDR', 'unsigned short')
    __constant__('IPV6_RTHDRDSTOPTS', 'unsigned short')
    __constant__('IPV6_RTHDR_TYPE_0', 'unsigned short')
    __constant__('IPV6_TCLASS', 'unsigned short')
    __constant__('IPV6_UNICAST_HOPS', 'unsigned short')
    __constant__('IPV6_V6ONLY', 'unsigned short')
    __constant__('IP_ADD_MEMBERSHIP', 'unsigned short')
    __constant__('IP_ADD_SOURCE_MEMBERSHIP', 'unsigned short')
    __constant__('IP_BLOCK_SOURCE', 'unsigned short')
    __constant__('IP_DEFAULT_MULTICAST_LOOP', 'unsigned short')
    __constant__('IP_DEFAULT_MULTICAST_TTL', 'unsigned short')
    __constant__('IP_DROP_MEMBERSHIP', 'unsigned short')
    __constant__('IP_DROP_SOURCE_MEMBERSHIP', 'unsigned short')
    __constant__('IP_FREEBIND', 'unsigned short')
    __constant__('IP_HDRINCL', 'unsigned short')
    __constant__('IP_IPSEC_POLICY', 'unsigned short')
    __constant__('IP_MAX_MEMBERSHIPS', 'unsigned short')
    __constant__('IP_MINTTL', 'unsigned short')
    __constant__('IP_MSFILTER', 'unsigned short')
    __constant__('IP_MTU', 'unsigned short')
    __constant__('IP_MTU_DISCOVER', 'unsigned short')
    __constant__('IP_MULTICAST_IF', 'unsigned short')
    __constant__('IP_MULTICAST_LOOP', 'unsigned short')
    __constant__('IP_MULTICAST_TTL', 'unsigned short')
    __constant__('IP_OPTIONS', 'unsigned short')
    __constant__('IP_PASSSEC', 'unsigned short')
    __constant__('IP_PKTINFO', 'unsigned short')
    __constant__('IP_PKTOPTIONS', 'unsigned short')
    __constant__('IP_PMTUDISC_DO', 'unsigned short')
    __constant__('IP_PMTUDISC_DONT', 'unsigned short')
    __constant__('IP_PMTUDISC_WANT', 'unsigned short')
    __constant__('IP_RECVERR', 'unsigned short')
    __constant__('IP_RECVOPTS', 'unsigned short')
    __constant__('IP_RECVRETOPTS', 'unsigned short')
    __constant__('IP_RECVTOS', 'unsigned short')
    __constant__('IP_RECVTTL', 'unsigned short')
    __constant__('IP_RETOPTS', 'unsigned short')
    __constant__('IP_ROUTER_ALERT', 'unsigned short')
    __constant__('IP_TOS', 'unsigned short')
    __constant__('IP_TRANSPARENT', 'unsigned short')
    __constant__('IP_TTL', 'unsigned short')
    __constant__('IP_UNBLOCK_SOURCE', 'unsigned short')
    __constant__('IP_XFRM_POLICY', 'unsigned short')
    __constant__('MCAST_BLOCK_SOURCE', 'unsigned short')
    __constant__('MCAST_EXCLUDE', 'unsigned short')
    __constant__('MCAST_INCLUDE', 'unsigned short')
    __constant__('MCAST_JOIN_GROUP', 'unsigned short')
    __constant__('MCAST_JOIN_SOURCE_GROUP', 'unsigned short')
    __constant__('MCAST_LEAVE_GROUP', 'unsigned short')
    __constant__('MCAST_LEAVE_SOURCE_GROUP', 'unsigned short')
    __constant__('MCAST_MSFILTER', 'unsigned short')
    __constant__('MCAST_UNBLOCK_SOURCE', 'unsigned short')
    __constant__('MSG_CONFIRM', 'unsigned short')
    __constant__('MSG_CTRUNC', 'unsigned short')
    __constant__('MSG_DONTROUTE', 'unsigned short')
    __constant__('MSG_DONTWAIT', 'unsigned short')
    __constant__('MSG_EOR', 'unsigned short')
    __constant__('MSG_ERRQUEUE', 'unsigned short')
    __constant__('MSG_FASTOPEN', 'unsigned short')
    __constant__('MSG_FIN', 'unsigned short')
    __constant__('MSG_MORE', 'unsigned short')
    __constant__('MSG_NOSIGNAL', 'unsigned short')
    __constant__('MSG_OOB', 'unsigned short')
    __constant__('MSG_PEEK', 'unsigned short')
    __constant__('MSG_PROXY', 'unsigned short')
    __constant__('MSG_RST', 'unsigned short')
    __constant__('MSG_SYN', 'unsigned short')
    __constant__('MSG_TRUNC', 'unsigned short')
    __constant__('MSG_WAITALL', 'unsigned short')
    __constant__('NI_DGRAM', 'unsigned short')
    __constant__('NI_MAXHOST', 'unsigned short')
    __constant__('NI_MAXSERV', 'unsigned short')
    __constant__('NI_NAMEREQD', 'unsigned short')
    __constant__('NI_NOFQDN', 'unsigned short')
    __constant__('NI_NUMERICHOST', 'unsigned short')
    __constant__('NI_NUMERICSERV', 'unsigned short')
    __constant__('PF_APPLETALK', 'unsigned short')
    __constant__('PF_AX25', 'unsigned short')
    __constant__('PF_INET', 'unsigned short')
    __constant__('PF_INET6', 'unsigned short')
    __constant__('PF_IPX', 'unsigned short')
    __constant__('PF_ISDN', 'unsigned short')
    __constant__('PF_KEY', 'unsigned short')
    __constant__('PF_LOCAL', 'unsigned short')
    __constant__('PF_MAX', 'unsigned short')
    __constant__('PF_PACKET', 'unsigned short')
    __constant__('PF_ROUTE', 'unsigned short')
    __constant__('PF_SNA', 'unsigned short')
    __constant__('PF_UNIX', 'unsigned short')
    __constant__('PF_UNSPEC', 'unsigned short')
    __constant__('SCM_CREDENTIALS', 'unsigned short')
    __constant__('SCM_RIGHTS', 'unsigned short')
    __constant__('SCM_TIMESTAMP', 'unsigned short')
    __constant__('SCM_TIMESTAMPING', 'unsigned short')
    __constant__('SCM_TIMESTAMPNS', 'unsigned short')
    __constant__('SCM_WIFI_STATUS', 'unsigned short')
    __constant__('SHUT_RD', 'unsigned short')
    __constant__('SHUT_RDWR', 'unsigned short')
    __constant__('SHUT_WR', 'unsigned short')
    __constant__('SOCK_DGRAM', 'unsigned short')
    __constant__('SOCK_PACKET', 'unsigned short')
    __constant__('SOCK_RAW', 'unsigned short')
    __constant__('SOCK_RDM', 'unsigned short')
    __constant__('SOCK_SEQPACKET', 'unsigned short')
    __constant__('SOCK_STREAM', 'unsigned short')
    __constant__('SOL_IP', 'unsigned short')
    __constant__('SOL_SOCKET', 'unsigned short')
    __constant__('SOL_TCP', 'unsigned short')
    __constant__('SOL_UDP', 'unsigned short')
    __constant__('SOMAXCONN', 'unsigned short')
    __constant__('SO_ACCEPTCONN', 'unsigned short')
    __constant__('SO_ATTACH_FILTER', 'unsigned short')
    __constant__('SO_BINDTODEVICE', 'unsigned short')
    __constant__('SO_BPF_EXTENSIONS', 'unsigned short')
    __constant__('SO_BROADCAST', 'unsigned short')
    __constant__('SO_BUSY_POLL', 'unsigned short')
    __constant__('SO_DEBUG', 'unsigned short')
    __constant__('SO_DETACH_FILTER', 'unsigned short')
    __constant__('SO_DOMAIN', 'unsigned short')
    __constant__('SO_DONTROUTE', 'unsigned short')
    __constant__('SO_ERROR', 'unsigned short')
    __constant__('SO_GET_FILTER', 'unsigned short')
    __constant__('SO_KEEPALIVE', 'unsigned short')
    __constant__('SO_LINGER', 'unsigned short')
    __constant__('SO_LOCK_FILTER', 'unsigned short')
    __constant__('SO_MARK', 'unsigned short')
    __constant__('SO_MAX_PACING_RATE', 'unsigned short')
    __constant__('SO_NOFCS', 'unsigned short')
    __constant__('SO_NO_CHECK', 'unsigned short')
    __constant__('SO_OOBINLINE', 'unsigned short')
    __constant__('SO_PASSCRED', 'unsigned short')
    __constant__('SO_PASSSEC', 'unsigned short')
    __constant__('SO_PEEK_OFF', 'unsigned short')
    __constant__('SO_PEERCRED', 'unsigned short')
    __constant__('SO_PEERNAME', 'unsigned short')
    __constant__('SO_PEERSEC', 'unsigned short')
    __constant__('SO_PRIORITY', 'unsigned short')
    __constant__('SO_PROTOCOL', 'unsigned short')
    __constant__('SO_RCVBUF', 'unsigned short')
    __constant__('SO_RCVBUFFORCE', 'unsigned short')
    __constant__('SO_RCVLOWAT', 'unsigned short')
    __constant__('SO_RCVTIMEO', 'unsigned short')
    __constant__('SO_REUSEADDR', 'unsigned short')
    __constant__('SO_REUSEPORT', 'unsigned short')
    __constant__('SO_RXQ_OVFL', 'unsigned short')
    __constant__('SO_SECURITY_AUTHENTICATION', 'unsigned short')
    __constant__('SO_SECURITY_ENCRYPTION_NETWORK', 'unsigned short')
    __constant__('SO_SECURITY_ENCRYPTION_TRANSPORT', 'unsigned short')
    __constant__('SO_SELECT_ERR_QUEUE', 'unsigned short')
    __constant__('SO_SNDBUF', 'unsigned short')
    __constant__('SO_SNDBUFFORCE', 'unsigned short')
    __constant__('SO_SNDLOWAT', 'unsigned short')
    __constant__('SO_SNDTIMEO', 'unsigned short')
    __constant__('SO_TIMESTAMP', 'unsigned short')
    __constant__('SO_TIMESTAMPING', 'unsigned short')
    __constant__('SO_TIMESTAMPNS', 'unsigned short')
    __constant__('SO_TYPE', 'unsigned short')
    __constant__('SO_WIFI_STATUS', 'unsigned short')
    __constant__('TCP_CONGESTION', 'unsigned short')
    __constant__('TCP_COOKIE_TRANSACTIONS', 'unsigned short')
    __constant__('TCP_CORK', 'unsigned short')
    __constant__('TCP_DEFER_ACCEPT', 'unsigned short')
    __constant__('TCP_FASTOPEN', 'unsigned short')
    __constant__('TCP_INFO', 'unsigned short')
    __constant__('TCP_KEEPCNT', 'unsigned short')
    __constant__('TCP_KEEPIDLE', 'unsigned short')
    __constant__('TCP_KEEPINTVL', 'unsigned short')
    __constant__('TCP_LINGER2', 'unsigned short')
    __constant__('TCP_MAXSEG', 'unsigned short')
    __constant__('TCP_MD5SIG', 'unsigned short')
    __constant__('TCP_NODELAY', 'unsigned short')
    __constant__('TCP_QUEUE_SEQ', 'unsigned short')
    __constant__('TCP_QUICKACK', 'unsigned short')
    __constant__('TCP_REPAIR', 'unsigned short')
    __constant__('TCP_REPAIR_OPTIONS', 'unsigned short')
    __constant__('TCP_REPAIR_QUEUE', 'unsigned short')
    __constant__('TCP_SYNCNT', 'unsigned short')
    __constant__('TCP_THIN_DUPACK', 'unsigned short')
    __constant__('TCP_THIN_LINEAR_TIMEOUTS', 'unsigned short')
    __constant__('TCP_TIMESTAMP', 'unsigned short')
    __constant__('TCP_USER_TIMEOUT', 'unsigned short')
    __constant__('TCP_WINDOW_CLAMP', 'unsigned short')
    __constant__('UDP_CORK', 'unsigned short')
  end
end
