Add option to list network interfaces
This commit is contained in:
parent
8ceb9370f5
commit
0bcc6da157
3 changed files with 34 additions and 2 deletions
30
ethsock.c
30
ethsock.c
|
|
@ -153,7 +153,7 @@ struct ethsock *ethsock_create(const char *interface, uint16_t protocol)
|
||||||
|
|
||||||
sock->pcap = pcap_open_live(interface, BUFSIZ, 1, 1, buf);
|
sock->pcap = pcap_open_live(interface, BUFSIZ, 1, 1, buf);
|
||||||
if (!sock->pcap) {
|
if (!sock->pcap) {
|
||||||
fprintf(stderr, "%s\n", buf);
|
fprintf(stderr, "%s.\n", buf);
|
||||||
goto cleanup_malloc;
|
goto cleanup_malloc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -261,3 +261,31 @@ int ethsock_set_timeout(struct ethsock *sock, unsigned msec)
|
||||||
sock->timeout.tv_usec = (msec % 1000) * 1000;
|
sock->timeout.tv_usec = (msec % 1000) * 1000;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ethsock_list_all(void)
|
||||||
|
{
|
||||||
|
pcap_if_t *devs, *dev;
|
||||||
|
uint8_t hwaddr[8];
|
||||||
|
char errbuf[PCAP_ERRBUF_SIZE];
|
||||||
|
|
||||||
|
if (pcap_findalldevs(&devs, errbuf) != 0) {
|
||||||
|
fprintf(stderr, "%s.\n", errbuf);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (dev = devs; dev; dev = dev->next) {
|
||||||
|
get_hwaddr(hwaddr, dev->name);
|
||||||
|
printf("%02x:%02x:%02x:%02x:%02x:%02x %s",
|
||||||
|
hwaddr[0], hwaddr[1], hwaddr[2],
|
||||||
|
hwaddr[3], hwaddr[4], hwaddr[5],
|
||||||
|
dev->name);
|
||||||
|
|
||||||
|
if (dev->description) {
|
||||||
|
printf(" (%s)\n", dev->description);
|
||||||
|
} else {
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,3 +8,4 @@ int ethsock_send(struct ethsock *sock, void *buf, size_t len);
|
||||||
ssize_t ethsock_recv(struct ethsock *sock, void *buf, size_t len);
|
ssize_t ethsock_recv(struct ethsock *sock, void *buf, size_t len);
|
||||||
int ethsock_set_timeout(struct ethsock *sock, unsigned msec);
|
int ethsock_set_timeout(struct ethsock *sock, unsigned msec);
|
||||||
uint8_t *ethsock_get_hwaddr(struct ethsock *sock);
|
uint8_t *ethsock_get_hwaddr(struct ethsock *sock);
|
||||||
|
int ethsock_list_all(void);
|
||||||
|
|
|
||||||
5
main.c
5
main.c
|
|
@ -37,6 +37,7 @@ void usage(FILE *fp)
|
||||||
" -T <timeout> Time to wait after successfull TFTP upload\n"
|
" -T <timeout> Time to wait after successfull TFTP upload\n"
|
||||||
" -p <port> Port to use for TFTP upload\n"
|
" -p <port> Port to use for TFTP upload\n"
|
||||||
" -V Print version and exit\n"
|
" -V Print version and exit\n"
|
||||||
|
" -L List network interfaces\n"
|
||||||
" -h Show this screen\n"
|
" -h Show this screen\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Example:\n"
|
"Example:\n"
|
||||||
|
|
@ -69,7 +70,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
opterr = 0;
|
opterr = 0;
|
||||||
|
|
||||||
while ((c = getopt(argc, argv, "a:f:i:m:M:p:t:T:hV")) != -1) {
|
while ((c = getopt(argc, argv, "a:f:i:m:M:p:t:T:hLV")) != -1) {
|
||||||
max = 0x7fffffff;
|
max = 0x7fffffff;
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'a':
|
case 'a':
|
||||||
|
|
@ -109,6 +110,8 @@ int main(int argc, char **argv)
|
||||||
case 'V':
|
case 'V':
|
||||||
printf("nmrp-flash v%s\n", NMRPD_VERSION);
|
printf("nmrp-flash v%s\n", NMRPD_VERSION);
|
||||||
return 0;
|
return 0;
|
||||||
|
case 'L':
|
||||||
|
return ethsock_list_all();
|
||||||
case 'h':
|
case 'h':
|
||||||
usage(stdout);
|
usage(stdout);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue