Advanced Programming in the UNIX® Environment

(lily) #1
ptg10805159

Section 16.5 Data Transfer 611


the destination address is first set by callingconnect,sosendtogives us an alternate
way to send a message.

FreeBSD Linux Mac OS X Solaris
Flag Description POSIX.1 8.0 3.2.0 10.6.8 10

MSG_CONFIRM Provide feedback to the link layer •
to keep address mapping valid.
MSG_DONTROUTE Don’t route packet outside of local ••••
network.
MSG_DONTWAIT Enable nonblocking operation ••••
(equivalent to using
O_NONBLOCK).
MSG_EOF Shut the sender side of the socket ••
down after sending data.
MSG_EOR Mark the end of the recordif •••••
supported by protocol.
MSG_MORE Delay sending the packet to allow •
moredata to be written.
MSG_NOSIGNAL Don’t generateSIGPIPEwhen •••
writing to an unconnected
socket.
MSG_OOB Send out-of-band data if •••••
supported by protocol (see
Section 16.7).

Figure 16.13Flags used withsendsocket calls

We have one morechoice when transmitting data over a socket. We can call
sendmsgwith amsghdrstructure to specify multiple buffers from which to transmit
data, similar to thewritevfunction (Section 14.6).
#include <sys/socket.h>
ssize_t sendmsg(intsockfd,const struct msghdr *msg,intflags);
Returns: number of bytes sent if OK,−1 on error
POSIX.1 defines themsghdrstructure to have at least the following members:
struct msghdr {
void *msg_name; /* optional address */
socklen_t msg_namelen; /* address size in bytes */
struct iovec *msg_iov; /* array of I/O buffers */
int msg_iovlen; /* number of elements in array */
void *msg_control; /* ancillary data */
socklen_t msg_controllen; /* number of ancillary bytes */
int msg_flags; /* flags for received message */
..
.
};

We saw theiovecstructure in Section 14.6. We’ll see the use of ancillary data in
Section 17.4.
Free download pdf