Sunday, February 19, 2012

sendmsg system call unix

The sendmsg(2) function is conceptually the foundation for all the write functions, as it pertains to sockets. Table below lists the write functions available, in increasing complexity. At each level, the features that are added are listed also.

Function
Features Added
write(2)
The simplest socket write function
send(2)
Adds the flags argument
sendto(2)
Adds socket address and socket length arguments
writev(2)
No flags or socket address, but has scatter write capabilities
sendmsg(2)
Adds flags, socket address and length, scatter write, and ancillary
data capabilities

Given the expanded capabilities of the sendmsg(2) function, you can expect it to require more effort to program. The function prototype for sendmsg(2) is provided as follows:

#include <sys/types.h>
#include <sys/socket.h>
int sendmsg(int s, const struct msghdr *msg, unsigned int flags);

The function's arguments are described as follows:
  • The socket s to send a message on. 
  • The message header structure pointer msg, which will control the operation of this function call. 
  • The optional flag bits argument flags. These are the same flags that are valid for send(2) or sendto(2) function calls.
The return value from this function is the number of bytes sent. Otherwise, -1 indicates an error occurred and errno indicates the reason for it.

See Also:

No comments:

Post a Comment