wangchen61698 commented on code in PR #10319:
URL: https://github.com/apache/nuttx/pull/10319#discussion_r1300819608
##########
net/inet/ipv4_setsockopt.c:
##########
@@ -208,10 +208,83 @@ int ipv4_setsockopt(FAR struct socket *psock, int option,
}
break;
- /* The following IPv4 socket options are defined, but not implemented */
-
case IP_MULTICAST_IF: /* Set local device for a multicast
* socket */
+#if defined(NET_UDP_HAVE_STACK) && defined(CONFIG_NET_BINDTODEVICE)
+
+ {
+ FAR struct udp_conn_s *conn;
+ FAR struct net_driver_s *dev;
+ struct ip_mreqn mreq;
+
+ conn = psock->s_conn;
+ if (value == NULL || value_len == 0)
+ {
+ ret = -EINVAL;
+ break;
+ }
+
+ if (value_len >= sizeof(struct ip_mreqn))
+ {
+ memcpy(&mreq, value, sizeof(mreq));
+ }
+ else
+ {
+ memset(&mreq, 0, sizeof(mreq));
+ if (value_len >= sizeof(struct ip_mreq))
+ {
+ memcpy(&mreq, value, sizeof(struct ip_mreq));
+ }
+ else if (value_len >= sizeof(struct in_addr))
+ {
+ memcpy(&mreq.imr_multiaddr,
+ value, sizeof(struct in_addr));
+ }
+ }
+
+ if (!mreq.imr_ifindex)
+ {
+ if (net_ipv4addr_cmp(mreq.imr_multiaddr.s_addr, INADDR_ANY))
+ {
+ conn->mreq.imr_interface.s_addr = 0;
+ conn->mreq.imr_ifindex = 0;
+ ret = OK;
+ break;
+ }
+
+ dev = netdev_findby_lipv4addr(mreq.imr_multiaddr.s_addr);
+ if (dev)
+ {
+ mreq.imr_ifindex = dev->d_ifindex;
+ }
+ }
+ else
+ {
+ dev = netdev_findbyindex(mreq.imr_ifindex);
+ }
+
+ if (!dev)
+ {
+ ret = -EADDRNOTAVAIL;
+ break;
+ }
+
+ if (conn->sconn.s_boundto &&
Review Comment:
ditto
##########
net/inet/ipv6_setsockopt.c:
##########
@@ -103,10 +105,41 @@ int ipv6_setsockopt(FAR struct socket *psock, int option,
}
break;
- /* The following IPv6 socket options are defined, but not implemented */
-
case IPV6_MULTICAST_IF: /* Interface to use for outgoing multicast
* packets */
+#if defined(NET_UDP_HAVE_STACK) && defined(CONFIG_NET_BINDTODEVICE)
Review Comment:
ditto
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]