Transport Interfaces Programming Guide

Data Transfer

This section describes the functions to send and receive data. You can send or receive a message with the normal read() and write() function calls:


write(s, buf, sizeof buf);
read(s,  buf, sizeof buf);

Or the calls send() and recv() can be used:


send(s, buf, sizeof buf, flags);
recv(s, buf, sizeof buf, flags);

send() and recv() are very similar to read() and write(), but the flags argument is important. The flags, defined in sys/socket.h, can be specified as a nonzero value if one or more of the following is required:

MSG_OOB

Send and receive out-of-band data

MSG_PEEK

Look at data without reading

MSG_DONTROUTE

Send data without routing packets

Out-of-band data is specific to stream sockets. When MSG_PEEK is specified with a recv() call, any data present is returned to the user but treated as still unread. The next read() or recv() call on the socket returns the same data. The option to send data without routing packets applied to the outgoing packets is currently used only by the routing table management process and is unlikely to be interesting to most users.