The socket call sends data and control information on a specified socket.
Syntax
#include <types.h> #include <sys\socket.h> int sendmsg(s, msg, flags) int s; struct msghdr *msg; int flags;
Parameters
s
MSG_DONTROUTE
Description
This call sends a msghdr structure on a socket with descriptor s.
Networking services supports the following msghdr structure.
Note: The fields msg_control and msg_controllen are ignored for the NetBIOS and Local IPC domains.
struct msghdr { caddr_t msg_name; /* optional pointer to destination address buffer */ int msg_namelen; /* size of address buffer */ struct iovec *msg_iov; /* scatter/gather array */ int msg_iovlen; /* number of elements in msg_iov, maximum 1024 */ caddr_t msg_control; /* ancillary data */ u_int msg_controllen; /* ancillary data length */ int msg_flags; /* flags on received message */ };
To broadcast on a socket, the application program must first issue a setsockopt() call using the SO_BROADCAST option, to gain broadcast permission.
The sendmsg() call applies to connection-oriented and connectionless sockets.
msg_iov is a scatter/gather array of iovec structures. The iovec structure is defined in <SYS/UIO.H> and contains the following fields:
Field
TCP/IP alters iov_base and iov_len for each element in the input struct iovec array. iov_base will point to the next character of the processed (sent or received) data on the original buffer, and iov_len will become (input value - processed length). Thus if only partial data has been sent or received and the application expects more data to send or receive, it can pass the same iovec structure back in a subsequent call.
This call returns the length of the data sent. If the socket with descriptor s is not ready for sending data, the sendmsg() call waits unless the socket is in nonblocking mode. See ioctl() for a description of how to set nonblocking mode.
Return Values
When successful, the number of bytes of data sent is returned. Successful completion does not guarantee delivery of the data to the receiver. The return value -1 indicates an error was detected on the sending side of the connection. You can get the specific error code by calling sock_errno() or psock_errno().
Error Code
Related Calls
getsockopt() ioctl()
readv()
recv()
recvfrom()
recvmsg()
select()
send()
sendto()
setsockopt()
shutdown()
sock_errno()
socket()
writev()