recvfrom (IXCALL 0x3E1B) - receive a message from a socket
ld a, (v_sockfd) ld hl, BUF_CONNINFO ld de, BUF_DATA ld bc, BUF_DATA_LEN ld ix, RECVFROM call IXCALL
#include <sys/types.h> #include <sys/socket.h> int recvfrom(int sockfd, void *buf, size_t len, int flags, struct sockaddr_in *from, socklen_t *fromlen);
The recvfrom() call is used to receive messages from a socket, and may be used to receive data on a socket whether or not it is connection-oriented. The recvfrom() call is typically used with UDP (SOCK_DGRAM) sockets to receive a datagram from the remote host.
The socket is specified by the sockfd parameter. The buf parameter is a pointer to a buffer which should be filled with the data from the remote host, and the len parameter specifies the maximum number of bytes that may be copied into this buffer. In the current implementation, the flags parameter is not used. The from parameter is a pointer to a struct sockaddr_in, and this structure will be filled with information about the remote host that sent the datagram that is being received. The fromlen parameter specifies the size of the structure; it is currently unused since the only structure type that is valid for this call is a struct sockaddr_in, and is provided to give compatibility with the BSD socket library specification.
For the assembly language interface, the socket is specified in the A register, the register pair DE contains the address in memory where the received data should be written, and the BC register pair contains the maximum number of bytes that may be copied into this area of memory. The HL register pair points to a location in memory where the information about the remote host may be copied. The connection information is 8 bytes long, so the memory location contained in HL must be a location with at least 8 bytes free. The assembly language interface fills the memory pointed to by HL in the following format:
bytes 0,1,2,3 - the remote host's IP address bytes 4,5 - the remote host's port number bytes 6,7 - the local host's port number
On return, the C interface returns the number of bytes actually received, or -1 if an error occurred.
The assembly language interface returns the number of bytes received in BC on success. On error, the carry flag is set and the A register contains the error code.