Support for read/write on connected UDP sockets
This commit is contained in:
parent
3926b70b22
commit
4d4cb8fa24
@ -110,7 +110,7 @@ static int _udp_connect(int socket, const struct sockaddr *address,
|
|||||||
if (address == NULL)
|
if (address == NULL)
|
||||||
{
|
{
|
||||||
/* Unset remote address */
|
/* 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);
|
r= ioctl(socket, NWIOSUDPOPT, &udpopt);
|
||||||
return r;
|
return r;
|
||||||
@ -127,7 +127,7 @@ static int _udp_connect(int socket, const struct sockaddr *address,
|
|||||||
errno= EINVAL;
|
errno= EINVAL;
|
||||||
return -1;
|
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)
|
if ((udpoptp->nwuo_flags & NWUO_LOCPORT_MASK) == NWUO_LP_ANY)
|
||||||
udpopt.nwuo_flags |= NWUO_LP_SEL;
|
udpopt.nwuo_flags |= NWUO_LP_SEL;
|
||||||
udpopt.nwuo_remaddr= sinp->sin_addr.s_addr;
|
udpopt.nwuo_remaddr= sinp->sin_addr.s_addr;
|
||||||
|
@ -120,12 +120,36 @@ static ssize_t _udp_recvfrom(int socket, void *_RESTRICT buffer, size_t length,
|
|||||||
|
|
||||||
if (udpoptp->nwuo_flags & NWUO_RWDATONLY)
|
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
|
#if DEBUG
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"recvfrom(udp): NWUO_RWDATONLY not implemented\n");
|
"recvfrom(udp): RWDATONLY on unconnected socket\n");
|
||||||
#endif
|
#endif
|
||||||
errno= ENOSYS;
|
errno= ENOTCONN;
|
||||||
return -1;
|
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;
|
buflen= sizeof(*io_hdrp) + length;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user