[PATCH 4/9] wpa_supplicant: use sockaddr_storage for ctrl UDP iface

Janusz Dziedzic janusz.dziedzic
Wed Sep 23 05:04:14 PDT 2015


Kill not needed #ifdefs and use sockaddr_storage common
IPv4/IPv6 structure for ctrl UDP iface.

Signed-off-by: Janusz Dziedzic <janusz.dziedzic at tieto.com>
---
 wpa_supplicant/ctrl_iface_udp.c | 38 +++++++++-----------------------------
 1 file changed, 9 insertions(+), 29 deletions(-)

diff --git a/wpa_supplicant/ctrl_iface_udp.c b/wpa_supplicant/ctrl_iface_udp.c
index e219ff4..c5ba92d 100644
--- a/wpa_supplicant/ctrl_iface_udp.c
+++ b/wpa_supplicant/ctrl_iface_udp.c
@@ -30,11 +30,7 @@
  */
 struct wpa_ctrl_dst {
 	struct wpa_ctrl_dst *next;
-#ifdef CONFIG_CTRL_IFACE_UDP_IPV6
-	struct sockaddr_in6 addr;
-#else /* CONFIG_CTRL_IFACE_UDP_IPV6 */
-	struct sockaddr_in addr;
-#endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
+	struct sockaddr_storage addr;
 	socklen_t addrlen;
 	int debug_level;
 	int errors;
@@ -88,11 +84,7 @@ static int sockaddr_compare(struct sockaddr *a, struct sockaddr *b)
 }
 
 static int wpa_supplicant_ctrl_iface_attach(struct ctrl_iface_priv *priv,
-#ifdef CONFIG_CTRL_IFACE_UDP_IPV6
-					    struct sockaddr_in6 *from,
-#else /* CONFIG_CTRL_IFACE_UDP_IPV6 */
-					    struct sockaddr_in *from,
-#endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
+					    struct sockaddr_storage *from,
 					    socklen_t fromlen)
 {
 	struct wpa_ctrl_dst *dst;
@@ -102,7 +94,7 @@ static int wpa_supplicant_ctrl_iface_attach(struct ctrl_iface_priv *priv,
 	dst = os_zalloc(sizeof(*dst));
 	if (dst == NULL)
 		return -1;
-	os_memcpy(&dst->addr, from, sizeof(*from));
+	os_memcpy(&dst->addr, from, fromlen);
 	dst->addrlen = fromlen;
 	dst->debug_level = MSG_INFO;
 	dst->next = priv->ctrl_dst;
@@ -120,11 +112,7 @@ static int wpa_supplicant_ctrl_iface_attach(struct ctrl_iface_priv *priv,
 
 
 static int wpa_supplicant_ctrl_iface_detach(struct ctrl_iface_priv *priv,
-#ifdef CONFIG_CTRL_IFACE_UDP_IPV6
-					    struct sockaddr_in6 *from,
-#else /* CONFIG_CTRL_IFACE_UDP_IPV6 */
-					    struct sockaddr_in *from,
-#endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
+					    struct sockaddr_storage *from,
 					    socklen_t fromlen)
 {
 	struct wpa_ctrl_dst *dst, *prev = NULL;
@@ -157,11 +145,7 @@ static int wpa_supplicant_ctrl_iface_detach(struct ctrl_iface_priv *priv,
 
 
 static int wpa_supplicant_ctrl_iface_level(struct ctrl_iface_priv *priv,
-#ifdef CONFIG_CTRL_IFACE_UDP_IPV6
-					   struct sockaddr_in6 *from,
-#else /* CONFIG_CTRL_IFACE_UDP_IPV6 */
-					   struct sockaddr_in *from,
-#endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
+					   struct sockaddr_storage *from,
 					   socklen_t fromlen,
 					   char *level)
 {
@@ -218,11 +202,7 @@ static void wpa_supplicant_ctrl_iface_receive(int sock, void *eloop_ctx,
 	struct ctrl_iface_priv *priv = sock_ctx;
 	char buf[256], *pos;
 	int res;
-#ifdef CONFIG_CTRL_IFACE_UDP_IPV6
-	struct sockaddr_in6 from;
-#else /* CONFIG_CTRL_IFACE_UDP_IPV6 */
-	struct sockaddr_in from;
-#endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
+	struct sockaddr_storage from;
 	socklen_t fromlen = sizeof(from);
 	char *reply = NULL;
 	size_t reply_len = 0;
@@ -274,19 +254,19 @@ static void wpa_supplicant_ctrl_iface_receive(int sock, void *eloop_ctx,
 		pos++;
 
 	if (os_strcmp(pos, "ATTACH") == 0) {
-		if (wpa_supplicant_ctrl_iface_attach(priv, &from, fromlen))
+		if (wpa_supplicant_ctrl_iface_attach(priv, (struct sockaddr_storage *) &from, fromlen))
 			reply_len = 1;
 		else {
 			new_attached = 1;
 			reply_len = 2;
 		}
 	} else if (os_strcmp(pos, "DETACH") == 0) {
-		if (wpa_supplicant_ctrl_iface_detach(priv, &from, fromlen))
+		if (wpa_supplicant_ctrl_iface_detach(priv, (struct sockaddr_storage *)&from, fromlen))
 			reply_len = 1;
 		else
 			reply_len = 2;
 	} else if (os_strncmp(pos, "LEVEL ", 6) == 0) {
-		if (wpa_supplicant_ctrl_iface_level(priv, &from, fromlen,
+		if (wpa_supplicant_ctrl_iface_level(priv, (struct sockaddr_storage *)&from, fromlen,
 						    pos + 6))
 			reply_len = 1;
 		else
-- 
1.9.1




More information about the Hostap mailing list