This repository has been archived on 2025-04-11. You can view files and clone it, but cannot push or open issues or pull requests.
csce465pine64backup/hw1/set_device.cpp
2018-02-12 04:57:21 -06:00

30 lines
561 B
C++

#include <stdio.h>
#include <pcap.h>
// Naive, implies the user will pass in and consequently
// know what the device name is.
/*
int main(int argc, char *argv[])
{
char *dev = argv[1];
printf("Device: %s\n", dev);
return(0);
}
*/
// In this way, the program detects the device to use on its own.
int main(int argc, char *argv[])
{
char *dev, errbuf[PCAP_ERRBUF_SIZE];
dev = pcap_lookupdev(errbuf);
if (dev == NULL) {
fprintf(stderr, "Couldn't find default device: %s\n", errbuf);
return(2);
}
printf("Device: %s\n", dev);
return(0);
}