recv() - Unix, Linux System Call

Unix - Home
Unix - Getting Started
Unix - File Management
Unix - Directories
Unix - File Permission
Unix - Environment
Unix - Basic Utilities
Unix - Pipes & Filters
Unix - Processes
Unix - Communication
Unix - The vi Editor
Unix - What is Shell?
Unix - Using Variables
Unix - Special Variables
Unix - Using Arrays
Unix - Basic Operators
Unix - Decision Making
Unix - Shell Loops
Unix - Loop Control
Unix - Shell Substitutions
Unix - Quoting Mechanisms
Unix - IO Redirections
Unix - Shell Functions
Unix - Manpage Help
Unix - Regular Expressions
Unix - File System Basics
Unix - User Administration
Unix - System Performance
Unix - System Logging
Unix - Signals and Traps
Unix - Useful Commands
Unix - Quick Guide
Unix - Builtin Functions
Unix - System Calls
Unix - Commands List
Unix Useful Resources
Computer Glossary
Who is Who
Copyright © 2014 by tutorialspoint
#include <sys/types.h> 

#include <sys/socket.h> 

ssize_t recv(int s, void *buf, size_t len, int flags); 

ssize_t recvfrom(int s, void *buf, size_t len, int flags, 
                 struct sockaddr *from, socklen_t *fromlen); 

ssize_t recvmsg(int s, struct msghdr *msg, int flags); 


ssize_t recv(int s, void *buf, size_t len, int flags); 


ssize_t recvfrom(int s, void *buf, size_t len, int flags, 
                 struct sockaddr *from, socklen_t *fromlen); 


ssize_t recvmsg(int s, struct msghdr *msg, int flags); 


If
from is not NULL, and the underlying protocol provides the source address,
this source address is filled in.
The argument
fromlen is a value-result parameter, initialized to the size of the buffer
associated with
from, and modified on return to indicate the actual size of the address stored
there.


The
recv() call is normally used only on a
connected socket (see
connect(2))
and is identical to
recvfrom() with a NULL
from parameter.


All three routines return the length of the message on successful
completion.  If a message is too long to fit in the supplied buffer, excess
bytes may be discarded depending on the type of socket the message is
received from.


If no messages are available at the socket, the receive calls wait for a
message to arrive, unless the socket is nonblocking (see
fcntl(2)),
in which case the value -1 is returned and the external variable
errno set to
EAGAIN. The receive calls normally return any data available, up to the requested
amount, rather than waiting for receipt of the full amount requested.


The
select(2)
or
poll(2)
call may be used to determine when more data arrives.


The
flags argument to a
recv() call is formed by
OR’ing one or more of the following values:


The error is supplied in a
sock_extended_err structure:



#define SO_EE_ORIGIN_NONE    0
#define SO_EE_ORIGIN_LOCAL   1
#define SO_EE_ORIGIN_ICMP    2
#define SO_EE_ORIGIN_ICMP6   3

struct sock_extended_err
{
    u_int32_t ee_errno;   /* error number */
    u_int8_t  ee_origin;  /* where the error originated */
    u_int8_t  ee_type;    /* type */
    u_int8_t  ee_code;    /* code */
    u_int8_t  ee_pad;
    u_int32_t ee_info;    /* additional information */
    u_int32_t ee_data;    /* other data */ 
    /* More data may follow */
};

struct sockaddr *SO_EE_OFFENDER(struct sock_extended_err *);


#define SO_EE_ORIGIN_NONE    0
#define SO_EE_ORIGIN_LOCAL   1
#define SO_EE_ORIGIN_ICMP    2
#define SO_EE_ORIGIN_ICMP6   3


struct sock_extended_err
{
    u_int32_t ee_errno;   /* error number */
    u_int8_t  ee_origin;  /* where the error originated */
    u_int8_t  ee_type;    /* type */
    u_int8_t  ee_code;    /* code */
    u_int8_t  ee_pad;
    u_int32_t ee_info;    /* additional information */
    u_int32_t ee_data;    /* other data */ 
    /* More data may follow */
};


struct sockaddr *SO_EE_OFFENDER(struct sock_extended_err *);


struct msghdr {
    void         *msg_name;       /* optional address */
    socklen_t     msg_namelen;    /* size of address */
    struct iovec *msg_iov;        /* scatter/gather array */
    size_t        msg_iovlen;     /* # elements in msg_iov */
    void         *msg_control;    /* ancillary data, see below */
    socklen_t     msg_controllen; /* ancillary data buffer len */
    int           msg_flags;      /* flags on received message */
};


struct msghdr {
    void         *msg_name;       /* optional address */
    socklen_t     msg_namelen;    /* size of address */
    struct iovec *msg_iov;        /* scatter/gather array */
    size_t        msg_iovlen;     /* # elements in msg_iov */
    void         *msg_control;    /* ancillary data, see below */
    socklen_t     msg_controllen; /* ancillary data buffer len */
    int           msg_flags;      /* flags on received message */
};


struct cmsghdr {
    socklen_t cmsg_len;     /* data byte count, including hdr */
    int       cmsg_level;   /* originating protocol */
    int       cmsg_type;    /* protocol-specific type */
/* followed by
    u_char    cmsg_data[]; */
};


struct cmsghdr {
    socklen_t cmsg_len;     /* data byte count, including hdr */
    int       cmsg_level;   /* originating protocol */
    int       cmsg_type;    /* protocol-specific type */
/* followed by
    u_char    cmsg_data[]; */
};


POSIX.1-2001 only describes the
MSG_OOB, MSG_PEEK, and
MSG_WAITALL flags.


According to POSIX.1-2001, the
msg_controllen field of the
msghdr structure should be typed as
socklen_t, but glibc currently (2.4) types it as
size_t. 
fcntl (2)
fcntl (2)
getsockopt (2)
getsockopt (2)
read (2)
read (2)
select (2)
select (2)
shutdown (2)
shutdown (2)
socket (2)
socket (2)

Advertisements


    129 Lectures 
     23 hours 

 Eduonix Learning Solutions

    5 Lectures 
     4.5 hours 

 Frahaan Hussain

    35 Lectures 
     2 hours 

 Pradeep D

    41 Lectures 
     2.5 hours 

 Musab Zayadneh

    46 Lectures 
     4 hours 

 GUHARAJANM

    6 Lectures 
     4 hours 

 Uplatz
 Print
 Add Notes
 Bookmark this page