2 * Copyright (C) 2008 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <sys/socket.h>
19 #include <sys/types.h>
20 #include <netinet/in.h>
21 #include <arpa/inet.h>
28 #define LOG_TAG "CommandListener"
29 #include <cutils/log.h>
31 #include <sysutils/SocketClient.h>
33 #include "CommandListener.h"
34 #include "ResponseCode.h"
35 #include "ThrottleController.h"
38 extern "C" int ifc_init(void);
39 extern "C" int ifc_get_hwaddr(const char *name, void *ptr);
40 extern "C" int ifc_get_info(const char *name, in_addr_t *addr, int *prefixLength, unsigned *flags);
41 extern "C" int ifc_set_addr(const char *name, in_addr_t addr);
42 extern "C" int ifc_set_prefixLength(const char *name, int prefixLength);
43 extern "C" int ifc_up(const char *name);
44 extern "C" int ifc_down(const char *name);
45 extern "C" int ifc_add_route(const char *name, const char *dst, int prefix_length, const char *gw);
46 extern "C" int ifc_remove_route(const char *name, const char *dst, int p_length, const char *gw);
48 TetherController *CommandListener::sTetherCtrl = NULL;
49 NatController *CommandListener::sNatCtrl = NULL;
50 PppController *CommandListener::sPppCtrl = NULL;
51 PanController *CommandListener::sPanCtrl = NULL;
52 SoftapController *CommandListener::sSoftapCtrl = NULL;
53 UsbController *CommandListener::sUsbCtrl = NULL;
54 ResolverController *CommandListener::sResolverCtrl = NULL;
56 CommandListener::CommandListener() :
57 FrameworkListener("netd") {
58 registerCmd(new InterfaceCmd());
59 registerCmd(new IpFwdCmd());
60 registerCmd(new TetherCmd());
61 registerCmd(new NatCmd());
62 registerCmd(new ListTtysCmd());
63 registerCmd(new PppdCmd());
64 registerCmd(new PanCmd());
65 registerCmd(new SoftapCmd());
66 registerCmd(new UsbCmd());
67 registerCmd(new ResolverCmd());
70 sTetherCtrl = new TetherController();
72 sNatCtrl = new NatController();
74 sPppCtrl = new PppController();
76 sPanCtrl = new PanController();
78 sSoftapCtrl = new SoftapController();
80 sUsbCtrl = new UsbController();
82 sResolverCtrl = new ResolverController();
85 CommandListener::InterfaceCmd::InterfaceCmd() :
86 NetdCommand("interface") {
89 int CommandListener::InterfaceCmd::runCommand(SocketClient *cli,
90 int argc, char **argv) {
92 cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing argument", false);
96 if (!strcmp(argv[1], "list")) {
100 if (!(d = opendir("/sys/class/net"))) {
101 cli->sendMsg(ResponseCode::OperationFailed, "Failed to open sysfs dir", true);
105 while((de = readdir(d))) {
106 if (de->d_name[0] == '.')
108 cli->sendMsg(ResponseCode::InterfaceListResult, de->d_name, false);
111 cli->sendMsg(ResponseCode::CommandOkay, "Interface list completed", false);
113 } else if (!strcmp(argv[1], "readrxcounter")) {
115 cli->sendMsg(ResponseCode::CommandSyntaxError,
116 "Usage: interface readrxcounter <interface>", false);
119 unsigned long rx = 0, tx = 0;
120 if (readInterfaceCounters(argv[2], &rx, &tx)) {
121 cli->sendMsg(ResponseCode::OperationFailed, "Failed to read counters", true);
126 asprintf(&msg, "%lu", rx);
127 cli->sendMsg(ResponseCode::InterfaceRxCounterResult, msg, false);
131 } else if (!strcmp(argv[1], "readtxcounter")) {
133 cli->sendMsg(ResponseCode::CommandSyntaxError,
134 "Usage: interface readtxcounter <interface>", false);
137 unsigned long rx = 0, tx = 0;
138 if (readInterfaceCounters(argv[2], &rx, &tx)) {
139 cli->sendMsg(ResponseCode::OperationFailed, "Failed to read counters", true);
144 asprintf(&msg, "%lu", tx);
145 cli->sendMsg(ResponseCode::InterfaceTxCounterResult, msg, false);
148 } else if (!strcmp(argv[1], "getthrottle")) {
149 if (argc != 4 || (argc == 4 && (strcmp(argv[3], "rx") && (strcmp(argv[3], "tx"))))) {
150 cli->sendMsg(ResponseCode::CommandSyntaxError,
151 "Usage: interface getthrottle <interface> <rx|tx>", false);
156 int voldRc = ResponseCode::InterfaceRxThrottleResult;
158 if (!strcmp(argv[3], "rx")) {
159 rc = ThrottleController::getInterfaceRxThrottle(argv[2], &val);
161 rc = ThrottleController::getInterfaceTxThrottle(argv[2], &val);
162 voldRc = ResponseCode::InterfaceTxThrottleResult;
165 cli->sendMsg(ResponseCode::OperationFailed, "Failed to get throttle", true);
168 asprintf(&msg, "%u", val);
169 cli->sendMsg(voldRc, msg, false);
174 } else if (!strcmp(argv[1], "setthrottle")) {
176 cli->sendMsg(ResponseCode::CommandSyntaxError,
177 "Usage: interface setthrottle <interface> <rx_kbps> <tx_kbps>", false);
180 if (ThrottleController::setInterfaceThrottle(argv[2], atoi(argv[3]), atoi(argv[4]))) {
181 cli->sendMsg(ResponseCode::OperationFailed, "Failed to set throttle", true);
183 cli->sendMsg(ResponseCode::CommandOkay, "Interface throttling set", false);
188 * These commands take a minimum of 3 arguments
191 cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing argument", false);
195 if (!strcmp(argv[1], "route")) {
196 int prefix_length = 0;
198 cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing argument", false);
201 if (sscanf(argv[5], "%d", &prefix_length) != 1) {
202 cli->sendMsg(ResponseCode::CommandParameterError, "Invalid route prefix", false);
205 if (!strcmp(argv[2], "add")) {
206 if (ifc_add_route(argv[3], argv[4], prefix_length, argv[6])) {
207 cli->sendMsg(ResponseCode::OperationFailed, "Failed to add route", true);
209 cli->sendMsg(ResponseCode::CommandOkay, "Route added", false);
211 } else if (!strcmp(argv[2], "remove")) {
212 if (ifc_remove_route(argv[3], argv[4], prefix_length, argv[6])) {
213 cli->sendMsg(ResponseCode::OperationFailed, "Failed to remove route", true);
215 cli->sendMsg(ResponseCode::CommandOkay, "Route removed", false);
218 cli->sendMsg(ResponseCode::CommandSyntaxError, "Unknown interface cmd", false);
223 if (!strcmp(argv[1], "getcfg")) {
226 unsigned char hwaddr[6];
230 memset(hwaddr, 0, sizeof(hwaddr));
232 if (ifc_get_info(argv[2], &addr.s_addr, &prefixLength, &flags)) {
233 cli->sendMsg(ResponseCode::OperationFailed, "Interface not found", true);
237 if (ifc_get_hwaddr(argv[2], (void *) hwaddr)) {
238 LOGW("Failed to retrieve HW addr for %s (%s)", argv[2], strerror(errno));
241 char *addr_s = strdup(inet_ntoa(addr));
242 const char *updown, *brdcst, *loopbk, *ppp, *running, *multi;
244 updown = (flags & IFF_UP) ? "up" : "down";
245 brdcst = (flags & IFF_BROADCAST) ? " broadcast" : "";
246 loopbk = (flags & IFF_LOOPBACK) ? " loopback" : "";
247 ppp = (flags & IFF_POINTOPOINT) ? " point-to-point" : "";
248 running = (flags & IFF_RUNNING) ? " running" : "";
249 multi = (flags & IFF_MULTICAST) ? " multicast" : "";
253 asprintf(&flag_s, "[%s%s%s%s%s%s]", updown, brdcst, loopbk, ppp, running, multi);
256 asprintf(&msg, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x %s %d %s",
257 hwaddr[0], hwaddr[1], hwaddr[2], hwaddr[3], hwaddr[4], hwaddr[5],
258 addr_s, prefixLength, flag_s);
260 cli->sendMsg(ResponseCode::InterfaceGetCfgResult, msg, false);
266 } else if (!strcmp(argv[1], "setcfg")) {
267 // arglist: iface addr prefixLength [flags]
269 cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing argument", false);
272 LOGD("Setting iface cfg");
277 if (!inet_aton(argv[3], &addr)) {
278 cli->sendMsg(ResponseCode::CommandParameterError, "Invalid address", false);
283 if (ifc_set_addr(argv[2], addr.s_addr)) {
284 cli->sendMsg(ResponseCode::OperationFailed, "Failed to set address", true);
288 if (ifc_set_prefixLength(argv[2], atoi(argv[4]))) {
289 cli->sendMsg(ResponseCode::OperationFailed, "Failed to set prefixLength", true);
294 /* read from "[XX" arg to "YY]" arg */
295 bool bStarted = false;
296 for (int i = 5; i < argc; i++) {
297 char *flag = argv[i];
306 int len = strlen(flag);
307 if (flag[len-1] == ']') {
308 i = argc; // stop after this loop
311 if (!strcmp(flag, "up")) {
312 LOGD("Trying to bring up %s", argv[2]);
313 if (ifc_up(argv[2])) {
314 LOGE("Error upping interface");
315 cli->sendMsg(ResponseCode::OperationFailed, "Failed to up interface", true);
318 } else if (!strcmp(flag, "down")) {
319 LOGD("Trying to bring down %s", argv[2]);
320 if (ifc_down(argv[2])) {
321 LOGE("Error downing interface");
322 cli->sendMsg(ResponseCode::OperationFailed, "Failed to down interface", true);
325 } else if (!strcmp(flag, "broadcast")) {
326 LOGD("broadcast flag ignored");
327 } else if (!strcmp(flag, "multicast")) {
328 LOGD("multicast flag ignored");
330 cli->sendMsg(ResponseCode::CommandParameterError, "Flag unsupported", false);
334 cli->sendMsg(ResponseCode::CommandOkay, "Interface configuration set", false);
337 cli->sendMsg(ResponseCode::CommandSyntaxError, "Unknown interface cmd", false);
344 CommandListener::ListTtysCmd::ListTtysCmd() :
345 NetdCommand("list_ttys") {
348 int CommandListener::ListTtysCmd::runCommand(SocketClient *cli,
349 int argc, char **argv) {
350 TtyCollection *tlist = sPppCtrl->getTtyList();
351 TtyCollection::iterator it;
353 for (it = tlist->begin(); it != tlist->end(); ++it) {
354 cli->sendMsg(ResponseCode::TtyListResult, *it, false);
357 cli->sendMsg(ResponseCode::CommandOkay, "Ttys listed.", false);
361 CommandListener::IpFwdCmd::IpFwdCmd() :
362 NetdCommand("ipfwd") {
365 int CommandListener::IpFwdCmd::runCommand(SocketClient *cli,
366 int argc, char **argv) {
370 cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing argument", false);
374 if (!strcmp(argv[1], "status")) {
377 asprintf(&tmp, "Forwarding %s", (sTetherCtrl->getIpFwdEnabled() ? "enabled" : "disabled"));
378 cli->sendMsg(ResponseCode::IpFwdStatusResult, tmp, false);
381 } else if (!strcmp(argv[1], "enable")) {
382 rc = sTetherCtrl->setIpFwdEnabled(true);
383 } else if (!strcmp(argv[1], "disable")) {
384 rc = sTetherCtrl->setIpFwdEnabled(false);
386 cli->sendMsg(ResponseCode::CommandSyntaxError, "Unknown ipfwd cmd", false);
391 cli->sendMsg(ResponseCode::CommandOkay, "ipfwd operation succeeded", false);
393 cli->sendMsg(ResponseCode::OperationFailed, "ipfwd operation failed", true);
399 CommandListener::TetherCmd::TetherCmd() :
400 NetdCommand("tether") {
403 int CommandListener::TetherCmd::runCommand(SocketClient *cli,
404 int argc, char **argv) {
408 cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing argument", false);
412 if (!strcmp(argv[1], "stop")) {
413 rc = sTetherCtrl->stopTethering();
414 } else if (!strcmp(argv[1], "status")) {
417 asprintf(&tmp, "Tethering services %s",
418 (sTetherCtrl->isTetheringStarted() ? "started" : "stopped"));
419 cli->sendMsg(ResponseCode::TetherStatusResult, tmp, false);
424 * These commands take a minimum of 4 arguments
427 cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing argument", false);
431 if (!strcmp(argv[1], "start")) {
433 cli->sendMsg(ResponseCode::CommandSyntaxError, "Bad number of arguments", false);
437 int num_addrs = argc - 2;
440 in_addr *addrs = (in_addr *)malloc(sizeof(in_addr) * num_addrs);
441 while (array_index < num_addrs) {
442 if (!inet_aton(argv[arg_index++], &(addrs[array_index++]))) {
443 cli->sendMsg(ResponseCode::CommandParameterError, "Invalid address", false);
448 rc = sTetherCtrl->startTethering(num_addrs, addrs);
450 } else if (!strcmp(argv[1], "interface")) {
451 if (!strcmp(argv[2], "add")) {
452 rc = sTetherCtrl->tetherInterface(argv[3]);
453 } else if (!strcmp(argv[2], "remove")) {
454 rc = sTetherCtrl->untetherInterface(argv[3]);
455 } else if (!strcmp(argv[2], "list")) {
456 InterfaceCollection *ilist = sTetherCtrl->getTetheredInterfaceList();
457 InterfaceCollection::iterator it;
459 for (it = ilist->begin(); it != ilist->end(); ++it) {
460 cli->sendMsg(ResponseCode::TetherInterfaceListResult, *it, false);
463 cli->sendMsg(ResponseCode::CommandParameterError,
464 "Unknown tether interface operation", false);
467 } else if (!strcmp(argv[1], "dns")) {
468 if (!strcmp(argv[2], "set")) {
469 rc = sTetherCtrl->setDnsForwarders(&argv[3], argc - 3);
470 } else if (!strcmp(argv[2], "list")) {
471 NetAddressCollection *dlist = sTetherCtrl->getDnsForwarders();
472 NetAddressCollection::iterator it;
474 for (it = dlist->begin(); it != dlist->end(); ++it) {
475 cli->sendMsg(ResponseCode::TetherDnsFwdTgtListResult, inet_ntoa(*it), false);
478 cli->sendMsg(ResponseCode::CommandParameterError,
479 "Unknown tether interface operation", false);
483 cli->sendMsg(ResponseCode::CommandSyntaxError, "Unknown tether cmd", false);
489 cli->sendMsg(ResponseCode::CommandOkay, "Tether operation succeeded", false);
491 cli->sendMsg(ResponseCode::OperationFailed, "Tether operation failed", true);
497 CommandListener::NatCmd::NatCmd() :
501 int CommandListener::NatCmd::runCommand(SocketClient *cli,
502 int argc, char **argv) {
506 cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing argument", false);
510 if (!strcmp(argv[1], "enable")) {
511 rc = sNatCtrl->enableNat(argv[2], argv[3]);
512 } else if (!strcmp(argv[1], "disable")) {
513 rc = sNatCtrl->disableNat(argv[2], argv[3]);
515 cli->sendMsg(ResponseCode::CommandSyntaxError, "Unknown nat cmd", false);
520 cli->sendMsg(ResponseCode::CommandOkay, "Nat operation succeeded", false);
522 cli->sendMsg(ResponseCode::OperationFailed, "Nat operation failed", true);
528 CommandListener::PppdCmd::PppdCmd() :
529 NetdCommand("pppd") {
532 int CommandListener::PppdCmd::runCommand(SocketClient *cli,
533 int argc, char **argv) {
537 cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing argument", false);
541 if (!strcmp(argv[1], "attach")) {
542 struct in_addr l, r, dns1, dns2;
544 memset(&dns1, sizeof(struct in_addr), 0);
545 memset(&dns2, sizeof(struct in_addr), 0);
547 if (!inet_aton(argv[3], &l)) {
548 cli->sendMsg(ResponseCode::CommandParameterError, "Invalid local address", false);
551 if (!inet_aton(argv[4], &r)) {
552 cli->sendMsg(ResponseCode::CommandParameterError, "Invalid remote address", false);
555 if ((argc > 3) && (!inet_aton(argv[5], &dns1))) {
556 cli->sendMsg(ResponseCode::CommandParameterError, "Invalid dns1 address", false);
559 if ((argc > 4) && (!inet_aton(argv[6], &dns2))) {
560 cli->sendMsg(ResponseCode::CommandParameterError, "Invalid dns2 address", false);
563 rc = sPppCtrl->attachPppd(argv[2], l, r, dns1, dns2);
564 } else if (!strcmp(argv[1], "detach")) {
565 rc = sPppCtrl->detachPppd(argv[2]);
567 cli->sendMsg(ResponseCode::CommandSyntaxError, "Unknown pppd cmd", false);
572 cli->sendMsg(ResponseCode::CommandOkay, "Pppd operation succeeded", false);
574 cli->sendMsg(ResponseCode::OperationFailed, "Pppd operation failed", true);
580 CommandListener::PanCmd::PanCmd() :
584 int CommandListener::PanCmd::runCommand(SocketClient *cli,
585 int argc, char **argv) {
589 cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing argument", false);
593 if (!strcmp(argv[1], "start")) {
594 rc = sPanCtrl->startPan();
595 } else if (!strcmp(argv[1], "stop")) {
596 rc = sPanCtrl->stopPan();
597 } else if (!strcmp(argv[1], "status")) {
600 asprintf(&tmp, "Pan services %s",
601 (sPanCtrl->isPanStarted() ? "started" : "stopped"));
602 cli->sendMsg(ResponseCode::PanStatusResult, tmp, false);
606 cli->sendMsg(ResponseCode::CommandSyntaxError, "Unknown pan cmd", false);
611 cli->sendMsg(ResponseCode::CommandOkay, "Pan operation succeeded", false);
613 cli->sendMsg(ResponseCode::OperationFailed, "Pan operation failed", true);
619 CommandListener::SoftapCmd::SoftapCmd() :
620 NetdCommand("softap") {
623 int CommandListener::SoftapCmd::runCommand(SocketClient *cli,
624 int argc, char **argv) {
625 int rc = 0, flag = 0;
628 cli->sendMsg(ResponseCode::CommandSyntaxError, "Softap Missing argument", false);
632 if (!strcmp(argv[1], "start")) {
633 rc = sSoftapCtrl->startDriver(argv[2]);
634 } else if (!strcmp(argv[1], "stop")) {
635 rc = sSoftapCtrl->stopDriver(argv[2]);
636 } else if (!strcmp(argv[1], "startap")) {
637 rc = sSoftapCtrl->startSoftap();
638 } else if (!strcmp(argv[1], "stopap")) {
639 rc = sSoftapCtrl->stopSoftap();
640 } else if (!strcmp(argv[1], "fwreload")) {
641 rc = sSoftapCtrl->fwReloadSoftap(argc, argv);
642 } else if (!strcmp(argv[1], "status")) {
645 asprintf(&tmp, "Softap service %s",
646 (sSoftapCtrl->isSoftapStarted() ? "started" : "stopped"));
647 cli->sendMsg(ResponseCode::SoftapStatusResult, tmp, false);
650 } else if (!strcmp(argv[1], "set")) {
651 rc = sSoftapCtrl->setSoftap(argc, argv);
653 cli->sendMsg(ResponseCode::CommandSyntaxError, "Softap Unknown cmd", false);
658 cli->sendMsg(ResponseCode::CommandOkay, "Softap operation succeeded", false);
660 cli->sendMsg(ResponseCode::OperationFailed, "Softap operation failed", true);
666 CommandListener::UsbCmd::UsbCmd() :
670 int CommandListener::UsbCmd::runCommand(SocketClient *cli, int argc, char **argv) {
674 cli->sendMsg(ResponseCode::CommandSyntaxError, "Usb Missing argument", false);
678 if (!strcmp(argv[1], "startrndis")) {
679 rc = sUsbCtrl->startRNDIS();
680 } else if (!strcmp(argv[1], "stoprndis")) {
681 rc = sUsbCtrl->stopRNDIS();
682 } else if (!strcmp(argv[1], "rndisstatus")) {
685 asprintf(&tmp, "Usb RNDIS %s",
686 (sUsbCtrl->isRNDISStarted() ? "started" : "stopped"));
687 cli->sendMsg(ResponseCode::UsbRNDISStatusResult, tmp, false);
691 cli->sendMsg(ResponseCode::CommandSyntaxError, "Usb Unknown cmd", false);
696 cli->sendMsg(ResponseCode::CommandOkay, "Usb operation succeeded", false);
698 cli->sendMsg(ResponseCode::OperationFailed, "Softap operation failed", true);
704 CommandListener::ResolverCmd::ResolverCmd() :
705 NetdCommand("resolver") {
708 int CommandListener::ResolverCmd::runCommand(SocketClient *cli, int argc, char **argv) {
713 cli->sendMsg(ResponseCode::CommandSyntaxError, "Resolver missing arguments", false);
717 if (!strcmp(argv[1], "setdefaultif")) { // "resolver setdefaultif <iface>"
719 rc = sResolverCtrl->setDefaultInterface(argv[2]);
721 cli->sendMsg(ResponseCode::CommandSyntaxError,
722 "Wrong number of arguments to resolver setdefaultif", false);
725 } else if (!strcmp(argv[1], "setifdns")) { // "resolver setifdns <iface> <dns1> <dns2> ..."
727 rc = sResolverCtrl->setInterfaceDnsServers(argv[2], &argv[3], argc - 3);
729 cli->sendMsg(ResponseCode::CommandSyntaxError,
730 "Wrong number of arguments to resolver setifdns", false);
734 // set the address of the interface to which the name servers
735 // are bound. Required in order to bind to right interface when
736 // doing the dns query.
739 ifc_get_info(argv[2], &addr.s_addr, NULL, 0);
741 rc = sResolverCtrl->setInterfaceAddress(argv[2], &addr);
743 } else if (!strcmp(argv[1], "flushdefaultif")) { // "resolver flushdefaultif"
745 rc = sResolverCtrl->flushDefaultDnsCache();
747 cli->sendMsg(ResponseCode::CommandSyntaxError,
748 "Wrong number of arguments to resolver flushdefaultif", false);
751 } else if (!strcmp(argv[1], "flushif")) { // "resolver flushif <iface>"
753 rc = sResolverCtrl->flushInterfaceDnsCache(argv[2]);
755 cli->sendMsg(ResponseCode::CommandSyntaxError,
756 "Wrong number of arguments to resolver setdefaultif", false);
760 cli->sendMsg(ResponseCode::CommandSyntaxError,"Resolver unknown command", false);
765 cli->sendMsg(ResponseCode::CommandOkay, "Resolver command succeeded", false);
767 cli->sendMsg(ResponseCode::OperationFailed, "Resolver command failed", true);
773 int CommandListener::readInterfaceCounters(const char *iface, unsigned long *rx, unsigned long *tx) {
774 FILE *fp = fopen("/proc/net/dev", "r");
776 LOGE("Failed to open /proc/net/dev (%s)", strerror(errno));
782 fgets(buffer, sizeof(buffer), fp); // Header 1
783 fgets(buffer, sizeof(buffer), fp); // Header 2
784 while(fgets(buffer, sizeof(buffer), fp)) {
785 buffer[strlen(buffer)-1] = '\0';
789 sscanf(buffer, "%30s %lu %lu %lu %lu %lu %lu %lu %lu %lu",
790 name, rx, &d, &d, &d, &d, &d, &d, &d, tx);
791 char *rxString = strchr(name, ':');
794 // when the rx count gets too big it changes from "name: 999" to "name:1000"
795 // and the sscanf munge the two together. Detect that and fix
796 // note that all the %lu will be off by one and the real tx value will be in d
797 if (*rxString != '\0') {
799 sscanf(rxString, "%20lu", rx);
801 if (strcmp(name, iface)) {