You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/08/24 16:11:28 UTC

[incubator-nuttx-apps] branch master updated: net/sockopt: move BINDTODEVICE to socket level

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git


The following commit(s) were added to refs/heads/master by this push:
     new 995aef9d9 net/sockopt: move BINDTODEVICE to socket level
995aef9d9 is described below

commit 995aef9d9963b442d879a7e4764c3e8bc6dc32ef
Author: chao.an <an...@xiaomi.com>
AuthorDate: Wed Aug 24 10:37:49 2022 +0800

    net/sockopt: move BINDTODEVICE to socket level
    
    rename the UDP_BINDTODEVICE to SO_BINDTODEVICE to follow the linux
    style to be compatible with non-UDP protocol binding requirements
    
    Signed-off-by: chao.an <an...@xiaomi.com>
---
 netutils/dhcpc/Kconfig | 2 +-
 netutils/dhcpc/dhcpc.c | 4 ++--
 netutils/dhcpd/dhcpd.c | 4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/netutils/dhcpc/Kconfig b/netutils/dhcpc/Kconfig
index 5504c87a0..49e55856c 100644
--- a/netutils/dhcpc/Kconfig
+++ b/netutils/dhcpc/Kconfig
@@ -7,7 +7,7 @@ config NETUTILS_DHCPC
 	bool "DHCP client"
 	default n
 	depends on NET_UDP && NET_BROADCAST && NET_IPv4
-	select NET_UDP_BINDTODEVICE if !NET_UDP_NO_STACK
+	select NET_BINDTODEVICE if !NET_UDP_NO_STACK
 	---help---
 		Enable support for the DHCP client.
 
diff --git a/netutils/dhcpc/dhcpc.c b/netutils/dhcpc/dhcpc.c
index 2f6b918da..5502f897c 100644
--- a/netutils/dhcpc/dhcpc.c
+++ b/netutils/dhcpc/dhcpc.c
@@ -565,14 +565,14 @@ FAR void *dhcpc_open(FAR const char *interface, FAR const void *macaddr,
           return NULL;
         }
 
-#ifdef CONFIG_NET_UDP_BINDTODEVICE
+#ifdef CONFIG_NET_BINDTODEVICE
       /* Bind socket to interface, because UDP packets have to be sent to the
        * broadcast address at a moment when it is not possible to decide the
        * target network device using the local or remote address (which is,
        * by definition and purpose of DHCP, undefined yet).
        */
 
-      ret = setsockopt(pdhcpc->sockfd, IPPROTO_UDP, UDP_BINDTODEVICE,
+      ret = setsockopt(pdhcpc->sockfd, SOL_SOCKET, SO_BINDTODEVICE,
                        pdhcpc->interface, strlen(pdhcpc->interface));
       if (ret < 0)
         {
diff --git a/netutils/dhcpd/dhcpd.c b/netutils/dhcpd/dhcpd.c
index 244e6eabf..d5eb45569 100644
--- a/netutils/dhcpd/dhcpd.c
+++ b/netutils/dhcpd/dhcpd.c
@@ -864,14 +864,14 @@ static inline int dhcpd_socket(FAR const char *interface)
     }
 #endif
 
-#ifdef CONFIG_NET_UDP_BINDTODEVICE
+#ifdef CONFIG_NET_BINDTODEVICE
   /* Bind socket to interface, because UDP packets have to be sent to the
    * broadcast address at a moment when it is not possible to decide the
    * target network device using the local or remote address (which is,
    * by definition and purpose of DHCP, undefined yet).
    */
 
-  if (setsockopt(sockfd, IPPROTO_UDP, UDP_BINDTODEVICE,
+  if (setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE,
                  interface, strlen(interface)) < 0)
     {
       ninfo("ERROR: setsockopt UDP_BINDTODEVICE failed: %d\n", errno);