; _______________________________________________________________________________________
;|                                                                                       |
;| ..::FreshLib::..  Free, open source. Licensed under "BSD 2-clause" license."          |
;|_______________________________________________________________________________________|
;
;  Description: WSOCK32.DLL structures and constants
;
;  Target OS: Win32
;
;  Dependencies:
;
;  Notes:
;_________________________________________________________________________________________


struct WSADATA
  .wVersion       dw ?
  .wHighVersion   dw ?
  .szDescription  rb 256+1
  .szSystemStatus rb 128+1
  .iMaxSockets    dw ?
  .iMaxUdpDg      dw ?
  .lpVendorInfo   dd ?
ends

struct hostent
  .h_name      dd ?
  .h_aliases   dd ?
  .h_addrtype  dw ?
  .h_length    dw ?
  .h_addr_list dd ?
ends

struct sockaddr_in
  .sin_family dw ?
  .sin_port   dw ?
  .sin_addr   dd ?
  .sin_zero   rb 8
ends

struct sockaddr
   .sa_family dw ?
   .sa_data rb 14
ends

; Socket error

SOCKET_ERROR = -1
INVALID_SOCKET = -1

UNIX_PATH_MAX = 108


; Socket types

SOCK_STREAM    = 1
SOCK_DGRAM     = 2
SOCK_RAW       = 3
SOCK_RDM       = 4
SOCK_SEQPACKET = 5

; Address formats

AF_UNSPEC    = 0
AF_UNIX      = 1
AF_INET      = 2
AF_IMPLINK   = 3
AF_PUP       = 4
AF_CHAOS     = 5
AF_NS        = 6
AF_IPX       = AF_NS
AF_ISO       = 7
AF_OSI       = AF_ISO
AF_ECMA      = 8
AF_DATAKIT   = 9
AF_CCITT     = 10
AF_SNA       = 11
AF_DECnet    = 12
AF_DLI       = 13
AF_LAT       = 14
AF_HYLINK    = 15
AF_APPLETALK = 16
AF_NETBIOS   = 17
AF_VOICEVIEW = 18    ; VoiceView
AF_FIREFOX   = 19              ; Protocols from Firefox
AF_UNKNOWN1  = 20              ; Somebody is using this!
AF_BAN       = 21              ; Banyan
AF_ATM       = 22              ; Native ATM Services
AF_INET6     = 23              ; Internetwork Version 6
AF_CLUSTER   = 24              ; Microsoft Wolfpack
AF_12844     = 25              ; IEEE 1284.4 WG AF

AF_MAX       = 26

; Protocol formats

PF_UNSPEC    = 0
PF_UNIX      = 1
PF_INET      = 2
PF_IMPLINK   = 3
PF_PUP       = 4
PF_CHAOS     = 5
PF_NS        = 6
PF_IPX       = 6
PF_ISO       = 7
PF_OSI       = PF_ISO
PF_ECMA      = 8
PF_DATAKIT   = 9
PF_CCITT     = 10
PF_SNA       = 11
PF_DECnet    = 12
PF_DLI       = 13
PF_LAT       = 14
PF_HYLINK    = 15
PF_APPLETALK = 16
PF_NETBIOS   = 17


; IPPROTO_ constants
; Protocols

IPPROTO_IP       =       0               ; dummy for IP
IPPROTO_ICMP     =       1               ; control message protocol
IPPROTO_IGMP     =       2               ; internet group management protocol
IPPROTO_GGP      =       3               ; gateway^2 (deprecated)
IPPROTO_TCP      =       6               ; tcp
IPPROTO_PUP      =       12              ; pup
IPPROTO_UDP      =       17              ; user datagram protocol
IPPROTO_IDP      =       22              ; xns idp
IPPROTO_ND       =       77              ; UNOFFICIAL net disk proto

IPPROTO_RAW      =       255             ; raw IP packet
IPPROTO_MAX      =       256


; IP Ports

IPPORT_ECHO        = 7
IPPORT_DISCARD     = 9
IPPORT_SYSTAT      = 11
IPPORT_DAYTIME     = 13
IPPORT_NETSTAT     = 15
IPPORT_FTP         = 21
IPPORT_TELNET      = 23
IPPORT_SMTP        = 25
IPPORT_TIMESERVER  = 37
IPPORT_NAMESERVER  = 42
IPPORT_WHOIS       = 43
IPPORT_MTP         = 57
IPPORT_TFTP        = 69
IPPORT_RJE         = 77
IPPORT_FINGER      = 79
IPPORT_TTYLINK     = 87
IPPORT_SUPDUP      = 95
IPPORT_EXECSERVER  = 512
IPPORT_LOGINSERVER = 513
IPPORT_CMDSERVER   = 514
IPPORT_EFSSERVER   = 520
IPPORT_BIFFUDP     = 512
IPPORT_WHOSERVER   = 513
IPPORT_ROUTESERVER = 520
IPPORT_RESERVED    = 1024

; Notifications

FD_READ         = 01h
FD_WRITE        = 02h
FD_OOB          = 04h
FD_ACCEPT       = 08h
FD_CONNECT      = 10h
FD_CLOSE        = 20h

; commands for ioctlsocket

FIONBIO         = 8004667Eh
FIONSYNC        = 8004667Dh
FIONREAD        = 4004667Fh


; flags

MSG_OOB       = 1
MSG_PEEK      = 2
MSG_DONTROUTE = 4
MSG_MAXIOVLEN = 16
MSG_PARTIAL   = 0x8000

; options

SOL_SOCKET = $FFFF

SO_DEBUG       = $01
SO_ACCEPTCONN  = $02
SO_REUSEADDR   = $04
SO_KEEPALIVE   = $08
SO_DONTROUTE   = $10
SO_BROADCAST   = $20
SO_USELOOPBACK = $40
SO_LINGER      = $80
SO_OOBINLINE   = $100
SO_SNDBUF      = $1001
SO_RCVBUF      = $1002
SO_SNDTIMEO    = $1005
SO_RCVTIMEO    = $1006



WSABASEERR              =  10000

WSAEINTR                =  WSABASEERR+4
WSAEBADF                =  WSABASEERR+9
WSAEACCES               =  WSABASEERR+13
WSAEFAULT               =  WSABASEERR+14
WSAEINVAL               =  WSABASEERR+22
WSAEMFILE               =  WSABASEERR+24

WSAEWOULDBLOCK          =  WSABASEERR+35
WSAEINPROGRESS          =  WSABASEERR+36
WSAEALREADY             =  WSABASEERR+37
WSAENOTSOCK             =  WSABASEERR+38
WSAEDESTADDRREQ         =  WSABASEERR+39
WSAEMSGSIZE             =  WSABASEERR+40
WSAEPROTOTYPE           =  WSABASEERR+41
WSAENOPROTOOPT          =  WSABASEERR+42
WSAEPROTONOSUPPORT      =  WSABASEERR+43
WSAESOCKTNOSUPPORT      =  WSABASEERR+44
WSAEOPNOTSUPP           =  WSABASEERR+45
WSAEPFNOSUPPORT         =  WSABASEERR+46
WSAEAFNOSUPPORT         =  WSABASEERR+47
WSAEADDRINUSE           =  WSABASEERR+48
WSAEADDRNOTAVAIL        =  WSABASEERR+49
WSAENETDOWN             =  WSABASEERR+50
WSAENETUNREACH          =  WSABASEERR+51
WSAENETRESET            =  WSABASEERR+52
WSAECONNABORTED         =  WSABASEERR+53
WSAECONNRESET           =  WSABASEERR+54
WSAENOBUFS              =  WSABASEERR+55
WSAEISCONN              =  WSABASEERR+56
WSAENOTCONN             =  WSABASEERR+57
WSAESHUTDOWN            =  WSABASEERR+58
WSAETOOMANYREFS         =  WSABASEERR+59
WSAETIMEDOUT            =  WSABASEERR+60
WSAECONNREFUSED         =  WSABASEERR+61
WSAELOOP                =  WSABASEERR+62
WSAENAMETOOLONG         =  WSABASEERR+63
WSAEHOSTDOWN            =  WSABASEERR+64
WSAEHOSTUNREACH         =  WSABASEERR+65
WSAENOTEMPTY            =  WSABASEERR+66
WSAEUSERS               =  WSABASEERR+68
WSAEDQUOT               =  WSABASEERR+69
WSAESTALE               =  WSABASEERR+70
WSAEREMOTE              =  WSABASEERR+71

; Extended Windows Sockets error codes

WSASYSNOTREADY          =  WSABASEERR+91
WSAVERNOTSUPPORTED      =  WSABASEERR+92
WSANOTINITIALISED       =  WSABASEERR+93
WSAEDISCON              =  WSABASEERR+101
WSAENOMORE              =  WSABASEERR+102
WSAECANCELLED           =  WSABASEERR+103
WSAEINVALIDPROCTABLE    =  WSABASEERR+104
WSAEINVALIDPROVIDER     =  WSABASEERR+105
WSAEPROVIDERFAILEDINIT  =  WSABASEERR+106
WSASYSCALLFAILURE       =  WSABASEERR+107
WSASERVICE_NOT_FOUND    =  WSABASEERR+108
WSATYPE_NOT_FOUND       =  WSABASEERR+109
WSA_E_NO_MORE           =  WSABASEERR+110
WSA_E_CANCELLED         =  WSABASEERR+111
WSAEREFUSED             =  WSABASEERR+112

WSAHOST_NOT_FOUND       =  WSABASEERR+1001
WSATRY_AGAIN            =  WSABASEERR+1002
WSANO_RECOVERY          =  WSABASEERR+1003
WSANO_DATA              =  WSABASEERR+1004
WSANO_ADDRESS           =  WSANO_DATA