send() - 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

ssize_t send(int s, const void *buf, size_t len, int flags); 
ssize_t sendto(int s, const void *buf, size_t len, int flags, const struct sockaddr *to, socklen_t tolen); 
ssize_t sendmsg(int s, const struct msghdr *msg, int flags); 

The
send() call may be used only when the socket is in a
connected state (so that the intended recipient is known).
The only difference between
send() and
write() is the presence of
flags. With zero
flags parameter,
send() is equivalent to
write(). Also,
send(s,buf,len,flags) is equivalent to
sendto(s,buf,len,flags,NULL,0). 

The parameter
s is the file descriptor of the sending socket.


If
sendto() is used on a connection-mode (SOCK_STREAM, SOCK_SEQPACKET) socket,
the parameters
to and
tolen are ignored (and the error EISCONN may be returned when they are
not NULL and 0), and the error ENOTCONN is returned when the socket was
not actually connected. Otherwise, the address of the target is given by
to with
tolen specifying its size.
For
sendmsg(), the address of the target is given by
msg.msg_name, with
msg.msg_namelen specifying its size.


For
send() and
sendto(), the message is found in
buf and has length
len. For
sendmsg(), the message is pointed to by the elements of the array
msg.msg_iov. The
sendmsg() call also allows sending ancillary data (also known as control information).


If the message is too long to pass atomically through the
underlying protocol, the error
EMSGSIZE is returned, and the message is not transmitted.


No indication of failure to deliver is implicit in a
send(). Locally detected errors are indicated by a return value of -1.


When the message does not fit into the send buffer of the socket,
send() normally blocks, unless the socket has been placed in non-blocking I/O
mode.  In non-blocking mode it would return
EAGAIN in this case.
The
select(2)
call may be used to determine when it is possible to send more data.


The
flags parameter is the bitwise OR
of zero or more of the following flags.


Since Linux 2.6, this flag is also supported for UDP sockets, and informs
the kernel to package all of the data sent in calls with this flag set
into a single datagram which is only transmitted when a call is performed
that does not specify this flag. 
(See also the
UDP_CORK socket option described in
udp(7).)


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 */
};


You may send control information using the
msg_control and
msg_controllen members. The maximum control buffer length the kernel can process is limited
per socket by the
net.core.optmem_max sysctl; see
socket(7).


POSIX.1-2001 only describes the
MSG_OOB and
MSG_EOR flags.
The
MSG_CONFIRM flag is a Linux extension.


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)
recv (2)
recv (2)
select (2)
select (2)
sendfile (2)
sendfile (2)
shutdown (2)
shutdown (2)
socket (2)
socket (2)
write (2)
write (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