net/setsockopt/IP_MULTICAST_TTL: add handles of different prototypes
Reference here:
b3298500b2/net/ipv4/ip_sockglue.c (L923-L932)
Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
parent
5ad2c931a3
commit
e37001f269
@ -192,26 +192,28 @@ int ipv4_setsockopt(FAR struct socket *psock, int option,
|
|||||||
case IP_MULTICAST_TTL: /* Set/read the time-to-live value of
|
case IP_MULTICAST_TTL: /* Set/read the time-to-live value of
|
||||||
* outgoing multicast packets */
|
* outgoing multicast packets */
|
||||||
{
|
{
|
||||||
|
FAR struct udp_conn_s *conn;
|
||||||
|
int ttl;
|
||||||
|
|
||||||
if (psock->s_type != SOCK_DGRAM ||
|
if (psock->s_type != SOCK_DGRAM ||
|
||||||
value_len != sizeof(int))
|
value == NULL || value_len == 0)
|
||||||
|
{
|
||||||
|
ret = -EINVAL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ttl = (value_len >= sizeof(int)) ?
|
||||||
|
*(FAR int *)value : (int)*(FAR unsigned char *)value;
|
||||||
|
|
||||||
|
if (ttl <= 0 || ttl > 255)
|
||||||
{
|
{
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FAR struct udp_conn_s *conn;
|
conn = (FAR struct udp_conn_s *)psock->s_conn;
|
||||||
int ttl = *(FAR int *)value;
|
conn->ttl = ttl;
|
||||||
|
ret = OK;
|
||||||
if (ttl <= 0 || ttl > 255)
|
|
||||||
{
|
|
||||||
ret = -EINVAL;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
conn = (FAR struct udp_conn_s *)psock->s_conn;
|
|
||||||
conn->ttl = ttl;
|
|
||||||
ret = OK;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user