' UDP via Winsock DECLARE — sendto, recvfrom
#COMPILE EXE
#DIM ALL

DECLARE FUNCTION WSAStartup LIB "WS2_32.DLL" (BYVAL wVersionRequired AS LONG, BYREF lpWSAData AS LongPtr) AS LONG
DECLARE FUNCTION WSACleanup LIB "WS2_32.DLL" () AS LONG
DECLARE FUNCTION socket LIB "WS2_32.DLL" (BYVAL af AS LONG, BYVAL type AS LONG, BYVAL protocol AS LONG) AS LONG
DECLARE FUNCTION sendto LIB "WS2_32.DLL" (BYVAL s AS LONG, BYREF buf AS BYTE, BYVAL len AS LONG, BYVAL flags AS LONG, BYREF to AS LongPtr, BYVAL tolen AS LONG) AS LONG
DECLARE FUNCTION recvfrom LIB "WS2_32.DLL" (BYVAL s AS LONG, BYREF buf AS BYTE, BYVAL len AS LONG, BYVAL flags AS LONG, BYREF from AS LongPtr, BYREF fromlen AS LONG) AS LONG
DECLARE FUNCTION closesocket LIB "WS2_32.DLL" (BYVAL s AS LONG) AS LONG

%AF_INET = 2
%SOCK_DGRAM = 2

FUNCTION PBMAIN() AS LONG
    PRINT "UDP via Winsock DECLARE:"
    PRINT "1. WSAStartup"
    PRINT "2. socket(AF_INET, SOCK_DGRAM, 0) -> s"
    PRINT "3. sendto(s, buf, len, 0, dest, destlen)"
    PRINT "4. recvfrom(s, buf, len, 0, src, srclen)"
    PRINT "5. closesocket(s) + WSACleanup"
    FUNCTION = 0
END FUNCTION
