View | Details | Raw Unified | Return to bug 241737 | Differences between
and this patch

Collapse All | Expand All

(-)pci_virtio_net.c (-2 / +57 lines)
Lines 60-65 Link Here
60
#include <pthread.h>
60
#include <pthread.h>
61
#include <pthread_np.h>
61
#include <pthread_np.h>
62
#include <sysexits.h>
62
#include <sysexits.h>
63
#include <net/if.h>
64
#include <net/if_tap.h>
65
#include <dirent.h>
63
66
64
#include "bhyverun.h"
67
#include "bhyverun.h"
65
#include "pci_emul.h"
68
#include "pci_emul.h"
Lines 817-822 Link Here
817
	}
820
	}
818
}
821
}
819
822
823
/* this function returns the name of the device according to the name in input
824
input : * char is the interface name (or alias)
825
output : * char is the name present in /dev
826
if interface does not exist the function return the input by default */
827
char * findDevName(char * intName) {
828
829
        /* variable implementation */
830
        int fd;
831
        char * path = "/dev/";
832
        char *tbuf, *tbuf2, *devName;
833
        struct ifreq myTapInfo; //use to find the tap name
834
        DIR *d;
835
        struct dirent *dir;
836
837
        /* variable initialisation */
838
        devName = (char*) malloc(sizeof(char*));
839
        devName = strdup(intName);
840
841
        /* Openning directory */
842
        d = opendir("/dev/");
843
        /* readding file in directory if not empty */
844
        if (d) {
845
                while ((dir = readdir(d)) != NULL) {
846
                /* looking for tap file and implement it on the table tbl */
847
                        tbuf = (char *) malloc((strlen(dir->d_name) + 1) * sizeof(char) );
848
                        strcpy(tbuf,dir->d_name);
849
                        if(strncmp("tap", tbuf, 3) == 0) {
850
                                tbuf2 = (char *) malloc(sizeof(char) * (strlen(path) + strlen(tbuf) + 1 ));
851
                                tbuf2 = strdup(path);
852
                                strcat(tbuf2, tbuf);
853
                                fd = open(tbuf2, O_RDONLY); // opening the device
854
                                ioctl(fd, TAPGIFNAME, &myTapInfo); // looking for the tap device name
855
                                /* If finded we break the loop */
856
                                if(strcmp(myTapInfo.ifr_name,intName) == 0 || strcmp(tbuf,intName) == 0) {
857
                                        devName = strdup(tbuf);
858
                                        close(fd);
859
                                        free(tbuf2);
860
                                        free(tbuf);
861
                                        break;
862
                                }
863
                                close(fd);
864
                                free(tbuf2);
865
                        }
866
                        free(tbuf);
867
                }
868
                /* closing directory */
869
                closedir(d);
870
        }
871
        free(tbuf);
872
        return devName;
873
}
874
820
static int
875
static int
821
pci_vtnet_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts)
876
pci_vtnet_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts)
822
{
877
{
Lines 855-862 Link Here
855
	if (opts != NULL) {
910
	if (opts != NULL) {
856
		int err;
911
		int err;
857
912
858
		devname = vtopts = strdup(opts);
913
                vtopts = strdup(opts);
859
		(void) strsep(&vtopts, ",");
914
                devname = findDevName(strsep(&vtopts,","));
860
915
861
		if (vtopts != NULL) {
916
		if (vtopts != NULL) {
862
			err = pci_vtnet_parsemac(vtopts, sc->vsc_config.mac);
917
			err = pci_vtnet_parsemac(vtopts, sc->vsc_config.mac);

Return to bug 241737