diff mbox

[v5,07/25] ctrl unix: use sockaddr_storage

Message ID 1457083241-7492-8-git-send-email-janusz.dziedzic@tieto.com
State Accepted
Headers show

Commit Message

Janusz.Dziedzic@tieto.com March 4, 2016, 9:20 a.m. UTC
Signed-off-by: Janusz Dziedzic <janusz.dziedzic@tieto.com>
---
 hostapd/ctrl_iface.c             | 23 +++++++++++------------
 src/common/ctrl_iface_common.c   | 16 ++++++++--------
 src/common/ctrl_iface_common.h   |  8 ++++----
 wpa_supplicant/ctrl_iface_unix.c | 21 +++++++++------------
 4 files changed, 32 insertions(+), 36 deletions(-)
diff mbox

Patch

diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c
index 6990373..4d90155 100644
--- a/hostapd/ctrl_iface.c
+++ b/hostapd/ctrl_iface.c
@@ -59,7 +59,7 @@  static void hostapd_ctrl_iface_send(struct hostapd_data *hapd, int level,
 
 
 static int hostapd_ctrl_iface_attach(struct hostapd_data *hapd,
-				     struct sockaddr_un *from,
+				     struct sockaddr_storage *from,
 				     socklen_t fromlen)
 {
 	return ctrl_iface_attach(&hapd->ctrl_dst, from, fromlen);
@@ -67,7 +67,7 @@  static int hostapd_ctrl_iface_attach(struct hostapd_data *hapd,
 
 
 static int hostapd_ctrl_iface_detach(struct hostapd_data *hapd,
-				     struct sockaddr_un *from,
+				     struct sockaddr_storage *from,
 				     socklen_t fromlen)
 {
 	return ctrl_iface_detach(&hapd->ctrl_dst, from, fromlen);
@@ -75,7 +75,7 @@  static int hostapd_ctrl_iface_detach(struct hostapd_data *hapd,
 
 
 static int hostapd_ctrl_iface_level(struct hostapd_data *hapd,
-				    struct sockaddr_un *from,
+				    struct sockaddr_storage *from,
 				    socklen_t fromlen,
 				    char *level)
 {
@@ -2061,7 +2061,7 @@  static int hostapd_ctrl_iface_track_sta_list(struct hostapd_data *hapd,
 static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd,
 					      char *buf, char *reply,
 					      int reply_size,
-					      struct sockaddr_un *from,
+					      struct sockaddr_storage *from,
 					      socklen_t fromlen)
 {
 	int reply_len, res;
@@ -2314,7 +2314,7 @@  static void hostapd_ctrl_iface_receive(int sock, void *eloop_ctx,
 	struct hostapd_data *hapd = eloop_ctx;
 	char buf[4096];
 	int res;
-	struct sockaddr_un from;
+	struct sockaddr_storage from;
 	socklen_t fromlen = sizeof(from);
 	char *reply;
 	const int reply_size = 4096;
@@ -2604,7 +2604,7 @@  static int hostapd_ctrl_iface_remove(struct hapd_interfaces *interfaces,
 
 
 static int hostapd_global_ctrl_iface_attach(struct hapd_interfaces *interfaces,
-					    struct sockaddr_un *from,
+					    struct sockaddr_storage *from,
 					    socklen_t fromlen)
 {
 	return ctrl_iface_attach(&interfaces->global_ctrl_dst, from, fromlen);
@@ -2612,7 +2612,7 @@  static int hostapd_global_ctrl_iface_attach(struct hapd_interfaces *interfaces,
 
 
 static int hostapd_global_ctrl_iface_detach(struct hapd_interfaces *interfaces,
-					    struct sockaddr_un *from,
+					    struct sockaddr_storage *from,
 					    socklen_t fromlen)
 {
 	return ctrl_iface_detach(&interfaces->global_ctrl_dst, from, fromlen);
@@ -2817,7 +2817,7 @@  static int hostapd_global_ctrl_iface_ifname(struct hapd_interfaces *interfaces,
 					    const char *ifname,
 					    char *buf, char *reply,
 					    int reply_size,
-					    struct sockaddr_un *from,
+					    struct sockaddr_storage *from,
 					    socklen_t fromlen)
 {
 	struct hostapd_data *hapd;
@@ -2843,7 +2843,7 @@  static void hostapd_global_ctrl_iface_receive(int sock, void *eloop_ctx,
 	void *interfaces = eloop_ctx;
 	char buf[256];
 	int res;
-	struct sockaddr_un from;
+	struct sockaddr_storage from;
 	socklen_t fromlen = sizeof(from);
 	char *reply;
 	int reply_len;
@@ -3157,9 +3157,8 @@  static void hostapd_ctrl_iface_send(struct hostapd_data *hapd, int level,
 	idx = 0;
 	dl_list_for_each_safe(dst, next, ctrl_dst, struct wpa_ctrl_dst, list) {
 		if (level >= dst->debug_level) {
-			wpa_hexdump(MSG_DEBUG, "CTRL_IFACE monitor send",
-				    (u8 *) dst->addr.sun_path, dst->addrlen -
-				    offsetof(struct sockaddr_un, sun_path));
+			sockaddr_print(MSG_DEBUG, "CTRL_IFACE monitor send",
+				       &dst->addr, dst->addrlen);
 			msg.msg_name = &dst->addr;
 			msg.msg_namelen = dst->addrlen;
 			if (sendmsg(s, &msg, 0) < 0) {
diff --git a/src/common/ctrl_iface_common.c b/src/common/ctrl_iface_common.c
index 82ff276..4d79569 100644
--- a/src/common/ctrl_iface_common.c
+++ b/src/common/ctrl_iface_common.c
@@ -84,7 +84,7 @@  void sockaddr_print(int level, char *msg, struct sockaddr_storage *sock, socklen
 }
 
 int ctrl_iface_attach(struct dl_list *ctrl_dst,
-		      struct sockaddr_un *from,
+		      struct sockaddr_storage *from,
 		      socklen_t fromlen)
 {
 	struct wpa_ctrl_dst *dst;
@@ -97,20 +97,20 @@  int ctrl_iface_attach(struct dl_list *ctrl_dst,
 	dst->debug_level = MSG_INFO;
 	dl_list_add(ctrl_dst, &dst->list);
 
-	sockaddr_print(MSG_DEBUG, "CTRL_IFACE monitor attached", (struct sockaddr_storage *)from, fromlen);
+	sockaddr_print(MSG_DEBUG, "CTRL_IFACE monitor attached", from, fromlen);
 	return 0;
 }
 
 
 int ctrl_iface_detach(struct dl_list *ctrl_dst,
-		      struct sockaddr_un *from,
+		      struct sockaddr_storage *from,
 		      socklen_t fromlen)
 {
 	struct wpa_ctrl_dst *dst;
 
 	dl_list_for_each(dst, ctrl_dst, struct wpa_ctrl_dst, list) {
-		if (!sockaddr_compare((struct sockaddr_storage *)from, (struct sockaddr_storage *)&dst->addr)) {
-			sockaddr_print(MSG_DEBUG, "CTRL_IFACE monitor detached", (struct sockaddr_storage *)from, fromlen);
+		if (!sockaddr_compare(from, &dst->addr)) {
+			sockaddr_print(MSG_DEBUG, "CTRL_IFACE monitor detached", from, fromlen);
 			dl_list_del(&dst->list);
 			os_free(dst);
 			return 0;
@@ -121,7 +121,7 @@  int ctrl_iface_detach(struct dl_list *ctrl_dst,
 }
 
 int ctrl_iface_level(struct dl_list *ctrl_dst,
-		     struct sockaddr_un *from,
+		     struct sockaddr_storage *from,
 		     socklen_t fromlen,
 		     char *level)
 {
@@ -130,8 +130,8 @@  int ctrl_iface_level(struct dl_list *ctrl_dst,
 	wpa_printf(MSG_DEBUG, "CTRL_IFACE LEVEL %s", level);
 
 	dl_list_for_each(dst, ctrl_dst, struct wpa_ctrl_dst, list) {
-		if (!sockaddr_compare((struct sockaddr_storage *)from, (struct sockaddr_storage *)&dst->addr)) {
-			sockaddr_print(MSG_DEBUG, "CTRL_IFACE changed monitor level", (struct sockaddr_storage *)from, fromlen);
+		if (!sockaddr_compare(from, &dst->addr)) {
+			sockaddr_print(MSG_DEBUG, "CTRL_IFACE changed monitor level", from, fromlen);
 			dst->debug_level = atoi(level);
 			return 0;
 		}
diff --git a/src/common/ctrl_iface_common.h b/src/common/ctrl_iface_common.h
index b693847..dcd88e0 100644
--- a/src/common/ctrl_iface_common.h
+++ b/src/common/ctrl_iface_common.h
@@ -13,7 +13,7 @@ 
 
 struct wpa_ctrl_dst {
 	struct dl_list list;
-	struct sockaddr_un addr;
+	struct sockaddr_storage addr;
 	socklen_t addrlen;
 	int debug_level;
 	int errors;
@@ -23,13 +23,13 @@  int sockaddr_compare(struct sockaddr_storage *a, struct sockaddr_storage *b);
 void sockaddr_print(int level, char *msg, struct sockaddr_storage *sock, socklen_t socklen);
 
 int ctrl_iface_attach(struct dl_list *ctrl_dst,
-		      struct sockaddr_un *from,
+		      struct sockaddr_storage *from,
 		       socklen_t fromlen);
 int ctrl_iface_detach(struct dl_list *ctrl_dst,
-		      struct sockaddr_un *from,
+		      struct sockaddr_storage *from,
 		      socklen_t fromlen);
 int ctrl_iface_level(struct dl_list *ctrl_dst,
-		     struct sockaddr_un *from,
+		     struct sockaddr_storage *from,
 		     socklen_t fromlen,
 		     char *level);
 
diff --git a/wpa_supplicant/ctrl_iface_unix.c b/wpa_supplicant/ctrl_iface_unix.c
index b88e6c1..a79c5a6 100644
--- a/wpa_supplicant/ctrl_iface_unix.c
+++ b/wpa_supplicant/ctrl_iface_unix.c
@@ -101,7 +101,7 @@  static void wpas_ctrl_sock_debug(const char *title, int sock, const char *buf,
 
 
 static int wpa_supplicant_ctrl_iface_attach(struct dl_list *ctrl_dst,
-					    struct sockaddr_un *from,
+					    struct sockaddr_storage *from,
 					    socklen_t fromlen, int global)
 {
 	return ctrl_iface_attach(ctrl_dst, from, fromlen);
@@ -109,7 +109,7 @@  static int wpa_supplicant_ctrl_iface_attach(struct dl_list *ctrl_dst,
 
 
 static int wpa_supplicant_ctrl_iface_detach(struct dl_list *ctrl_dst,
-					    struct sockaddr_un *from,
+					    struct sockaddr_storage *from,
 					    socklen_t fromlen)
 {
 	return ctrl_iface_detach(ctrl_dst, from, fromlen);
@@ -117,7 +117,7 @@  static int wpa_supplicant_ctrl_iface_detach(struct dl_list *ctrl_dst,
 
 
 static int wpa_supplicant_ctrl_iface_level(struct ctrl_iface_priv *priv,
-					   struct sockaddr_un *from,
+					   struct sockaddr_storage *from,
 					   socklen_t fromlen,
 					   char *level)
 {
@@ -134,7 +134,7 @@  static void wpa_supplicant_ctrl_iface_receive(int sock, void *eloop_ctx,
 	struct ctrl_iface_priv *priv = sock_ctx;
 	char buf[4096];
 	int res;
-	struct sockaddr_un from;
+	struct sockaddr_storage from;
 	socklen_t fromlen = sizeof(from);
 	char *reply = NULL, *reply_buf = NULL;
 	size_t reply_len = 0;
@@ -933,16 +933,13 @@  static void wpa_supplicant_ctrl_iface_send(struct wpa_supplicant *wpa_s,
 		if (level < dst->debug_level)
 			continue;
 
-		printf_encode(addr_txt, sizeof(addr_txt),
-			      (u8 *) dst->addr.sun_path, dst->addrlen -
-			      offsetof(struct sockaddr_un, sun_path));
 		msg.msg_name = (void *) &dst->addr;
 		msg.msg_namelen = dst->addrlen;
 		wpas_ctrl_sock_debug("ctrl_sock-sendmsg", sock, buf, len);
 		if (sendmsg(sock, &msg, MSG_DONTWAIT) >= 0) {
-			wpa_printf(MSG_MSGDUMP,
-				   "CTRL_IFACE monitor sent successfully to %s",
-				   addr_txt);
+			sockaddr_print(MSG_MSGDUMP,
+				       "CTRL_IFACE monitor sent successfully to ",
+				       &dst->addr, dst->addrlen);
 			dst->errors = 0;
 			continue;
 		}
@@ -988,7 +985,7 @@  void wpa_supplicant_ctrl_iface_wait(struct ctrl_iface_priv *priv)
 {
 	char buf[256];
 	int res;
-	struct sockaddr_un from;
+	struct sockaddr_storage from;
 	socklen_t fromlen = sizeof(from);
 
 	if (priv->sock == -1)
@@ -1051,7 +1048,7 @@  static void wpa_supplicant_global_ctrl_iface_receive(int sock, void *eloop_ctx,
 	struct ctrl_iface_global_priv *priv = sock_ctx;
 	char buf[4096];
 	int res;
-	struct sockaddr_un from;
+	struct sockaddr_storage from;
 	socklen_t fromlen = sizeof(from);
 	char *reply = NULL, *reply_buf = NULL;
 	size_t reply_len;