summaryrefslogtreecommitdiffstats
path: root/gatchat/test-server.c
diff options
context:
space:
mode:
authorZhenhua Zhang <zhenhua.zhang@intel.com>2010-06-25 11:19:08 +0800
committerDenis Kenzior <denkenz@gmail.com>2010-06-28 17:39:18 -0500
commit0725aba03f058a73d981d71f1ac6710b6b93efa6 (patch)
tree031066c1b373260afa0d67f912546e25715a3d6c /gatchat/test-server.c
parent90d240820bd9cbb01d0e4e9af5223ff2bc078375 (diff)
downloadofono-0725aba03f058a73d981d71f1ac6710b6b93efa6.tar.bz2
test-server: Configure network interface
Require ROOT priviledge to: 1. Run external command to configure and bring up network interface. 2. Enable kernel IP forwarding.
Diffstat (limited to 'gatchat/test-server.c')
-rw-r--r--gatchat/test-server.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/gatchat/test-server.c b/gatchat/test-server.c
index 71e49863..2f5dab2f 100644
--- a/gatchat/test-server.c
+++ b/gatchat/test-server.c
@@ -50,6 +50,7 @@
#define DEFAULT_TCP_PORT 12346
#define DEFAULT_SOCK_PATH "./server_sock"
+#define IFCONFIG_PATH "/sbin/ifconfig"
static int modem_mode = 0;
static int modem_creg = 0;
@@ -91,15 +92,40 @@ static void server_debug(const char *str, void *data)
g_print("%s: %s\n", (char *) data, str);
}
+static gboolean execute(const char *cmd)
+{
+ int status;
+
+ status = system(cmd);
+ if (status < 0) {
+ g_print("Failed to execute command: %s\n", strerror(errno));
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
static void ppp_connect(const char *iface, const char *local, const char *peer,
const char *dns1, const char *dns2,
gpointer user)
{
+ char buf[512];
+
g_print("Network Device: %s\n", iface);
g_print("IP Address: %s\n", local);
g_print("Peer IP Address: %s\n", peer);
g_print("Primary DNS Server: %s\n", dns1);
g_print("Secondary DNS Server: %s\n", dns2);
+
+ snprintf(buf, sizeof(buf), "%s %s up", IFCONFIG_PATH, iface);
+ execute(buf);
+
+ snprintf(buf, sizeof(buf), "%s %s %s pointopoint %s", IFCONFIG_PATH,
+ iface, local, peer);
+ execute(buf);
+
+ snprintf(buf, sizeof(buf), "echo 1 > /proc/sys/net/ipv4/ip_forward");
+ execute(buf);
}
static void ppp_disconnect(GAtPPPDisconnectReason reason, gpointer user)
@@ -130,6 +156,11 @@ static gboolean setup_ppp(gpointer user)
GAtServer *server = user;
GAtIO *io;
+ if (getuid() != 0) {
+ g_print("Need root priviledge for PPP connection\n");
+ return FALSE;
+ }
+
io = g_at_server_get_io(server);
g_at_server_suspend(server);