Index: pci_virtio_net.c =================================================================== --- pci_virtio_net.c (revision 355131) +++ pci_virtio_net.c (working copy) @@ -60,6 +60,9 @@ #include #include #include +#include +#include +#include #include "bhyverun.h" #include "pci_emul.h" @@ -817,6 +820,58 @@ } } +/* this function returns the name of the device according to the name in input +input : * char is the interface name (or alias) +output : * char is the name present in /dev +if interface does not exist the function return the input by default */ +char * findDevName(char * intName) { + + /* variable implementation */ + int fd; + char * path = "/dev/"; + char *tbuf, *tbuf2, *devName; + struct ifreq myTapInfo; //use to find the tap name + DIR *d; + struct dirent *dir; + + /* variable initialisation */ + devName = (char*) malloc(sizeof(char*)); + devName = strdup(intName); + + /* Openning directory */ + d = opendir("/dev/"); + /* readding file in directory if not empty */ + if (d) { + while ((dir = readdir(d)) != NULL) { + /* looking for tap file and implement it on the table tbl */ + tbuf = (char *) malloc((strlen(dir->d_name) + 1) * sizeof(char) ); + strcpy(tbuf,dir->d_name); + if(strncmp("tap", tbuf, 3) == 0) { + tbuf2 = (char *) malloc(sizeof(char) * (strlen(path) + strlen(tbuf) + 1 )); + tbuf2 = strdup(path); + strcat(tbuf2, tbuf); + fd = open(tbuf2, O_RDONLY); // opening the device + ioctl(fd, TAPGIFNAME, &myTapInfo); // looking for the tap device name + /* If finded we break the loop */ + if(strcmp(myTapInfo.ifr_name,intName) == 0 || strcmp(tbuf,intName) == 0) { + devName = strdup(tbuf); + close(fd); + free(tbuf2); + free(tbuf); + break; + } + close(fd); + free(tbuf2); + } + free(tbuf); + } + /* closing directory */ + closedir(d); + } + free(tbuf); + return devName; +} + static int pci_vtnet_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts) { @@ -855,8 +910,8 @@ if (opts != NULL) { int err; - devname = vtopts = strdup(opts); - (void) strsep(&vtopts, ","); + vtopts = strdup(opts); + devname = findDevName(strsep(&vtopts,",")); if (vtopts != NULL) { err = pci_vtnet_parsemac(vtopts, sc->vsc_config.mac);