From: Munkyu Im Date: Tue, 12 May 2015 08:23:24 +0000 (+0900) Subject: net: get base interface name X-Git-Tag: TizenStudio_2.0_p3.0~216 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2e4d531dd99375b0374c631da77f1ceb4bbab9c1;p=sdk%2Femulator%2Fqemu.git net: get base interface name ubuntu host user can get interface name from host ip. it is used for bridged network setting. Change-Id: I3a4dd0b624f851a2f8753419525a6c45ef469bd7 Signed-off-by: Munkyu Im --- diff --git a/net/tap.c b/net/tap.c index 3ad61df..7833142 100644 --- a/net/tap.c +++ b/net/tap.c @@ -359,13 +359,51 @@ static TAPState *net_tap_fd_init(NetClientState *peer, return s; } +#if !defined(CONFIG_WIN32) && defined(CONFIG_MARU) +#include +#include +#include +#define BRIDGE_NAME "bridge1" +static char *get_interface_name_from_ip(void) +{ + struct ifaddrs *ifaddrs, *ifaddr; + struct sockaddr_in *sa; + char *addr; + + getifaddrs(&ifaddrs); + for (ifaddr = ifaddrs; ifaddr; ifaddr = ifaddr->ifa_next) { + if (ifaddr->ifa_addr->sa_family == AF_INET) { + sa = (struct sockaddr_in *) ifaddr->ifa_addr; + addr = inet_ntoa(sa->sin_addr); + if (0 == strcmp(addr, get_emul_host_ip())) { + freeifaddrs(ifaddrs); + if (0 == strcmp(addr, BRIDGE_NAME)) { + fprintf(stdout, "interface is bridge\n"); + return NULL; + } + return ifaddr->ifa_name; + } + } + } + + freeifaddrs(ifaddrs); + return NULL; +} +#endif + static int launch_script(const char *setup_script, const char *ifname, int fd) { int pid, status; -#if defined(CONFIG_DARWIN) && defined(CONFIG_MARU) - char *args[5]; - const gchar* cocoasudo_path = g_strdup_printf("%scocoasudo", get_bin_path()); - const char* message = "--prompt=Emulator needs privileged mode to setup bridged network."; +#if !defined(CONFIG_WIN32) && defined(CONFIG_MARU) + const char* sudo_path = "/usr/bin/sudo"; + char *host_ifname = get_interface_name_from_ip(); + int arg_cnt = 0; + if (host_ifname == NULL) { + arg_cnt = 4; + } else { + arg_cnt = 5; + } + char *args[arg_cnt]; #else char *args[3]; #endif @@ -382,15 +420,18 @@ static int launch_script(const char *setup_script, const char *ifname, int fd) } } parg = args; -#if defined(CONFIG_DARWIN) && defined(CONFIG_MARU) - *parg++ = (char *)cocoasudo_path; - *parg++ = (char *)message; +#if !defined(CONFIG_WIN32) && defined(CONFIG_MARU) + *parg++ = (char *)sudo_path; #endif *parg++ = (char *)setup_script; *parg++ = (char *)ifname; + if (host_ifname) { + *parg++ = (char *)host_ifname; + } *parg = NULL; -#if defined(CONFIG_DARWIN) && defined(CONFIG_MARU) - execv(cocoasudo_path, args); + +#if !defined(CONFIG_WIN32) && defined(CONFIG_MARU) + execv(sudo_path, args); #else execv(setup_script, args); #endif diff --git a/tizen/src/scripts/emulator-ifup-linux.sh b/tizen/src/scripts/emulator-ifup-linux.sh index 3e059ff..9c5a905 100755 --- a/tizen/src/scripts/emulator-ifup-linux.sh +++ b/tizen/src/scripts/emulator-ifup-linux.sh @@ -1,9 +1,8 @@ #!/bin/sh +x -BASEIF=eth0 NETMASK=`ifconfig $BASE | grep "inet " | awk '{print $4}' | cut -d : -f2` GW=`netstat -rn | grep ^0.0.0.0 | awk '{print $2}'` -BR=br-tizen-vm-1 +BR=bridge1 # Check if bridge interface exists. CHECK_BR=`ifconfig $BR` @@ -18,12 +17,15 @@ fi # ifconfig up tap device. ifconfig $1 0.0.0.0 promisc up -# Take interface down. -ifdown $BASEIF -ifconfig $BASEIF 0.0.0.0 promisc up +if [ "$2" != "" ] +then + # Take interface down. + ifdown $2 + ifconfig $2 0.0.0.0 promisc up -# Add tap device and interface to bridge. -brctl addif $BR $BASEIF + # Add tap device and interface to bridge. + brctl addif $BR $2 +fi brctl addif $BR $1 # Add the default route.