ETHER: Add warning about potentially running as root for unavailable devices

This commit is contained in:
Mark Pizzolato 2016-11-19 19:20:46 -08:00
parent ff95fb8ec2
commit 08665e4989
2 changed files with 11 additions and 0 deletions

View file

@ -661,6 +661,11 @@ const char* eth_getname(int number, char* name, char *desc)
if ((number < 0) || (count <= number)) if ((number < 0) || (count <= number))
return NULL; return NULL;
if (list[number].eth_api != ETH_API_PCAP) {
sim_printf ("Eth: Pcap capable device not found. You may need to run as root\n");
return NULL;
}
strcpy(name, list[number].name); strcpy(name, list[number].name);
strcpy(desc, list[number].desc); strcpy(desc, list[number].desc);
return name; return name;
@ -3819,6 +3824,7 @@ for (i=0; i<used; ++i) {
conn = pcap_open_live(list[i].name, ETH_MAX_PACKET, ETH_PROMISC, PCAP_READ_TIMEOUT, errbuf); conn = pcap_open_live(list[i].name, ETH_MAX_PACKET, ETH_PROMISC, PCAP_READ_TIMEOUT, errbuf);
if (NULL != conn) if (NULL != conn)
datalink = pcap_datalink(conn), pcap_close(conn); datalink = pcap_datalink(conn), pcap_close(conn);
list[i].eth_api = ETH_API_PCAP;
#endif #endif
if ((NULL == conn) || (datalink != DLT_EN10MB)) { if ((NULL == conn) || (datalink != DLT_EN10MB)) {
for (j=i; j<used-1; ++j) for (j=i; j<used-1; ++j)
@ -3877,6 +3883,7 @@ if (used < max) {
sprintf(list[used].name, "%s", "tap:tapN"); sprintf(list[used].name, "%s", "tap:tapN");
#endif #endif
sprintf(list[used].desc, "%s", "Integrated Tun/Tap support"); sprintf(list[used].desc, "%s", "Integrated Tun/Tap support");
list[used].eth_api = ETH_API_TAP;
++used; ++used;
} }
#endif #endif
@ -3884,6 +3891,7 @@ if (used < max) {
if (used < max) { if (used < max) {
sprintf(list[used].name, "%s", "vde:device"); sprintf(list[used].name, "%s", "vde:device");
sprintf(list[used].desc, "%s", "Integrated VDE support"); sprintf(list[used].desc, "%s", "Integrated VDE support");
list[used].eth_api = ETH_API_VDE;
++used; ++used;
} }
#endif #endif
@ -3891,6 +3899,7 @@ if (used < max) {
if (used < max) { if (used < max) {
sprintf(list[used].name, "%s", "nat:{optional-nat-parameters}"); sprintf(list[used].name, "%s", "nat:{optional-nat-parameters}");
sprintf(list[used].desc, "%s", "Integrated NAT (SLiRP) support"); sprintf(list[used].desc, "%s", "Integrated NAT (SLiRP) support");
list[used].eth_api = ETH_API_NAT;
++used; ++used;
} }
#endif #endif
@ -3898,6 +3907,7 @@ if (used < max) {
if (used < max) { if (used < max) {
sprintf(list[used].name, "%s", "udp:sourceport:remotehost:remoteport"); sprintf(list[used].name, "%s", "udp:sourceport:remotehost:remoteport");
sprintf(list[used].desc, "%s", "Integrated UDP bridge support"); sprintf(list[used].desc, "%s", "Integrated UDP bridge support");
list[used].eth_api = ETH_API_UDP;
++used; ++used;
} }

View file

@ -229,6 +229,7 @@ struct eth_queue {
struct eth_list { struct eth_list {
char name[ETH_DEV_NAME_MAX]; char name[ETH_DEV_NAME_MAX];
char desc[ETH_DEV_DESC_MAX]; char desc[ETH_DEV_DESC_MAX];
int eth_api;
}; };
typedef int ETH_BOOL; typedef int ETH_BOOL;