Skip to content

windows winsock

IsaacShelton edited this page Nov 13, 2022 · 5 revisions

windows/winsock

windows/winsock.adept contains definitions from the Windows header <winsock2.h>.

The winsock2 library libws2_32.a is automatically linked against and should not be manually linked.

Structures

struct WSADATA (
    wVersion       short,
    wHighVersion   short,
    iMaxSockets    ushort,
    iMaxUdpDg      ushort,
    lpVendorInfo   *ubyte,
    szDescription  257 ubyte,
    szSystemStatus 129 ubyte
)

// NOTE: 'ai_next' is of type 'ptr' because the compiler can't handle self-referencing pointer '*addrinfo'
// Isaac Shelton - Nov 5th 2019

struct addrinfo (
    ai_flags int,
    ai_family int,
    ai_socktype int,
    ai_protocol int,
    ai_addrlen usize,
    ai_canonname *ubyte,
    ai_addr *sockaddr,
    ai_next ptr
)

struct sockaddr (sa_family ushort, sa_data 14 ubyte)

struct sockaddr_in (sin_family short, sin_port ushort, sin_addr in_addr, sin_zero 8 ubyte)

struct in_addr (s_addr uint)

struct in_addr_uint_version (S_addr uint)

struct in_addr_words_version (s_w1, s_w2 ushort)

struct in_addr_bytes_version (s_b1, s_b2, s_b3, s_b4 ubyte)

struct hostent (h_name *ubyte, h_aliases **ubyte, h_addrtype short, h_length short, h_addr_list **ubyte)

struct netent (n_name *ubyte, n_aliases **ubyte, n_addrtype short, n_net uint)

struct servent (s_name *ubyte, s_aliases **ubyte, s_proto *ubyte, s_port short)

struct protoent (p_name *ubyte, p_aliases **ubyte, p_proto short)

struct timeval (tv_sec int, tv_usec int)

struct fd_set (fd_count uint, fd_array 64 SOCKET)

Type Aliases

alias SOCKET = *uint
alias socklen_t = int

Functions

  • func IN_CLASSA(i uint) bool
  • func IN_CLASSB(i uint) bool
  • func IN_CLASSC(i uint) bool
  • foreign WSAStartup(ushort, *WSADATA) int
  • foreign getaddrinfo(*ubyte, *ubyte, *addrinfo, **addrinfo) int
  • foreign WSACleanup() void
  • foreign socket(int, int, int) SOCKET
  • foreign freeaddrinfo(*addrinfo) void
  • foreign bind(SOCKET, *sockaddr, int) int
  • foreign closesocket(SOCKET) int
  • foreign listen(SOCKET, int) int
  • foreign accept(SOCKET, *sockaddr, *int) SOCKET
  • foreign recv(SOCKET, ptr, int, int) int
  • foreign connect(SOCKET, *sockaddr, int) int
  • foreign send(SOCKET, ptr, int, int) int
  • foreign ioctlsocket(SOCKET, long, *uint) int
  • foreign getpeername(SOCKET, *sockaddr, *int) int
  • foreign getsockname(SOCKET, *sockaddr, *int) int;
  • foreign getsockopt(SOCKET, int, int, ptr, *int) int
  • foreign inet_addr(*ubyte) uint
  • foreign inet_ntoa(in_addr) *ubyte
  • foreign recvfrom(SOCKET, ptr, int, int, *sockaddr, *int) int
  • foreign sendto(SOCKET, ptr, int, int, *sockaddr, int) int
  • foreign setsockopt(SOCKET, int, int, ptr, socklen_t) int
  • foreign shutdown(SOCKET, int) int
  • foreign select(int, *fd_set, *fd_set, *fd_set, *timeval) int
  • foreign gethostbyaddr(*ubyte, int, int) *hostent
  • foreign gethostbyname(*ubyte) *hostent
  • foreign gethostname(*ubyte, int) int
  • foreign getservbyport(int, *ubyte) *servent
  • foreign getservbyname(*ubyte, *ubyte) *servent
  • foreign getprotobynumber(int) *protoent
  • foreign getprotobyname(*ubyte) *protoent
  • foreign __WSAFDIsSet(SOCKET, *fd_set) int
  • func FD_CLR(fd SOCKET, set *fd_set) void
  • func FD_SET(fd SOCKET, set *fd_set) void
  • func FD_ZERO(set *fd_set) void
  • func FD_ISSET(fd SOCKET, set *fd_set) int
  • foreign WSAGetLastError() int
  • func htonl(x uint) uint
  • func ntohl(x uint) uint
  • func htons(x ushort) ushort
  • func ntohs(x ushort) ushort
  • func hton64(x ulong) ulong
  • func ntoh64(x ulong) ulong

Constants

define INVALID_SOCKET = cast SOCKET 0xFFFFFFFFFFFFFFFFFFul
define SOCKET_ERROR = -1
define AI_PASSIVE                = 0x00000001
define AI_CANONNAME              = 0x00000002
define AI_NUMERICHOST            = 0x00000004
define AI_NUMERICSERV            = 0x00000008
define AI_ALL                    = 0x00000100
define AI_ADDRCONFIG             = 0x00000400
define AI_V4MAPPED               = 0x00000800
define AI_NON_AUTHORITATIVE      = 0x00004000
define AI_SECURE                 = 0x00008000
define AI_RETURN_PREFERRED_NAMES = 0x00010000
define AI_FQDN                   = 0x00020000
define AI_FILESERVER             = 0x00040000
define SOCK_STREAM    = 1
define SOCK_DGRAM     = 2
define SOCK_RAW       = 3
define SOCK_RDM       = 4
define SOCK_SEQPACKET = 5
define IPPROTO_IP       = 0
define IPPROTO_HOPOPTS  = 0
define IPPROTO_ICMP     = 1
define IPPROTO_IGMP     = 2
define IPPROTO_GGP      = 3
define IPPROTO_IPV4     = 4
define IPPROTO_TCP      = 6
define IPPROTO_PUP      = 12
define IPPROTO_UDP      = 17
define IPPROTO_IDP      = 22
define IPPROTO_IPV6     = 41
define IPPROTO_ROUTING  = 43
define IPPROTO_FRAGMENT = 44
define IPPROTO_ESP      = 50
define IPPROTO_AH       = 51
define IPPROTO_ICMPV6   = 58
define IPPROTO_NONE     = 59
define IPPROTO_DSTOPTS  = 60
define IPPROTO_ND       = 77
define IPPROTO_ICLFXBM  = 78
define IPPROTO_RAW      = 255
define IPPROTO_MAX      = 256
define AF_UNSPEC     = 0
define AF_UNIX       = 1
define AF_INET       = 2
define AF_IMPLINK    = 3
define AF_PUP        = 4
define AF_CHAOS      = 5
define AF_NS         = 6
define AF_IPX        = AF_NS
define AF_ISO        = 7
define AF_OSI        = AF_ISO
define AF_ECMA       = 8
define AF_DATAKIT    = 9
define AF_CCITT      = 10
define AF_SNA        = 11
define AF_DECnet     = 12
define AF_DLI        = 13
define AF_LAT        = 14
define AF_HYLINK     = 15
define AF_APPLETALK  = 16
define AF_NETBIOS    = 17
define AF_VOICEVIEW  = 18
define AF_FIREFOX    = 19
define AF_UNKNOWN1   = 20
define AF_BAN        = 21
define AF_ATM        = 22
define AF_INET6      = 23
define AF_CLUSTER    = 24
define AF_12844      = 25
define AF_IRDA       = 26
define AF_NETDES     = 28
define AF_TCNPROCESS = 29
define AF_TCNMESSAGE = 30
define AF_ICLFXBM    = 31
define AF_BTH        = 32
define AF_MAX        = 33
define SOMAXCONN = 0x7FFFFFFF
define WINSOCK_1_0 = 1us
define WINSOCK_1_1 = 257us
define WINSOCK_2_0 = 2us
define WINSOCK_2_1 = 258us
define WINSOCK_2_2 = 514us
define IN_CLASSA_NET = 0xff000000
define IN_CLASSA_NSHIFT = 24
define IN_CLASSA_HOST = 0x00ffffff
define IN_CLASSA_MAX = 128
define IN_CLASSB_NET = 0xffff0000
define IN_CLASSB_NSHIFT = 16
define IN_CLASSB_HOST = 0x0000ffff
define IN_CLASSB_MAX = 65536
define IN_CLASSC_NET = 0xffffff00
define IN_CLASSC_NSHIFT = 8
define IN_CLASSC_HOST = 0x000000ff
define INADDR_ANY = 0x00000000
define INADDR_LOOPBACK = 0x7f000001
define INADDR_BROADCAST = 0xffffffff
define INADDR_NONE = 0xffffffff
define SOL_SOCKET = 0xffff
define SO_DEBUG                 = 0x0001
define SO_ACCEPTCONN            = 0x0002
define SO_REUSEADDR             = 0x0004
define SO_KEEPALIVE             = 0x0008
define SO_DONTROUTE             = 0x0010
define SO_BROADCAST             = 0x0020
define SO_USELOOPBACK           = 0x0040
define SO_LINGER                = 0x0080
define SO_OOBINLINE             = 0x0100
define SO_DONTLINGER            = ~SO_LINGER
define SO_SNDBUF                = 0x1001
define SO_RCVBUF                = 0x1002
define SO_SNDLOWAT              = 0x1003
define SO_RCVLOWAT              = 0x1004
define SO_SNDTIMEO              = 0x1005
define SO_RCVTIMEO              = 0x1006
define SO_ERROR                 = 0x1007
define SO_TYPE                  = 0x1008
define SO_CONNDATA              = 0x7000
define SO_CONNOPT               = 0x7001
define SO_DISCDATA              = 0x7002
define SO_DISCOPT               = 0x7003
define SO_CONNDATALEN           = 0x7004
define SO_CONNOPTLEN            = 0x7005
define SO_DISCDATALEN           = 0x7006
define SO_DISCOPTLEN            = 0x7007
define SO_OPENTYPE              = 0x7008
define SO_SYNCHRONOUS_ALERT     = 0x10
define SO_SYNCHRONOUS_NONALERT  = 0x20
define SO_MAXDG                 = 0x7009
define SO_MAXPATHDG             = 0x700A
define SO_UPDATE_ACCEPT_CONTEXT = 0x700B
define SO_CONNECT_TIME          = 0x700C
define TCP_NODELAY              = 0x0001
define TCP_BSDURGENT            = 0x7000
define FIONREAD = 1074030207
define FIONBIO = -2147195266
define FIOASYNC = -2147195267
define SIOCSHIWAT = -2147192064
define SIOCGHIWAT = 1074033409
define SIOCSLOWAT = -2147192062
define SIOCGLOWAT = 1074033411
define SIOCATMARK = 1074033415
define FD_SETSIZE = 64
define WSABASEERR = 10000
define WSAEINTR                         = 10004
define WSAEBADF                         = 10009
define WSAEACCES                        = 10013
define WSAEFAULT                        = 10014
define WSAEINVAL                        = 10022
define WSAEMFILE                        = 10024
define WSAEWOULDBLOCK                   = 10035
define WSAEINPROGRESS                   = 10036
define WSAEALREADY                      = 10037
define WSAENOTSOCK                      = 10038
define WSAEDESTADDRREQ                  = 10039
define WSAEMSGSIZE                      = 10040
define WSAEPROTOTYPE                    = 10041
define WSAENOPROTOOPT                   = 10042
define WSAEPROTONOSUPPORT               = 10043
define WSAESOCKTNOSUPPORT               = 10044
define WSAEOPNOTSUPP                    = 10045
define WSAEPFNOSUPPORT                  = 10046
define WSAEAFNOSUPPORT                  = 10047
define WSAEADDRINUSE                    = 10048
define WSAEADDRNOTAVAIL                 = 10049
define WSAENETDOWN                      = 10050
define WSAENETUNREACH                   = 10051
define WSAENETRESET                     = 10052
define WSAECONNABORTED                  = 10053
define WSAECONNRESET                    = 10054
define WSAENOBUFS                       = 10055
define WSAEISCONN                       = 10056
define WSAENOTCONN                      = 10057
define WSAESHUTDOWN                     = 10058
define WSAETOOMANYREFS                  = 10059
define WSAETIMEDOUT                     = 10060
define WSAECONNREFUSED                  = 10061
define WSAELOOP                         = 10062
define WSAENAMETOOLONG                  = 10063
define WSAEHOSTDOWN                     = 10064
define WSAEHOSTUNREACH                  = 10065
define WSAENOTEMPTY                     = 10066
define WSAEPROCLIM                      = 10067
define WSAEUSERS                        = 10068
define WSAEDQUOT                        = 10069
define WSAESTALE                        = 10070
define WSAEREMOTE                       = 10071
define WSASYSNOTREADY                   = 10091
define WSAVERNOTSUPPORTED               = 10092
define WSANOTINITIALISED                = 10093
define WSAEDISCON                       = 10101
define WSAENOMORE                       = 10102
define WSAECANCELLED                    = 10103
define WSAEINVALIDPROCTABLE             = 10104
define WSAEINVALIDPROVIDER              = 10105
define WSAEPROVIDERFAILEDINIT           = 10106
define WSASYSCALLFAILURE                = 10107
define WSASERVICE_NOT_FOUND             = 10108
define WSATYPE_NOT_FOUND                = 10109
define WSA_E_NO_MORE                    = 10110
define WSA_E_CANCELLED                  = 10111
define WSAEREFUSED                      = 10112
define WSAHOST_NOT_FOUND                = 11001
define WSATRY_AGAIN                     = 11002
define WSANO_RECOVERY                   = 11003
define WSANO_DATA                       = 11004
define WSA_QOS_RECEIVERS                = 11005
define WSA_QOS_SENDERS                  = 11006
define WSA_QOS_NO_SENDERS               = 11007
define WSA_QOS_NO_RECEIVERS             = 11008
define WSA_QOS_REQUEST_CONFIRMED        = 11009
define WSA_QOS_ADMISSION_FAILURE        = 11010
define WSA_QOS_POLICY_FAILURE           = 11011
define WSA_QOS_BAD_STYLE                = 11012
define WSA_QOS_BAD_OBJECT               = 11013
define WSA_QOS_TRAFFIC_CTRL_ERROR       = 11014
define WSA_QOS_GENERIC_ERROR            = 11015
define WSA_QOS_ESERVICETYPE             = 11016
define WSA_QOS_EFLOWSPEC                = 11017
define WSA_QOS_EPROVSPECBUF             = 11018
define WSA_QOS_EFILTERSTYLE             = 11019
define WSA_QOS_EFILTERTYPE              = 11020
define WSA_QOS_EFILTERCOUNT             = 11021
define WSA_QOS_EOBJLENGTH               = 11022
define WSA_QOS_EFLOWCOUNT               = 11023
define WSA_QOS_EUNKOWNPSOBJ             = 11024
define WSA_QOS_EPOLICYOBJ               = 11025
define WSA_QOS_EFLOWDESC                = 11026
define WSA_QOS_EPSFLOWSPEC              = 11027
define WSA_QOS_EPSFILTERSPEC            = 11028
define WSA_QOS_ESDMODEOBJ               = 11029
define WSA_QOS_ESHAPERATEOBJ            = 11030
define WSA_QOS_RESERVED_PETYPE          = 11031
define WSA_SECURE_HOST_NOT_FOUND        = 11032
define WSA_IPSEC_NAME_POLICY_ERROR      = 11033

Imports

import 'machine/endian.adept'
Clone this wiki locally