You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by bt...@apache.org on 2020/12/05 18:45:06 UTC
[incubator-nuttx] 03/03: net/setsockopt/IP_MULTICAST_TTL: add
handles of different prototypes
This is an automated email from the ASF dual-hosted git repository.
btashton pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit e37001f2694072dc6be5d7e406f22498148ea203
Author: chao.an <an...@xiaomi.com>
AuthorDate: Sat Dec 5 18:21:18 2020 +0800
net/setsockopt/IP_MULTICAST_TTL: add handles of different prototypes
Reference here:
https://github.com/torvalds/linux/blob/b3298500b23f0b53a8d81e0d5ad98a29db71f4f0/net/ipv4/ip_sockglue.c#L923-L932
Signed-off-by: chao.an <an...@xiaomi.com>
---
net/inet/ipv4_setsockopt.c | 30 ++++++++++++++++--------------
1 file changed, 16 insertions(+), 14 deletions(-)
diff --git a/net/inet/ipv4_setsockopt.c b/net/inet/ipv4_setsockopt.c
index 6c1ca94..7d08910 100644
--- a/net/inet/ipv4_setsockopt.c
+++ b/net/inet/ipv4_setsockopt.c
@@ -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
* outgoing multicast packets */
{
+ FAR struct udp_conn_s *conn;
+ int ttl;
+
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;
}
else
{
- FAR struct udp_conn_s *conn;
- int ttl = *(FAR int *)value;
-
- if (ttl <= 0 || ttl > 255)
- {
- ret = -EINVAL;
- }
- else
- {
- conn = (FAR struct udp_conn_s *)psock->s_conn;
- conn->ttl = ttl;
- ret = OK;
- }
+ conn = (FAR struct udp_conn_s *)psock->s_conn;
+ conn->ttl = ttl;
+ ret = OK;
}
}
break;