Skip to content

Commit d2af1c5

Browse files
committed
Adding an optional interface name on the throughput overlay specifier
1 parent 80d66a9 commit d2af1c5

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

doc/overlays.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Specifiers starting with a dollar sign are used to represent real-time statistic
2929
```
3030
curl http://192.168.1.17/api/osd/1?text=$B%20C:$C%20M:$M
3131
```
32-
N.B. Spaces have to be escaped with %20 in curl URL syntaxes
32+
N.B. Spaces have to be escaped with %20 in curl URL syntaxes, $B can take an optional interface name preceded by a colon
3333

3434
Showing the time and customizing the time format is done this way:
3535
```

src/region.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,25 @@ void region_fill_formatted(char* str) {
1919
}
2020
else if (str[ipos + 1] == 'B')
2121
{
22-
ipos++;
22+
char ifname[16] = {0};
2323
struct ifaddrs *ifaddr, *ifa;
24+
25+
ipos++;
26+
27+
if (str[ipos + 1] == ':') {
28+
int j = 0;
29+
ipos++;
30+
while (str[ipos + 1] && str[ipos + 1] != '$' && str[ipos + 1] != ' ' && j < (sizeof(ifname) - 1))
31+
ifname[j++] = str[++ipos];
32+
ifname[j] = '\0';
33+
}
34+
2435
if (getifaddrs(&ifaddr) == -1) continue;
2536

2637
for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next)
2738
{
2839
if (EQUALS(ifa->ifa_name, "lo")) continue;
40+
if (ifname[0] && !EQUALS(ifa->ifa_name, ifname)) continue;
2941
if (!ifa->ifa_addr || ifa->ifa_addr->sa_family != AF_PACKET) continue;
3042
if (!ifa->ifa_data) continue;
3143

0 commit comments

Comments
 (0)