From 3f571bdb274ad66d2a7b041f28e4a760e7be9a86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Wed, 3 Jul 2019 23:09:14 +0300 Subject: [PATCH] Specify interface on the command line --- ethertype-dump.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ethertype-dump.c b/ethertype-dump.c index 4e9b528..703d5c8 100644 --- a/ethertype-dump.c +++ b/ethertype-dump.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -28,7 +29,12 @@ void format_mac(const unsigned char binary_address[6], char formatted[18]) { formatted[17] = '\0'; } -int main(void) { +int main(int argc, char **argv) { + if (argc != 2) { + fprintf(stderr, "Usage: %s interface\n", argv[0]); + exit(1); + } + // Create a packet socket errno = 0; int packet_socket = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); @@ -38,7 +44,7 @@ int main(void) { // Find the index of the network interface struct ifreq ifr; - strncpy(ifr.ifr_name, "wlan0", IFNAMSIZ); + strncpy(ifr.ifr_name, argv[1], IFNAMSIZ); errno = 0; if (ioctl(packet_socket, SIOCGIFINDEX, &ifr) == -1) { err(1, "ioctl");