From 824b3e16d5f3962f7bdba0ff3159363afad3cc68 Mon Sep 17 00:00:00 2001 From: joeyh Date: Sat, 18 Mar 2006 19:17:43 +0000 Subject: [PATCH] * ifdata: Patch from KELEMEN Peter to add support for printing hardware interface. Closes: #357646 --- debian/changelog | 6 ++++-- ifdata.c | 21 +++++++++++++++++++++ ifdata.docbook | 8 ++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index 2831c75..0848452 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,8 +1,10 @@ -moreutils (0.7) UNRELEASED; urgency=low +moreutils (0.7) unstable; urgency=low * Add pee (pipe tee) contributed by Miek Gieben. + * ifdata: Patch from KELEMEN Peter to add support for printing hardware + interface. Closes: #357646 - -- Joey Hess Tue, 14 Mar 2006 18:07:46 -0500 + -- Joey Hess Sat, 18 Mar 2006 14:17:08 -0500 moreutils (0.6) unstable; urgency=low diff --git a/ifdata.c b/ifdata.c index c65ef16..1f1eb2a 100644 --- a/ifdata.c +++ b/ifdata.c @@ -41,6 +41,7 @@ #define DO_SOUTCARRIER 25 #define DO_SOUTMULTICAST 26 #define DO_PNETWORK 27 +#define DO_PHWADDRESS 28 struct if_stat { unsigned long long int in_packets; @@ -138,6 +139,20 @@ void if_flags(char *iface) { PRINT_IF(0xffff0000,"Unknown-flags"); } +void if_hwaddr(char *iface) { + unsigned char *hwaddr; + + PREPARE_SOCK(iface); + CALL_IOCTL(SIOCGIFHWADDR); + if (res < 0) { + CALL_ERROR(); + } + hwaddr = (unsigned char *)req.ifr_hwaddr.sa_data; + printf("%02X:%02X:%02X:%02X:%02X:%02X", + hwaddr[0], hwaddr[1], hwaddr[2], hwaddr[3], hwaddr[4], hwaddr[5]); + END_SOCK; +} + struct sockaddr *if_addr(char *iface) { PREPARE_SOCK(iface); CALL_IOCTL(SIOCGIFADDR); @@ -324,6 +339,7 @@ void usage(char *name) { fprintf(stderr," -e Says if iface exists or not\n" " -p Print out the whole config of iface\n" " -pe Print out yes or no according to existence\n" + " -ph Print out the hardware address\n" " -pa Print out the address\n" " -pn Print netmask\n" " -pN Print network address\n" @@ -379,6 +395,9 @@ void please_do(int ndo, int *todo, char *ifname) { printf("no"); } break; + case DO_PHWADDRESS: + if_hwaddr(ifname); + break; case DO_PADDRESS: sadr=if_addr(ifname); PRINT_OR_ERR(sadr); @@ -531,6 +550,8 @@ int main(int argc, char *argv[]) { add_do(&ndo,&todo,DO_EXISTS); } else if (!strcmp(argv[narg],"-p")) { add_do(&ndo,&todo,DO_PALL); + } else if (!strcmp(argv[narg],"-ph")) { + add_do(&ndo,&todo,DO_PHWADDRESS); } else if (!strcmp(argv[narg],"-pa")) { add_do(&ndo,&todo,DO_PADDRESS); } else if (!strcmp(argv[narg],"-pn")) { diff --git a/ifdata.docbook b/ifdata.docbook index 8c79b80..6adcc81 100644 --- a/ifdata.docbook +++ b/ifdata.docbook @@ -105,6 +105,14 @@ with this program; if not, write to the Free Software Foundation, Inc., + + + Prints the hardware address of the + interface. + + + + Prints the IPv4 address of the -- 2.11.4.GIT