Specify interface on the command line
This commit is contained in:
parent
4ce7f9c309
commit
3f571bdb27
1 changed files with 8 additions and 2 deletions
|
@ -7,6 +7,7 @@
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
@ -28,7 +29,12 @@ void format_mac(const unsigned char binary_address[6], char formatted[18]) {
|
||||||
formatted[17] = '\0';
|
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
|
// Create a packet socket
|
||||||
errno = 0;
|
errno = 0;
|
||||||
int packet_socket = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
|
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
|
// Find the index of the network interface
|
||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
strncpy(ifr.ifr_name, "wlan0", IFNAMSIZ);
|
strncpy(ifr.ifr_name, argv[1], IFNAMSIZ);
|
||||||
errno = 0;
|
errno = 0;
|
||||||
if (ioctl(packet_socket, SIOCGIFINDEX, &ifr) == -1) {
|
if (ioctl(packet_socket, SIOCGIFINDEX, &ifr) == -1) {
|
||||||
err(1, "ioctl");
|
err(1, "ioctl");
|
||||||
|
|
Loading…
Reference in a new issue