prototype of dumm GUI

This commit is contained in:
Martin Willi
2008-04-28 16:43:30 +00:00
parent e8a680d94a
commit a47486b5e4
13 changed files with 864 additions and 857 deletions
+45 -1
View File
@@ -43,6 +43,42 @@ struct private_iface_t {
mconsole_t *mconsole;
};
/**
* bring an interface up or down
*/
bool iface_control(char *name, bool up)
{
int s;
bool good = FALSE;
struct ifreq ifr;
memset(&ifr, 0, sizeof(struct ifreq));
strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
s = socket(AF_INET, SOCK_DGRAM, 0);
if (!s)
{
return FALSE;
}
if (ioctl(s, SIOCGIFFLAGS, &ifr) == 0)
{
if (up)
{
ifr.ifr_flags |= IFF_UP;
}
else
{
ifr.ifr_flags &= ~IFF_UP;
}
if (ioctl(s, SIOCSIFFLAGS, &ifr) == 0)
{
good = TRUE;
}
}
close(s);
return good;
}
/**
* Implementation of iface_t.get_guestif.
*/
@@ -74,7 +110,11 @@ static bool destroy_tap(private_iface_t *this)
{
struct ifreq ifr;
int tap;
if (!iface_control(this->hostif, FALSE))
{
DBG1("bringing iface down failed: %m");
}
memset(&ifr, 0, sizeof(ifr));
ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
strncpy(ifr.ifr_name, this->hostif, sizeof(ifr.ifr_name) - 1);
@@ -165,6 +205,10 @@ iface_t *iface_create(char *guest, char *guestif, mconsole_t *mconsole)
free(this);
return NULL;
}
if (!iface_control(this->hostif, TRUE))
{
DBG1("bringing iface '%s' up failed: %m", this->hostif);
}
if (!this->mconsole->add_iface(this->mconsole, this->guestif, this->hostif))
{
DBG1("creating interface '%s' in guest failed", this->guestif);