Skip to content

Commit ae2b86d

Browse files
committed
wifi-util: add "ret_" prefix for arguments which store results
1 parent a1d2ae0 commit ae2b86d

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

src/shared/wifi-util.c

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
#include "string-util.h"
55
#include "wifi-util.h"
66

7-
int wifi_get_interface(sd_netlink *genl, int ifindex, enum nl80211_iftype *iftype, char **ssid) {
7+
int wifi_get_interface(sd_netlink *genl, int ifindex, enum nl80211_iftype *ret_iftype, char **ret_ssid) {
88
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL, *reply = NULL;
9+
_cleanup_free_ char *ssid = NULL;
910
const char *family;
11+
uint32_t iftype;
1012
int r;
1113

1214
assert(genl);
@@ -47,41 +49,38 @@ int wifi_get_interface(sd_netlink *genl, int ifindex, enum nl80211_iftype *iftyp
4749
goto nodata;
4850
}
4951

50-
if (iftype) {
51-
uint32_t t;
52+
r = sd_netlink_message_read_u32(reply, NL80211_ATTR_IFTYPE, &iftype);
53+
if (r < 0)
54+
return log_debug_errno(r, "Failed to get NL80211_ATTR_IFTYPE attribute: %m");
5255

53-
r = sd_netlink_message_read_u32(reply, NL80211_ATTR_IFTYPE, &t);
54-
if (r < 0)
55-
return log_debug_errno(r, "Failed to get NL80211_ATTR_IFTYPE attribute: %m");
56-
*iftype = t;
57-
}
56+
r = sd_netlink_message_read_string_strdup(reply, NL80211_ATTR_SSID, &ssid);
57+
if (r < 0 && r != -ENODATA)
58+
return log_debug_errno(r, "Failed to get NL80211_ATTR_SSID attribute: %m");
5859

59-
if (ssid) {
60-
r = sd_netlink_message_read_string_strdup(reply, NL80211_ATTR_SSID, ssid);
61-
if (r == -ENODATA)
62-
*ssid = NULL;
63-
else if (r < 0)
64-
return log_debug_errno(r, "Failed to get NL80211_ATTR_SSID attribute: %m");
65-
}
60+
if (ret_iftype)
61+
*ret_iftype = iftype;
62+
63+
if (ret_ssid)
64+
*ret_ssid = TAKE_PTR(ssid);
6665

6766
return 1;
6867

6968
nodata:
70-
if (iftype)
71-
*iftype = 0;
72-
if (ssid)
73-
*ssid = NULL;
69+
if (ret_iftype)
70+
*ret_iftype = 0;
71+
if (ret_ssid)
72+
*ret_ssid = NULL;
7473
return 0;
7574
}
7675

77-
int wifi_get_station(sd_netlink *genl, int ifindex, struct ether_addr *bssid) {
76+
int wifi_get_station(sd_netlink *genl, int ifindex, struct ether_addr *ret_bssid) {
7877
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL, *reply = NULL;
7978
const char *family;
8079
int r;
8180

8281
assert(genl);
8382
assert(ifindex > 0);
84-
assert(bssid);
83+
assert(ret_bssid);
8584

8685
r = sd_genl_message_new(genl, NL80211_GENL_NAME, NL80211_CMD_GET_STATION, &m);
8786
if (r < 0)
@@ -115,7 +114,7 @@ int wifi_get_station(sd_netlink *genl, int ifindex, struct ether_addr *bssid) {
115114
goto nodata;
116115
}
117116

118-
r = sd_netlink_message_read_ether_addr(reply, NL80211_ATTR_MAC, bssid);
117+
r = sd_netlink_message_read_ether_addr(reply, NL80211_ATTR_MAC, ret_bssid);
119118
if (r == -ENODATA)
120119
goto nodata;
121120
if (r < 0)
@@ -124,6 +123,6 @@ int wifi_get_station(sd_netlink *genl, int ifindex, struct ether_addr *bssid) {
124123
return 1;
125124

126125
nodata:
127-
*bssid = (struct ether_addr) {};
126+
*ret_bssid = ETHER_ADDR_NULL;
128127
return 0;
129128
}

src/shared/wifi-util.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
#pragma once
44

55
#include <linux/nl80211.h>
6-
#include <net/ethernet.h>
76

87
#include "sd-netlink.h"
98

10-
int wifi_get_interface(sd_netlink *genl, int ifindex, enum nl80211_iftype *iftype, char **ssid);
11-
int wifi_get_station(sd_netlink *genl, int ifindex, struct ether_addr *bssid);
9+
#include "ether-addr-util.h"
10+
11+
int wifi_get_interface(sd_netlink *genl, int ifindex, enum nl80211_iftype *ret_iftype, char **ret_ssid);
12+
int wifi_get_station(sd_netlink *genl, int ifindex, struct ether_addr *ret_bssid);

0 commit comments

Comments
 (0)