VMS Help  —  TCPIP Services, Programming Interfaces, Socket API Functions, recvfrom()
    Receives bytes for a socket from any source.
    Format
      #include  <types.h>
      #include  <socket.h>
      int recvfrom  ( int s, char *buf, int len, int flags,
                    struct sockaddr *from, int *fromlen)  ;
                    (_DECC_V4_SOURCE)
      ssize_t recvfrom  ( int s, void *buf, size_t len, int flags,
                        struct sockaddr *from, size_t *fromlen)  ;
                        (not_DECC_V4_SOURCE)

1  –  Arguments

 s
    A socket descriptor created with the socket() function and
    bound to a name using the bind() function or as a result of the
    accept() function.
 buf
    A pointer to a buffer into which received data is placed.
 len
    The size of the buffer pointed to by buf.
 flags
    A bit mask that can contain one or more of the following
    flags. The mask is built by using a logical OR operation on the
    appropriate values.
    Flag               Description
    MSG_OOB            Allows you to receive out-of-band data. If
                       out-of-band data is available, it is read
                       first.
                       If no out-of-band data is available, the
                       MSG_OOB flag is ignored. To send out-of-band
                       data, use the send(), sendmsg(),  and sendto()
                       functions.
    MSG_PEEK           Allows you to examine the data that is next in
                       line to be received without actually removing
                       it from the system's buffers.
 from
    A buffer that the recvfrom() function uses to place the address
    of the sender who sent the data.
    If from is non-null, the address is returned. If from is null,
    the address is not returned.
 fromlen
    Points to an integer containing the size of the buffer pointed to
    by from. On return, the integer is modified to contain the actual
    length of the socket address structure returned.

2  –  Description

    This function allows a named, unconnected socket to receive
    data. The data is placed in the buffer pointed to by buf, and
    the address of the sender of the data is placed in the buffer
    pointed to by from if from is non-null. The structure that from
    points to is assumed to be as large as the sockaddr structure.
    To receive bytes from any source, the socket does not need to be
    connected.
    You can use the select() function to determine if data is
    available.
    If no data is available at the socket, the recvfrom() call
    waits for data to arrive, unless the socket is nonblocking. If
    the socket is nonblocking, a -1 is returned with the external
    variable errno set to EWOULDBLOCK.
    Related Functions
    See also read(), send(),  sendmsg(), sendto(), and socket().

3  –  Return Values

    x                  The number of bytes of data received and
                       placed in buf.
    0                  Successful completion.
    -1                 Error; errno is set to indicate the error.

4  –  Errors

    EBADF              The socket descriptor is invalid.
    ECONNRESET         A connection was forcibly closed by a peer.
    EFAULT             A valid message buffer was not specified.
                       Nonexistent or protected address space is
                       specified for the message buffer.
    EINTR              A signal interrupted the recvfrom() function
                       before any data was available.
    EINVAL             The MSG_OOB flag is set, and no out-of-band
                       data is available.
    ENOBUFS            The system has insufficient resources to
                       complete the call.
    ENOMEM             The system did not have sufficient memory to
                       fulfill the request.
    ENOTCONN           A receive is attempted on a connection-
                       oriented socket that is not connected.
    ENOTSOCK           The socket descriptor is invalid.
    EOPNOTSUPP         The specified flags are not supported for this
                       socket type.
    ETIMEDOUT          The connection timed out when trying to
                       establish a connection or when a transmission
                       timed out on an active connection.
    EWOULDBLOCK        The NBIO (nonblocking) flag is set for the
                       socket descriptor and the process delayed
                       during the write operation.
Close Help