Pass data and control information to the protocol associated send routines.
Item | Description |
---|---|
so | The socket to send data. |
faddr | The destination address, only necessary if the socket is not connected. |
top | The mbuf chain of data to be sent. Remember that the first mbuf must have the packet header filled out. Set the top->m_pkthdr.len to the total length of the data in the mbuf chain and the m_flags to M_PKTHDR. The caller must allocate mbuf memory before calling the routine. |
control | Pointer to an mbuf containing the control information to be sent. The caller must allocate mbuf memory before calling the function if the caller wants to pass in control information. |
flags | Flags options for this write call. Caller can set flags to MSG_NONBLOCK. |
The kern_sosend kernel service passes data and control information to the protocol associated send routines.
The kern_sosend kernel service can be called from process environment.
ksocket_t so;
int flags = 0;
struct sockaddr_in faddr;
struct mbuf *send_mbuf;
struct sockaddr_in faddr;
char msg[100];
int i, rc;
rc = kern_socreate(AF_INET, &so, SOCK_STREAM, IPPROTO_TCP);
if (rc != 0 )
{
return(-1);
}
bzero(&faddr, sizeof(struct sockaddr_in));
faddr.sin_family = AF_INET;
faddr.sin_port = 23456;
faddr.sin_len = sizeof(struct sockaddr_in);
faddr.sin_addr.s_addr = inet_addr("9.3.108.210");
rc = kern_soconnect(so, (struct sockaddr *) &faddr);
if (rc != 0 )
{
return(-1);
}
send_mbuf = MGETBUF(sizeof(msg), M_DONOTWAIT); /* Caller needs to allocate mbuf memory */
if (send_mbuf == NULL)
{
return (-1);
}
for (i=0; i < 100, i++)
{
msg[i] = 0x2A;
}
bcopy(msg, mtod(send_mbuf, caddr_t), sizeof(msg));
send_mbuf->m_len = send_mbuf->m_pkthdr.len = sizeof(msg);
rc = kern_sosend(so, NULL, send_mbuf, 0, MSG_NONBLOCK));
if (rc != 0 )
{
return(-1);
}
Item | Description |
---|---|
0 | Upon Success |
>0 | Error |
The nonzero return value is the error number that is defined in the /usr/include/sys/errno.h file.