---@meta posix.sys.socket

---@class posix_sockaddr*
---@field family integer
---@field port? integer
---@field addr? string
---@field socktype? integer
---@field canonname? string
---@field protocol? integer
---@field path? string
---@field pid? integer
---@field groups? integer
---@field ifindex? integer
---@field flowinfo? integer
---@field scope_id? integer

---@class posix_addrinfo*
---@field family? integer
---@field flags? integer
---@field socktype? integer
---@field protocol? integer
---@field addr? posix_sockaddr*
---@field canonname? string

---@class posix_linger*
---@field l_linger integer
---@field l_onoff integer

---@class posix_sys_socket*
---@field version string
---@field SOMAXCONN integer
---@field AF_UNSPEC integer
---@field AF_INET integer
---@field AF_INET6 integer
---@field AF_UNIX integer
---@field AF_NETLINK integer
---@field AF_PACKET integer
---@field SOL_SOCKET integer
---@field IPPROTO_TCP integer
---@field IPPROTO_UDP integer
---@field IPPROTO_IP integer
---@field IPPROTO_IPV6 integer
---@field IPPROTO_ICMP integer
---@field SOCK_STREAM integer
---@field SOCK_DGRAM integer
---@field SOCK_RAW integer
---@field SHUT_RD integer
---@field SHUT_WR integer
---@field SHUT_RDWR integer
---@field SO_ACCEPTCONN integer
---@field SO_BROADCAST integer
---@field SO_LINGER integer
---@field SO_RCVTIMEO integer
---@field SO_SNDTIMEO integer
---@field SO_BINDTODEVICE integer
---@field SO_DEBUG integer
---@field SO_DONTROUTE integer
---@field SO_ERROR integer
---@field SO_KEEPALIVE integer
---@field SO_OOBINLINE integer
---@field SO_RCVBUF integer
---@field SO_RCVLOWAT integer
---@field SO_REUSEADDR integer
---@field SO_SNDBUF integer
---@field SO_SNDLOWAT integer
---@field SO_TYPE integer
---@field TCP_NODELAY integer
---@field AI_ADDRCONFIG integer
---@field AI_ALL integer
---@field AI_CANONNAME integer
---@field AI_NUMERICHOST integer
---@field AI_NUMERICSERV integer
---@field AI_PASSIVE integer
---@field AI_V4MAPPED integer
---@field IPV6_JOIN_GROUP integer
---@field IPV6_LEAVE_GROUP integer
---@field IPV6_MULTICAST_HOPS integer
---@field IPV6_MULTICAST_IF integer
---@field IPV6_MULTICAST_LOOP integer
---@field IPV6_UNICAST_HOPS integer
---@field IPV6_V6ONLY integer
---@field NETLINK_ROUTE integer
---@field NETLINK_UNUSED integer
---@field NETLINK_USERSOCK integer
---@field NETLINK_FIREWALL integer
---@field NETLINK_NFLOG integer
---@field NETLINK_XFRM integer
---@field NETLINK_SELINUX integer
---@field NETLINK_ISCSI integer
---@field NETLINK_AUDIT integer
---@field NETLINK_FIB_LOOKUP integer
---@field NETLINK_CONNECTOR integer
---@field NETLINK_NETFILTER integer
---@field NETLINK_IP6_FW integer
---@field NETLINK_DNRTMSG integer
---@field NETLINK_KOBJECT_UEVENT integer
---@field NETLINK_GENERIC integer
---@field NETLINK_SCSITRANSPORT integer
---@field NETLINK_ECRYPTFS integer
---@type posix_sys_socket*
local M = {}

---@param domain integer
---@param type integer
---@param protocol integer
---@return integer? fd
---@return string? errMsg
---@return integer? errno
function M.socket(domain, type, protocol) end

---@param domain integer
---@param type integer
---@param protocol integer
---@return integer? fd1
---@return integer? fd2
---@return string? errMsg
---@return integer? errno
function M.socketpair(domain, type, protocol) end

---@param host? string
---@param service? string|integer
---@param hints? posix_addrinfo*
---@return posix_addrinfo[]? result
---@return string? errMsg
---@return integer? errno
function M.getaddrinfo(host, service, hints) end

---@param fd integer
---@param addr posix_sockaddr*
---@return integer? ok
---@return string? errMsg
---@return integer? errno
function M.connect(fd, addr) end

---@param fd integer
---@param addr posix_sockaddr*
---@return integer? ok
---@return string? errMsg
---@return integer? errno
function M.bind(fd, addr) end

---@param fd integer
---@param backlog integer
---@return integer? ok
---@return string? errMsg
---@return integer? errno
function M.listen(fd, backlog) end

---@param fd integer
---@return integer? clientfd
---@return posix_sockaddr*? addr
---@return string? errMsg
---@return integer? errno
function M.accept(fd) end

---@param fd integer
---@param count integer
---@param flags? integer
---@return string? data
---@return string? errMsg
---@return integer? errno
function M.recv(fd, count, flags) end

---@param fd integer
---@param count integer
---@param flags? integer
---@return string? data
---@return posix_sockaddr*? addr
---@return string? errMsg
---@return integer? errno
function M.recvfrom(fd, count, flags) end

---@param fd integer
---@param data string
---@param flags? integer
---@return integer? bytes
---@return string? errMsg
---@return integer? errno
function M.send(fd, data, flags) end

---@param fd integer
---@param data string
---@param flags integer
---@param addr posix_sockaddr*
---@return integer? bytes
---@return string? errMsg
---@return integer? errno
function M.sendto(fd, data, flags, addr) end

---@param fd integer
---@param how integer
---@return integer? ok
---@return string? errMsg
---@return integer? errno
function M.shutdown(fd, how) end

---@param fd integer
---@param level integer
---@param option integer
---@param value any
---@return integer? ok
---@return string? errMsg
---@return integer? errno
function M.setsockopt(fd, level, option, value) end

---@param fd integer
---@param level integer
---@param option integer
---@return any value
---@return string? errMsg
---@return integer? errno
function M.getsockopt(fd, level, option) end

---@param fd integer
---@return posix_sockaddr*? addr
---@return string? errMsg
---@return integer? errno
function M.getsockname(fd) end

---@param fd integer
---@return posix_sockaddr*? addr
---@return string? errMsg
---@return integer? errno
function M.getpeername(fd) end

---@param ifname string
---@return integer? index
---@return string? errMsg
---@return integer? errno
function M.if_nametoindex(ifname) end

return M
