Support for read/write on connected UDP sockets

This commit is contained in:
David van Moolenbroek 2009-11-19 23:45:46 +00:00
parent 3926b70b22
commit 4d4cb8fa24
2 changed files with 30 additions and 6 deletions

View file

@ -110,7 +110,7 @@ static int _udp_connect(int socket, const struct sockaddr *address,
if (address == NULL)
{
/* Unset remote address */
udpopt.nwuo_flags= NWUO_RP_ANY | NWUO_RA_ANY;
udpopt.nwuo_flags= NWUO_RP_ANY | NWUO_RA_ANY | NWUO_RWDATALL;
r= ioctl(socket, NWIOSUDPOPT, &udpopt);
return r;
@ -127,7 +127,7 @@ static int _udp_connect(int socket, const struct sockaddr *address,
errno= EINVAL;
return -1;
}
udpopt.nwuo_flags= NWUO_RP_SET | NWUO_RA_SET;
udpopt.nwuo_flags= NWUO_RP_SET | NWUO_RA_SET | NWUO_RWDATONLY;
if ((udpoptp->nwuo_flags & NWUO_LOCPORT_MASK) == NWUO_LP_ANY)
udpopt.nwuo_flags |= NWUO_LP_SEL;
udpopt.nwuo_remaddr= sinp->sin_addr.s_addr;

View file

@ -120,14 +120,38 @@ static ssize_t _udp_recvfrom(int socket, void *_RESTRICT buffer, size_t length,
if (udpoptp->nwuo_flags & NWUO_RWDATONLY)
{
if (address != NULL &&
(udpoptp->nwuo_flags & (NWUO_RA_SET | NWUO_RP_SET)) !=
(NWUO_RA_SET | NWUO_RP_SET))
{
#if DEBUG
fprintf(stderr,
"recvfrom(udp): NWUO_RWDATONLY not implemented\n");
"recvfrom(udp): RWDATONLY on unconnected socket\n");
#endif
errno= ENOSYS;
errno= ENOTCONN;
return -1;
}
r= read(socket, buffer, length);
if (r == -1)
return r;
if (address != NULL)
{
sin.sin_family= AF_INET;
sin.sin_addr.s_addr= udpoptp->nwuo_remaddr;
sin.sin_port= udpoptp->nwuo_remport;
len= *address_len;
if (len > sizeof(sin))
len= sizeof(sin);
memcpy(address, &sin, len);
*address_len= sizeof(sin);
}
return r;
}
buflen= sizeof(*io_hdrp) + length;
if (buflen < length)
{