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
6968nodata :
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
126125nodata :
127- * bssid = ( struct ether_addr ) {} ;
126+ * ret_bssid = ETHER_ADDR_NULL ;
128127 return 0 ;
129128}
0 commit comments