The %sendto() sends data to a specified destination. If no errors occur, the total number of bytes sent is returned.
code = %sendto(socket, buffer, buflen, flags, HostName, port)
socket | File descriptor for the local socket. |
buffer | Data to send. |
buflen | Length of the data in bytes. |
flags | Should be zero. |
HostName | Destination target server name. |
port | Port number for the target server. |
* * Open a connection through UDP/IP. * cfunction socket.builtin include dm,bp,includes sysid.inc include dm,bp,unix.h socket.h equ ip_port to 3176 * * Get the host name. tclread line host = field(trim(line),' ',2) * * Create a socket fd=%socket( AF$INET, SOCK$DGRAM, 0) if fd<0 then print "Open error: ":system(0); stop * port=%bind( fd, AF$INET, INADDR$ANY, ip_port ) * leng = 4; err = " " x = %getsockopt(fd,SOL$SOCKET,SO$ERROR,&err,&leng) * prompt "" print "command: ":; input cmd ln = len(cmd) MaxPack = int(ln/242)+1 for x = 1 to MaxPack Buffer = "ExEC":x 'r%4':MaxPack 'r%4':cmd[((x-1)*242)+1,242]:space(242) n = %sendto(fd, Buffer, 256, 0, &host, ip_port) if n < 0 then print "Write error: ":system(0) end next x * * Loop reading the Result packets bigbuff = ""; packcnt = 0 loop addr=0; port=0 buffer = space(256) length=%recvfrom( fd, buffer, 256, 0, &addr, &port) if length<0 then print "Read Error: ":system(0) PackSeq = buffer[5,4] MaxPack = buffer[9,4] packcnt += 1 bigbuff[1+((PackSeq-1)*242),242] = buffer[13,242] until packcnt = MaxPack do repeat * * print the buffer cnt = dcount(bigbuff,char(254)) for x = 1 to cnt print bigbuff<x> next x * * Close the socket %close( fd ) end