diff options
author | Bhanu Chetlapalli <bhanu@mips.com> | 2014-06-18 17:11:27 -0700 |
---|---|---|
committer | Chris Dearman <chris.dearman@imgtec.com> | 2014-06-18 17:24:04 -0700 |
commit | 9875ee97c7119f52fc6ce9f5e176e009faf9a753 (patch) | |
tree | 56a71ad0e22934ef5bffc1d865862199c20156d1 | |
parent | 4924d10ae04574a15d94c6812153321af59a3e5b (diff) | |
download | system_core-9875ee97c7119f52fc6ce9f5e176e009faf9a753.zip system_core-9875ee97c7119f52fc6ce9f5e176e009faf9a753.tar.gz system_core-9875ee97c7119f52fc6ce9f5e176e009faf9a753.tar.bz2 |
Use inet_ntoa to display ipaddr and mask values
Signed-off-by: Chris Dearman <chris@mips.com>
Change-Id: Iee72a6b987e4ec1c720e925b59e9e2631ae978e5
-rw-r--r-- | toolbox/ifconfig.c | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/toolbox/ifconfig.c b/toolbox/ifconfig.c index 80c0e5c..b953176 100644 --- a/toolbox/ifconfig.c +++ b/toolbox/ifconfig.c @@ -61,11 +61,11 @@ int ifconfig_main(int argc, char *argv[]) { struct ifreq ifr; int s; - unsigned int addr, mask, flags; + unsigned int flags; char astring[20]; char mstring[20]; char *updown, *brdcst, *loopbk, *ppp, *running, *multi; - + argc--; argv++; @@ -85,13 +85,17 @@ int ifconfig_main(int argc, char *argv[]) perror(ifr.ifr_name); return -1; } else - addr = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr; + strlcpy(astring, + inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr), + sizeof(astring)); if (ioctl(s, SIOCGIFNETMASK, &ifr) < 0) { perror(ifr.ifr_name); return -1; } else - mask = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr; + strlcpy(mstring, + inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr), + sizeof(mstring)); if (ioctl(s, SIOCGIFFLAGS, &ifr) < 0) { perror(ifr.ifr_name); @@ -99,16 +103,6 @@ int ifconfig_main(int argc, char *argv[]) } else flags = ifr.ifr_flags; - sprintf(astring, "%d.%d.%d.%d", - addr & 0xff, - ((addr >> 8) & 0xff), - ((addr >> 16) & 0xff), - ((addr >> 24) & 0xff)); - sprintf(mstring, "%d.%d.%d.%d", - mask & 0xff, - ((mask >> 8) & 0xff), - ((mask >> 16) & 0xff), - ((mask >> 24) & 0xff)); printf("%s: ip %s mask %s flags [", ifr.ifr_name, astring, mstring |