aboutsummaryrefslogtreecommitdiffstats
path: root/wpa_supplicant/ctrl_iface_unix.c
diff options
context:
space:
mode:
authorJouni Malinen <jouni@qca.qualcomm.com>2013-09-23 14:52:10 (GMT)
committerJouni Malinen <j@w1.fi>2013-09-23 14:52:10 (GMT)
commit742e715b31e11576706130c90514c701d49abc8d (patch)
treee8304a469fe806bf5182734c64f218a6fc292d0c /wpa_supplicant/ctrl_iface_unix.c
parent6668efda5813b87c43cfb6780c60dfebe0b9da4c (diff)
downloadhostap-742e715b31e11576706130c90514c701d49abc8d.zip
hostap-742e715b31e11576706130c90514c701d49abc8d.tar.gz
hostap-742e715b31e11576706130c90514c701d49abc8d.tar.bz2
Simplify ctrl_iface sendto() use
Prepare reply buffer first for all cases and then use a single sendto() call instead of three calls depending on reply type. This allows simpler error handling for control interface send operations. Signed-hostap: Jouni Malinen <jouni@qca.qualcomm.com>
Diffstat (limited to 'wpa_supplicant/ctrl_iface_unix.c')
-rw-r--r--wpa_supplicant/ctrl_iface_unix.c60
1 files changed, 26 insertions, 34 deletions
diff --git a/wpa_supplicant/ctrl_iface_unix.c b/wpa_supplicant/ctrl_iface_unix.c
index 49489d6..383bab0 100644
--- a/wpa_supplicant/ctrl_iface_unix.c
+++ b/wpa_supplicant/ctrl_iface_unix.c
@@ -143,7 +143,7 @@ static void wpa_supplicant_ctrl_iface_receive(int sock, void *eloop_ctx,
int res;
struct sockaddr_un from;
socklen_t fromlen = sizeof(from);
- char *reply = NULL;
+ char *reply = NULL, *reply_buf = NULL;
size_t reply_len = 0;
int new_attached = 0;
@@ -177,8 +177,17 @@ static void wpa_supplicant_ctrl_iface_receive(int sock, void *eloop_ctx,
else
reply_len = 2;
} else {
- reply = wpa_supplicant_ctrl_iface_process(wpa_s, buf,
- &reply_len);
+ reply_buf = wpa_supplicant_ctrl_iface_process(wpa_s, buf,
+ &reply_len);
+ reply = reply_buf;
+ }
+
+ if (!reply && reply_len == 1) {
+ reply = "FAIL\n";
+ reply_len = 5;
+ } else if (!reply && reply_len == 2) {
+ reply = "OK\n";
+ reply_len = 3;
}
if (reply) {
@@ -188,22 +197,8 @@ static void wpa_supplicant_ctrl_iface_receive(int sock, void *eloop_ctx,
"ctrl_iface sendto failed: %s",
strerror(errno));
}
- os_free(reply);
- } else if (reply_len == 1) {
- if (sendto(sock, "FAIL\n", 5, 0, (struct sockaddr *) &from,
- fromlen) < 0) {
- wpa_dbg(wpa_s, MSG_DEBUG,
- "ctrl_iface sendto failed: %s",
- strerror(errno));
- }
- } else if (reply_len == 2) {
- if (sendto(sock, "OK\n", 3, 0, (struct sockaddr *) &from,
- fromlen) < 0) {
- wpa_dbg(wpa_s, MSG_DEBUG,
- "ctrl_iface sendto failed: %s",
- strerror(errno));
- }
}
+ os_free(reply_buf);
if (new_attached)
eapol_sm_notify_ctrl_attached(wpa_s->eapol);
@@ -708,7 +703,7 @@ static void wpa_supplicant_global_ctrl_iface_receive(int sock, void *eloop_ctx,
int res;
struct sockaddr_un from;
socklen_t fromlen = sizeof(from);
- char *reply = NULL;
+ char *reply = NULL, *reply_buf = NULL;
size_t reply_len;
res = recvfrom(sock, buf, sizeof(buf) - 1, 0,
@@ -733,8 +728,17 @@ static void wpa_supplicant_global_ctrl_iface_receive(int sock, void *eloop_ctx,
else
reply_len = 2;
} else {
- reply = wpa_supplicant_global_ctrl_iface_process(global, buf,
- &reply_len);
+ reply_buf = wpa_supplicant_global_ctrl_iface_process(
+ global, buf, &reply_len);
+ reply = reply_buf;
+ }
+
+ if (!reply && reply_len == 1) {
+ reply = "FAIL\n";
+ reply_len = 5;
+ } else if (!reply && reply_len == 2) {
+ reply = "OK\n";
+ reply_len = 3;
}
if (reply) {
@@ -743,20 +747,8 @@ static void wpa_supplicant_global_ctrl_iface_receive(int sock, void *eloop_ctx,
wpa_printf(MSG_DEBUG, "ctrl_iface sendto failed: %s",
strerror(errno));
}
- os_free(reply);
- } else if (reply_len == 1) {
- if (sendto(sock, "FAIL\n", 5, 0, (struct sockaddr *) &from,
- fromlen) < 0) {
- wpa_printf(MSG_DEBUG, "ctrl_iface sendto failed: %s",
- strerror(errno));
- }
- } else if (reply_len == 2) {
- if (sendto(sock, "OK\n", 3, 0, (struct sockaddr *) &from,
- fromlen) < 0) {
- wpa_printf(MSG_DEBUG, "ctrl_iface sendto failed: %s",
- strerror(errno));
- }
}
+ os_free(reply_buf);
}