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