Tag Archive: network

use winsock

This article only contains the equates and prototypes for the winsock api calls. The equates are at the top of the article, and the prototypes are at the bottom.

Courtesy of Bill Knopf, LEADS Software Group.

Equates for Winsock:

!---------------------- WINSOCK EQUATES ----------------------
SOCK_STREAM     EQUATE(1)
SOCK_DGRAM      EQUATE(2)

INVALID_SOCKET  EQUATE(-1)
SOL_SOCKET      EQUATE(0000ffffh)
IPPROTO_TCP     EQUATE(6)
SOCKET_ERROR    EQUATE(-1)

AF_INET         EQUATE(2)               !TCP/IP Address Type
AF_IPX          EQUATE(6)               !IPX/SPX Address Type
INADDR_ANY      EQUATE(0)
INADDR_BROADCAST EQUATE(-1)             !Broadcast Address

SO_DEBUG        EQUATE(0001h)
SO_ACCEPTCONN   EQUATE(0002h)
SO_REUSEADDR    EQUATE(0004h)
SO_DONTROUTE    EQUATE(0010h)
SO_BROADCAST    EQUATE(0020h)
SO_USELOOPBACK  EQUATE(0040h)
SO_LINGER       EQUATE(0080h)
SO_OOBINLINE    EQUATE(0100h)
SO_SNDBUF       EQUATE(1001h)
SO_RCVBUF       EQUATE(1002h)
SO_SNDLOWAT     EQUATE(1003h)
SO_RCVLOWAT     EQUATE(1004h)
SO_SNDTIMEO     EQUATE(1005h)
SO_RCVTIMEO     EQUATE(1006h)
SO_ERROR        EQUATE(1007h)
SO_TYPE         EQUATE(1008h)

TCP_NODELAY     EQUATE(0001h)

SOMAXCONN       EQUATE(5)

MSG_OOB         EQUATE(1h)
MSG_PEEK        EQUATE(2h)
MSG_DONTROUTE   EQUATE(4h)
MSG_MAXIOVLEN   EQUATE(16)

MAXGETHOSTSTRUCT EQUATE(1024)

FD_READ      EQUATE(01h)
FD_WRITE     EQUATE(02h)
FD_OOB       EQUATE(04h)
FD_ACCEPT    EQUATE(08h)
FD_CONNECT   EQUATE(10h)
FD_CLOSE     EQUATE(20h)

WSABASEERR              EQUATE(10000)

WSAEINTR                EQUATE(WSABASEERR+4)
WSAEBADF                EQUATE(WSABASEERR+9)
WSAEACCES               EQUATE(WSABASEERR+13)
WSAEFAULT               EQUATE(WSABASEERR+14)
WSAEINVAL               EQUATE(WSABASEERR+22)
WSAEMFILE               EQUATE(WSABASEERR+24)

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

WSASYSNOTREADY          EQUATE(WSABASEERR+91)
WSAVERNOTSUPPORTED      EQUATE(WSABASEERR+92)
WSANOTINITIALISED       EQUATE(WSABASEERR+93)
WSANOSOCKETS            EQUATE(WSABASEERR+94)

WSAHOST_NOT_FOUND       EQUATE(WSABASEERR+1001)
HOST_NOT_FOUND          EQUATE(WSAHOST_NOT_FOUND)
WSATRY_AGAIN            EQUATE(WSABASEERR+1002)
TRY_AGAIN               EQUATE(WSATRY_AGAIN)
WSANO_RECOVERY          EQUATE(WSABASEERR+1003)
NO_RECOVERY             EQUATE(WSANO_RECOVERY)
WSANO_DATA              EQUATE(WSABASEERR+1004)
NO_DATA                 EQUATE(WSANO_DATA)

WSANO_ADDRESS           EQUATE(WSANO_DATA)
NO_ADDRESS              EQUATE(WSANO_ADDRESS)


SOCKET          EQUATE(UNSIGNED)

WSAData         GROUP,TYPE
wVersion          SHORT
wHighVersion      SHORT
szDescription     CSTRING(256)
szSystemStatus    CSTRING(128)
iMaxSockets       USHORT
iMaxUdpDg         USHORT
lpVendorInfo      CSTRING(30)
                END

in_addr   GROUP,TYPE
S_addr        ULONG
S_un_b        GROUP,OVER(S_addr)
s_b1            BYTE
s_b2            BYTE
s_b3            BYTE
s_b4            BYTE
              END

S_un_w        GROUP,OVER(S_addr)
s_w1            USHORT
s_w2            USHORT
              END
          END

hostent  GROUP,TYPE
h_name      CSTRING(35)
h_aliases   CSTRING(35)
h_addrtype  SHORT
h_length    SHORT
h_IPStr     CSTRING(20)
         END

servent  GROUP,TYPE
s_name     CSTRING(15)
s_alias    CSTRING(20)
s_port     SHORT
s_proto    CSTRING(3)
         END

sockaddr       GROUP,TYPE
family           SHORT
port             USHORT
addr             ULONG          !LIKE(in_addr)
zero             CSTRING(16)
               END

sockproto    GROUP,TYPE
sp_family      USHORT
sp_protocol    USHORT
             END

linger       GROUP,TYPE
l_onoff        USHORT
l_linger       USHORT
             END


!-------------------- WINSOCK PROTOTYPES ---------------------

 MODULE('WINSOCK.DLL')
   WSAStartup(UNSIGNED,LONG),SIGNED,PASCAL,NAME('WSASTARTUP'),DLL(dll_mode)
   WSACleanup(),SIGNED,PASCAL,NAME('WSACLEANUP'),DLL(dll_mode)
   htons(USHORT),USHORT,PASCAL,NAME('HTONS'),DLL(dll_mode)
   ntohs(USHORT),USHORT,PASCAL,NAME('NTOHS'),DLL(dll_mode)
   htonl(ULONG),ULONG,PASCAL,NAME('HTONL'),DLL(dll_mode)
   ntohl(ULONG),ULONG,PASCAL,NAME('NTOHL'),DLL(dll_mode)
   inet_addr(*CSTRING),ULONG,PASCAL,RAW,NAME('INET_ADDR'),DLL(dll_mode)
   inet_ntoa(ULONG),CSTRING,PASCAL,RAW,NAME('INET_NTOA'),DLL(dll_mode)
   getservbyname(*CSTRING,*CSTRING),LONG,RAW,PASCAL,NAME('GETSERVBYNAME'),DLL(dll_mode)
   getservbyport(SIGNED,*CSTRING),LONG,RAW,PASCAL,NAME('GETSERVBYPORT'),DLL(dll_mode)
   gethostname(*CSTRING,SIGNED),SIGNED,RAW,PASCAL,NAME('GETHOSTNAME'),DLL(dll_mode),PROC
   gethostbyname(*CSTRING),LONG,PASCAL,RAW,NAME('GETHOSTBYNAME'),DLL(dll_mode)
   WSAGetLastError(),SIGNED,RAW,PASCAL,NAME('WSAGETLASTERROR'),DLL(dll_mode)
   ssocket(SIGNED,SIGNED,SIGNED),UNSIGNED,PASCAL,NAME('SOCKET'),DLL(dll_mode)
   closesocket(UNSIGNED),SIGNED,PASCAL,NAME('CLOSESOCKET'),DLL(dll_mode)
   sbind(UNSIGNED,LONG,SIGNED),SIGNED,RAW,PASCAL,NAME('BIND'),DLL(dll_mode)
   getsockname(UNSIGNED,*sockaddr,*SIGNED),SIGNED,RAW,PASCAL,NAME('GETSOCKNAME'),DLL(dll_mode)
   getpeername(UNSIGNED,*sockaddr,*SIGNED),SIGNED,RAW,PASCAL, NAME('GETPEERNAME'),DLL(dll_mode)
   getsockopt(UNSIGNED,SIGNED,SIGNED,*CSTRING,*SIGNED),SIGNED,RAW,PASCAL,NAME('GETSOCKOPT'),DLL(dll_mode)
   setsockopt(UNSIGNED,SIGNED,SIGNED,LONG,SIGNED),SIGNED,RAW,PASCAL,NAME('SETSOCKOPT'),DLL(dll_mode)
   sshutdown(UNSIGNED,SIGNED),SIGNED,PASCAL,NAME('SHUTDOWN'),DLL(dll_mode)
   ioctlsocket(UNSIGNED,LONG,*ULONG),SIGNED,RAW,PASCAL,NAME('IOCTLSOCKET'),DLL(dll_mode)
   listen(UNSIGNED,SIGNED),SIGNED,PASCAL,NAME('LISTEN'),DLL(dll_mode)
   saccept(UNSIGNED,*sockaddr,*SIGNED),UNSIGNED,RAW,PASCAL,NAME('ACCEPT'),DLL(dll_mode)
   connect(UNSIGNED,*sockaddr,SIGNED),SIGNED,RAW,PASCAL,NAME('CONNECT'),DLL(dll_mode)
   ssend(UNSIGNED,LONG,SIGNED,SIGNED),SIGNED,RAW,PASCAL,NAME('SEND')
   recv(UNSIGNED,LONG,SIGNED,SIGNED),SIGNED,RAW,PASCAL, NAME('RECV'),DLL(dll_mode)
   sendto(UNSIGNED,LONG,SIGNED,SIGNED,LONG,SIGNED),SIGNED,RAW,PASCAL,NAME('SENDTO'),DLL(dll_mode)
   recvfrom(UNSIGNED,LONG,SIGNED,SIGNED,LONG,LONG),SIGNED,RAW,PASCAL,NAME('RECVFROM'),DLL(dll_mode)
   WSAAsyncgethostbyname(HANDLE,UNSIGNED,*CSTRING,*CSTRING,SIGNED), HANDLE,RAW,PASCAL,NAME('WSAASYNCGETHOSTBYNAME'),DLL(dll_mode)
   WSAAsyncgethostbyaddr(HANDLE,UNSIGNED,*CSTRING,SIGNED,SIGNED,*CSTRING,SIGNED),HANDLE,RAW,PASCAL,NAME('WSAASYNCGETHOSTBYADDR'),DLL(dll_mode)
   WSAAsyncSelect(UNSIGNED,HANDLE,UNSIGNED,LONG),SIGNED,PASCAL,NAME('WSAASYNCSELECT'),DLL(dll_mode)
 END

map network drive

!global equates
NETRESOURCE GROUP
dwScope       ULONG
dwType        ULONG
dwDisplayType ULONG
dwUsage       ULONG
lpLocalName   ULONG
lpRemoteName  ULONG
lpComment     ULONG
lpProvider    ULONG
            END
CONNECT_UPDATE_PROFILE  EQUATE(01h)
RESOURCETYPE_DISK       EQUATE(01h)
RESOURCETYPE_PRINT      EQUATE(02h)
RESOURCETYPE_ANY        EQUATE(00h)


!global prototypes
MODULE('WNET API')
  WNetAddConnection(*NETRESOURCE,*CSTRING,*CSTRING,ULONG),SIGNED,PASCAL,RAW,NAME('WNetAddConnection2A')
END


!local data
LOC:NetRes           LIKE(NETRESOURCE)
LOC:lpPassword       CSTRING(20)
LOC:lpUserName       CSTRING(20)
LOC:dwFlags          ULONG
LOC:lpLocalName   CSTRING(10)
LOC:lpRemoteName  CSTRING(260)
LOC:lpComment     CSTRING(10)
LOC:lpProvider    CSTRING(10)

!map network drive
CLEAR(LOC:NetRes)
LOC:NetRes.dwType = RESOURCETYPE_DISK
LOC:lpLocalName = 'F:'
LOC:lpRemoteName = '\\III-NTServer\C'
LOC:NetRes.lpLocalName = ADDRESS(LOC:lpLocalName)
LOC:NetRes.lpRemoteName = ADDRESS(LOC:lpRemoteName)
CLEAR(LOC:lpPassword)
CLEAR(LOC:lpUserName)
LOC:dwFlags = CONNECT_UPDATE_PROFILE
Erc# = WNetAddConnection(LOC:NetRes,LOC:lpPassword,LOC:lpUserName,LOC:dwFlags)