BSD Sockets Interface Programmer's Guide

Chapter 7 155
Using UNIX Domain Datagram Sockets
Sending and Receiving Messages
Sending and Receiving Messages
The sendto and recvfrom (or sendmsg and recvmsg) system calls are
usually used to transmit and receive messages with datagram sockets.
Sending Messages
Use sendto or sendmsg to send messages. sendmsg is similar to
sendto, except sendmsg allows the send data to be gathered from
several buffers. sendto and its parameters are described in the
following table.
Include files: #include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
System call: count = sendto(s, msg, len, flags, to, tolen)
int s;
char *msg;
int len, flags;
struct sockaddr_un *to;
int tolen;
Parameter
Description of
Contents
INPUT Value
s socket descriptor of local
socket
socket descriptor of socket
that is sending the
message
msg pointer to data buffer pointer to data to be sent
len size of data buffer size of msg
flags settings for optional
flags
0 (no options are currently
supported)
to address of recipient
socket
pointer to the socket
address that message
should be sent to
tolen size of to length of address
structure that to points to