]> git.sur5r.net Git - i3/i3status/blob - src/print_wireless_info.c
Detect interface type on DragonFly BSD
[i3/i3status] / src / print_wireless_info.c
1 // vim:ts=4:sw=4:expandtab
2 #include <stdio.h>
3 #include <string.h>
4 #include <yajl/yajl_gen.h>
5 #include <yajl/yajl_version.h>
6
7 #ifdef LINUX
8 #include <errno.h>
9 #include <net/if.h>
10 #include <netlink/netlink.h>
11 #include <netlink/genl/genl.h>
12 #include <netlink/genl/ctrl.h>
13 #include <linux/nl80211.h>
14 #include <linux/if_ether.h>
15 #define IW_ESSID_MAX_SIZE 32
16 #endif
17
18 #ifdef __APPLE__
19 #include <sys/socket.h>
20 #define IW_ESSID_MAX_SIZE 32
21 #endif
22
23 #ifdef __FreeBSD__
24 #include <sys/param.h>
25 #include <sys/ioctl.h>
26 #include <sys/socket.h>
27 #include <ifaddrs.h>
28 #include <net/if.h>
29 #include <net/if_media.h>
30 #include <net80211/ieee80211.h>
31 #include <net80211/ieee80211_ioctl.h>
32 #include <unistd.h>
33 #define IW_ESSID_MAX_SIZE IEEE80211_NWID_LEN
34 #endif
35
36 #ifdef __DragonFly__
37 #include <sys/param.h>
38 #include <sys/ioctl.h>
39 #include <sys/socket.h>
40 #include <ifaddrs.h>
41 #include <stdlib.h>
42 #include <net/if.h>
43 #include <net/if_media.h>
44 #include <netproto/802_11/ieee80211.h>
45 #include <netproto/802_11/ieee80211_ioctl.h>
46 #include <unistd.h>
47 #define IW_ESSID_MAX_SIZE IEEE80211_NWID_LEN
48 #endif
49
50 #ifdef __OpenBSD__
51 #include <sys/ioctl.h>
52 #include <sys/socket.h>
53 #include <net/if.h>
54 #include <sys/select.h>
55 #include <sys/types.h>
56 #include <netinet/in.h>
57 #include <netinet/if_ether.h>
58 #include <net80211/ieee80211.h>
59 #include <net80211/ieee80211_ioctl.h>
60 #define IW_ESSID_MAX_SIZE IEEE80211_NWID_LEN
61 #endif
62
63 #ifdef __NetBSD__
64 #include <sys/types.h>
65 #include <net80211/ieee80211.h>
66 #define IW_ESSID_MAX_SIZE IEEE80211_NWID_LEN
67 #endif
68
69 #include "i3status.h"
70
71 #define WIRELESS_INFO_FLAG_HAS_ESSID (1 << 0)
72 #define WIRELESS_INFO_FLAG_HAS_QUALITY (1 << 1)
73 #define WIRELESS_INFO_FLAG_HAS_SIGNAL (1 << 2)
74 #define WIRELESS_INFO_FLAG_HAS_NOISE (1 << 3)
75 #define WIRELESS_INFO_FLAG_HAS_FREQUENCY (1 << 4)
76
77 #define PERCENT_VALUE(value, total) ((int)(value * 100 / (float)total + 0.5f))
78
79 typedef struct {
80     int flags;
81 #ifdef IW_ESSID_MAX_SIZE
82     char essid[IW_ESSID_MAX_SIZE + 1];
83 #endif
84 #ifdef LINUX
85     uint8_t bssid[ETH_ALEN];
86 #endif
87     int quality;
88     int quality_max;
89     int quality_average;
90     int signal_level;
91     int signal_level_max;
92     int noise_level;
93     int noise_level_max;
94     int bitrate;
95     double frequency;
96 } wireless_info_t;
97
98 #ifdef LINUX
99 // Like iw_print_bitrate, but without the dependency on libiw.
100 static void print_bitrate(char *buffer, int buflen, int bitrate) {
101     const int kilo = 1e3;
102     const int mega = 1e6;
103     const int giga = 1e9;
104
105     const double rate = bitrate;
106     char scale;
107     int divisor;
108
109     if (rate >= giga) {
110         scale = 'G';
111         divisor = giga;
112     } else if (rate >= mega) {
113         scale = 'M';
114         divisor = mega;
115     } else {
116         scale = 'k';
117         divisor = kilo;
118     }
119     snprintf(buffer, buflen, "%g %cb/s", rate / divisor, scale);
120 }
121
122 // Based on NetworkManager/src/platform/wifi/wifi-utils-nl80211.c
123 static uint32_t nl80211_xbm_to_percent(int32_t xbm, int32_t divisor) {
124 #define NOISE_FLOOR_DBM -90
125 #define SIGNAL_MAX_DBM -20
126
127     xbm /= divisor;
128     if (xbm < NOISE_FLOOR_DBM)
129         xbm = NOISE_FLOOR_DBM;
130     if (xbm > SIGNAL_MAX_DBM)
131         xbm = SIGNAL_MAX_DBM;
132
133     return 100 - 70 * (((float)SIGNAL_MAX_DBM - (float)xbm) / ((float)SIGNAL_MAX_DBM - (float)NOISE_FLOOR_DBM));
134 }
135
136 // Based on NetworkManager/src/platform/wifi/wifi-utils-nl80211.c
137 static void find_ssid(uint8_t *ies, uint32_t ies_len, uint8_t **ssid, uint32_t *ssid_len) {
138 #define WLAN_EID_SSID 0
139     *ssid = NULL;
140     *ssid_len = 0;
141
142     while (ies_len > 2 && ies[0] != WLAN_EID_SSID) {
143         ies_len -= ies[1] + 2;
144         ies += ies[1] + 2;
145     }
146     if (ies_len < 2)
147         return;
148     if (ies_len < (uint32_t)(2 + ies[1]))
149         return;
150
151     *ssid_len = ies[1];
152     *ssid = ies + 2;
153 }
154
155 static int gwi_sta_cb(struct nl_msg *msg, void *data) {
156     wireless_info_t *info = data;
157
158     struct nlattr *tb[NL80211_ATTR_MAX + 1];
159     struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
160     struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1];
161     struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1];
162     static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = {
163             [NL80211_STA_INFO_RX_BITRATE] = {.type = NLA_NESTED},
164     };
165
166     static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = {
167             [NL80211_RATE_INFO_BITRATE] = {.type = NLA_U16},
168     };
169
170     if (nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL) < 0)
171         return NL_SKIP;
172
173     if (tb[NL80211_ATTR_STA_INFO] == NULL)
174         return NL_SKIP;
175
176     if (nla_parse_nested(sinfo, NL80211_STA_INFO_MAX, tb[NL80211_ATTR_STA_INFO], stats_policy))
177         return NL_SKIP;
178
179     if (sinfo[NL80211_STA_INFO_RX_BITRATE] == NULL)
180         return NL_SKIP;
181
182     if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX, sinfo[NL80211_STA_INFO_RX_BITRATE], rate_policy))
183         return NL_SKIP;
184
185     if (rinfo[NL80211_RATE_INFO_BITRATE] == NULL)
186         return NL_SKIP;
187
188     // NL80211_RATE_INFO_BITRATE is specified in units of 100 kbit/s, but iw
189     // used to specify bit/s, so we convert to use the same code path.
190     info->bitrate = (int)nla_get_u16(rinfo[NL80211_RATE_INFO_BITRATE]) * 100 * 1000;
191
192     return NL_SKIP;
193 }
194
195 static int gwi_scan_cb(struct nl_msg *msg, void *data) {
196     wireless_info_t *info = data;
197     struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
198     struct nlattr *tb[NL80211_ATTR_MAX + 1];
199     struct nlattr *bss[NL80211_BSS_MAX + 1];
200     struct nla_policy bss_policy[NL80211_BSS_MAX + 1] = {
201             [NL80211_BSS_FREQUENCY] = {.type = NLA_U32},
202             [NL80211_BSS_BSSID] = {.type = NLA_UNSPEC},
203             [NL80211_BSS_INFORMATION_ELEMENTS] = {.type = NLA_UNSPEC},
204             [NL80211_BSS_SIGNAL_MBM] = {.type = NLA_U32},
205             [NL80211_BSS_SIGNAL_UNSPEC] = {.type = NLA_U8},
206             [NL80211_BSS_STATUS] = {.type = NLA_U32},
207     };
208
209     if (nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL) < 0)
210         return NL_SKIP;
211
212     if (tb[NL80211_ATTR_BSS] == NULL)
213         return NL_SKIP;
214
215     if (nla_parse_nested(bss, NL80211_BSS_MAX, tb[NL80211_ATTR_BSS], bss_policy))
216         return NL_SKIP;
217
218     if (bss[NL80211_BSS_STATUS] == NULL)
219         return NL_SKIP;
220
221     const uint32_t status = nla_get_u32(bss[NL80211_BSS_STATUS]);
222
223     if (status != NL80211_BSS_STATUS_ASSOCIATED &&
224         status != NL80211_BSS_STATUS_IBSS_JOINED)
225         return NL_SKIP;
226
227     if (bss[NL80211_BSS_BSSID] == NULL)
228         return NL_SKIP;
229
230     memcpy(info->bssid, nla_data(bss[NL80211_BSS_BSSID]), ETH_ALEN);
231
232     if (bss[NL80211_BSS_FREQUENCY]) {
233         info->flags |= WIRELESS_INFO_FLAG_HAS_FREQUENCY;
234         info->frequency = (double)nla_get_u32(bss[NL80211_BSS_FREQUENCY]) * 1e6;
235     }
236
237     if (bss[NL80211_BSS_SIGNAL_UNSPEC]) {
238         info->flags |= WIRELESS_INFO_FLAG_HAS_SIGNAL;
239         info->signal_level = nla_get_u8(bss[NL80211_BSS_SIGNAL_UNSPEC]);
240         info->signal_level_max = 100;
241
242         info->flags |= WIRELESS_INFO_FLAG_HAS_QUALITY;
243         info->quality = info->signal_level;
244         info->quality_max = 100;
245         info->quality_average = 50;
246     }
247
248     if (bss[NL80211_BSS_SIGNAL_MBM]) {
249         info->flags |= WIRELESS_INFO_FLAG_HAS_SIGNAL;
250         info->signal_level = (int)nla_get_u32(bss[NL80211_BSS_SIGNAL_MBM]) / 100;
251
252         info->flags |= WIRELESS_INFO_FLAG_HAS_QUALITY;
253         info->quality = nl80211_xbm_to_percent(nla_get_u32(bss[NL80211_BSS_SIGNAL_MBM]), 100);
254         info->quality_max = 100;
255         info->quality_average = 50;
256     }
257
258     if (bss[NL80211_BSS_INFORMATION_ELEMENTS]) {
259         uint8_t *ssid;
260         uint32_t ssid_len;
261
262         find_ssid(nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]),
263                   nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]),
264                   &ssid, &ssid_len);
265         if (ssid && ssid_len) {
266             info->flags |= WIRELESS_INFO_FLAG_HAS_ESSID;
267             snprintf(info->essid, sizeof(info->essid), "%.*s", ssid_len, ssid);
268         }
269     }
270
271     return NL_SKIP;
272 }
273 #endif
274
275 static int get_wireless_info(const char *interface, wireless_info_t *info) {
276     memset(info, 0, sizeof(wireless_info_t));
277
278 #ifdef LINUX
279     struct nl_sock *sk = nl_socket_alloc();
280     if (genl_connect(sk) != 0)
281         goto error1;
282
283     if (nl_socket_modify_cb(sk, NL_CB_VALID, NL_CB_CUSTOM, gwi_scan_cb, info) < 0)
284         goto error1;
285
286     const int nl80211_id = genl_ctrl_resolve(sk, "nl80211");
287     if (nl80211_id < 0)
288         goto error1;
289
290     const unsigned int ifidx = if_nametoindex(interface);
291     if (ifidx == 0)
292         goto error1;
293
294     struct nl_msg *msg = NULL;
295     if ((msg = nlmsg_alloc()) == NULL)
296         goto error1;
297
298     if (!genlmsg_put(msg, NL_AUTO_PORT, NL_AUTO_SEQ, nl80211_id, 0, NLM_F_DUMP, NL80211_CMD_GET_SCAN, 0) ||
299         nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifidx) < 0)
300         goto error2;
301
302     if (nl_send_sync(sk, msg) < 0)
303         // nl_send_sync calls nlmsg_free()
304         goto error1;
305     msg = NULL;
306
307     if (nl_socket_modify_cb(sk, NL_CB_VALID, NL_CB_CUSTOM, gwi_sta_cb, info) < 0)
308         goto error1;
309
310     if ((msg = nlmsg_alloc()) == NULL)
311         goto error1;
312
313     if (!genlmsg_put(msg, NL_AUTO_PORT, NL_AUTO_SEQ, nl80211_id, 0, NLM_F_DUMP, NL80211_CMD_GET_STATION, 0) || nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifidx) < 0 || nla_put(msg, NL80211_ATTR_MAC, 6, info->bssid) < 0)
314         goto error2;
315
316     if (nl_send_sync(sk, msg) < 0)
317         // nl_send_sync calls nlmsg_free()
318         goto error1;
319     msg = NULL;
320
321     nl_socket_free(sk);
322     return 1;
323
324 error2:
325     nlmsg_free(msg);
326 error1:
327     nl_socket_free(sk);
328     return 0;
329
330 #endif
331 #if defined(__FreeBSD__) || defined(__DragonFly__)
332     int s, inwid;
333     union {
334         struct ieee80211req_sta_req req;
335         uint8_t buf[24 * 1024];
336     } u;
337     struct ieee80211req na;
338     char bssid[IEEE80211_ADDR_LEN];
339     size_t len;
340
341     if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
342         return (0);
343
344     memset(&na, 0, sizeof(na));
345     strlcpy(na.i_name, interface, sizeof(na.i_name));
346     na.i_type = IEEE80211_IOC_SSID;
347     na.i_data = &info->essid[0];
348     na.i_len = IEEE80211_NWID_LEN + 1;
349     if ((inwid = ioctl(s, SIOCG80211, (caddr_t)&na)) == -1) {
350         close(s);
351         return (0);
352     }
353     if (inwid == 0) {
354         if (na.i_len <= IEEE80211_NWID_LEN)
355             len = na.i_len + 1;
356         else
357             len = IEEE80211_NWID_LEN + 1;
358         info->essid[len - 1] = '\0';
359     } else {
360         close(s);
361         return (0);
362     }
363     info->flags |= WIRELESS_INFO_FLAG_HAS_ESSID;
364
365     memset(&na, 0, sizeof(na));
366     strlcpy(na.i_name, interface, sizeof(na.i_name));
367     na.i_type = IEEE80211_IOC_BSSID;
368     na.i_data = bssid;
369     na.i_len = sizeof(bssid);
370
371     if (ioctl(s, SIOCG80211, (caddr_t)&na) == -1) {
372         close(s);
373         return (0);
374     }
375
376     memcpy(u.req.is_u.macaddr, bssid, sizeof(bssid));
377     memset(&na, 0, sizeof(na));
378     strlcpy(na.i_name, interface, sizeof(na.i_name));
379     na.i_type = IEEE80211_IOC_STA_INFO;
380     na.i_data = &u;
381     na.i_len = sizeof(u);
382
383     if (ioctl(s, SIOCG80211, (caddr_t)&na) == -1) {
384         close(s);
385         return (0);
386     }
387
388     close(s);
389     if (na.i_len >= sizeof(u.req)) {
390         /*
391          * Just use the first BSSID returned even if there are
392          * multiple APs sharing the same BSSID.
393          */
394         info->signal_level = u.req.info[0].isi_rssi / 2 +
395                              u.req.info[0].isi_noise;
396         info->flags |= WIRELESS_INFO_FLAG_HAS_SIGNAL;
397         info->noise_level = u.req.info[0].isi_noise;
398         info->flags |= WIRELESS_INFO_FLAG_HAS_NOISE;
399     }
400
401     return 1;
402 #endif
403 #ifdef __OpenBSD__
404     struct ifreq ifr;
405     struct ieee80211_bssid bssid;
406     struct ieee80211_nwid nwid;
407     struct ieee80211_nodereq nr;
408
409     struct ether_addr ea;
410
411     int s, len, ibssid, inwid;
412     u_int8_t zero_bssid[IEEE80211_ADDR_LEN];
413
414     if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
415         return (0);
416
417     memset(&ifr, 0, sizeof(ifr));
418     ifr.ifr_data = (caddr_t)&nwid;
419     (void)strlcpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name));
420     inwid = ioctl(s, SIOCG80211NWID, (caddr_t)&ifr);
421
422     memset(&bssid, 0, sizeof(bssid));
423     strlcpy(bssid.i_name, interface, sizeof(bssid.i_name));
424     ibssid = ioctl(s, SIOCG80211BSSID, &bssid);
425
426     if (ibssid != 0 || inwid != 0) {
427         close(s);
428         return 0;
429     }
430
431     /* NWID */
432     {
433         if (nwid.i_len <= IEEE80211_NWID_LEN)
434             len = nwid.i_len + 1;
435         else
436             len = IEEE80211_NWID_LEN + 1;
437
438         strncpy(&info->essid[0], (char *)nwid.i_nwid, len);
439         info->essid[IW_ESSID_MAX_SIZE] = '\0';
440         info->flags |= WIRELESS_INFO_FLAG_HAS_ESSID;
441     }
442
443     /* Signal strength */
444     {
445         memset(&zero_bssid, 0, sizeof(zero_bssid));
446         if (ibssid == 0 && memcmp(bssid.i_bssid, zero_bssid, IEEE80211_ADDR_LEN) != 0) {
447             memcpy(&ea.ether_addr_octet, bssid.i_bssid, sizeof(ea.ether_addr_octet));
448
449             bzero(&nr, sizeof(nr));
450             bcopy(bssid.i_bssid, &nr.nr_macaddr, sizeof(nr.nr_macaddr));
451             strlcpy(nr.nr_ifname, interface, sizeof(nr.nr_ifname));
452
453             if (ioctl(s, SIOCG80211NODE, &nr) == 0 && nr.nr_rssi) {
454                 info->signal_level = nr.nr_rssi;
455                 if (nr.nr_max_rssi)
456                     info->signal_level_max = nr.nr_max_rssi;
457
458                 info->flags |= WIRELESS_INFO_FLAG_HAS_SIGNAL;
459             }
460         }
461     }
462
463     close(s);
464     return 1;
465 #endif
466     return 0;
467 }
468
469 /* Table summarizing what is the decision to prefer IPv4 or IPv6
470  * based their values.
471  *
472  * | ipv4_address | ipv6_address | Chosen IP | Color             |
473  * |--------------|--------------|-----------|-------------------|
474  * | NULL         | NULL         | None      | bad (red)         |
475  * | NULL         | no IP        | IPv6      | degraded (orange) |
476  * | NULL         | ::1/128      | IPv6      | ok (green)        |
477  * | no IP        | NULL         | IPv4      | degraded          |
478  * | no IP        | no IP        | IPv4      | degraded          |
479  * | no IP        | ::1/128      | IPv6      | ok                |
480  * | 127.0.0.1    | NULL         | IPv4      | ok                |
481  * | 127.0.0.1    | no IP        | IPv4      | ok                |
482  * | 127.0.0.1    | ::1/128      | IPv4      | ok                |
483  */
484 void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface, const char *format_up, const char *format_down, const char *format_quality) {
485     const char *walk;
486     char *outwalk = buffer;
487     wireless_info_t info;
488
489     INSTANCE(interface);
490
491     char *ipv4_address = sstrdup(get_ip_addr(interface, AF_INET));
492     char *ipv6_address = sstrdup(get_ip_addr(interface, AF_INET6));
493
494     /*
495      * Removing '%' and following characters from IPv6 since the interface identifier is redundant,
496      * as the output already includes the interface name.
497     */
498     if (ipv6_address != NULL) {
499         char *prct_ptr = strstr(ipv6_address, "%");
500         if (prct_ptr != NULL) {
501             *prct_ptr = '\0';
502         }
503     }
504
505     bool prefer_ipv4 = true;
506     if (ipv4_address == NULL) {
507         if (ipv6_address == NULL) {
508             START_COLOR("color_bad");
509             outwalk += sprintf(outwalk, "%s", format_down);
510             goto out;
511         } else {
512             prefer_ipv4 = false;
513         }
514     } else if (BEGINS_WITH(ipv4_address, "no IP") && ipv6_address != NULL && !BEGINS_WITH(ipv6_address, "no IP")) {
515         prefer_ipv4 = false;
516     }
517
518     const char *ip_address = (prefer_ipv4) ? ipv4_address : ipv6_address;
519     if (!get_wireless_info(interface, &info)) {
520         walk = format_down;
521         START_COLOR("color_bad");
522     } else {
523         walk = format_up;
524         if (info.flags & WIRELESS_INFO_FLAG_HAS_QUALITY)
525             START_COLOR((info.quality < info.quality_average ? "color_degraded" : "color_good"));
526         else {
527             if (BEGINS_WITH(ip_address, "no IP")) {
528                 START_COLOR("color_degraded");
529             } else {
530                 START_COLOR("color_good");
531             }
532         }
533     }
534
535     for (; *walk != '\0'; walk++) {
536         if (*walk != '%') {
537             *(outwalk++) = *walk;
538
539         } else if (BEGINS_WITH(walk + 1, "quality")) {
540             if (info.flags & WIRELESS_INFO_FLAG_HAS_QUALITY) {
541                 if (info.quality_max)
542                     outwalk += sprintf(outwalk, format_quality, PERCENT_VALUE(info.quality, info.quality_max), pct_mark);
543                 else
544                     outwalk += sprintf(outwalk, "%d", info.quality);
545             } else {
546                 *(outwalk++) = '?';
547             }
548             walk += strlen("quality");
549
550         } else if (BEGINS_WITH(walk + 1, "signal")) {
551             if (info.flags & WIRELESS_INFO_FLAG_HAS_SIGNAL) {
552                 if (info.signal_level_max)
553                     outwalk += sprintf(outwalk, "%3d%s", PERCENT_VALUE(info.signal_level, info.signal_level_max), pct_mark);
554                 else
555                     outwalk += sprintf(outwalk, "%d dBm", info.signal_level);
556             } else {
557                 *(outwalk++) = '?';
558             }
559             walk += strlen("signal");
560
561         } else if (BEGINS_WITH(walk + 1, "noise")) {
562             if (info.flags & WIRELESS_INFO_FLAG_HAS_NOISE) {
563                 if (info.noise_level_max)
564                     outwalk += sprintf(outwalk, "%3d%s", PERCENT_VALUE(info.noise_level, info.noise_level_max), pct_mark);
565                 else
566                     outwalk += sprintf(outwalk, "%d dBm", info.noise_level);
567             } else {
568                 *(outwalk++) = '?';
569             }
570             walk += strlen("noise");
571
572         } else if (BEGINS_WITH(walk + 1, "essid")) {
573 #ifdef IW_ESSID_MAX_SIZE
574             if (info.flags & WIRELESS_INFO_FLAG_HAS_ESSID)
575                 maybe_escape_markup(info.essid, &outwalk);
576             else
577 #endif
578                 *(outwalk++) = '?';
579             walk += strlen("essid");
580
581         } else if (BEGINS_WITH(walk + 1, "frequency")) {
582             if (info.flags & WIRELESS_INFO_FLAG_HAS_FREQUENCY)
583                 outwalk += sprintf(outwalk, "%1.1f GHz", info.frequency / 1e9);
584             else
585                 *(outwalk++) = '?';
586             walk += strlen("frequency");
587
588         } else if (BEGINS_WITH(walk + 1, "ip")) {
589             outwalk += sprintf(outwalk, "%s", ip_address);
590             walk += strlen("ip");
591         }
592 #ifdef LINUX
593         else if (BEGINS_WITH(walk + 1, "bitrate")) {
594             char br_buffer[128];
595
596             print_bitrate(br_buffer, sizeof(br_buffer), info.bitrate);
597
598             outwalk += sprintf(outwalk, "%s", br_buffer);
599             walk += strlen("bitrate");
600         }
601 #endif
602         else {
603             *(outwalk++) = '%';
604         }
605     }
606
607 out:
608     END_COLOR;
609     free(ipv4_address);
610     free(ipv6_address);
611     OUTPUT_FULL_TEXT(buffer);
612 }