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");