summaryrefslogtreecommitdiffstats
path: root/gatchat/gsmdial.c
diff options
context:
space:
mode:
authorZhenhua Zhang <zhenhua.zhang@intel.com>2010-06-25 11:19:09 +0800
committerDenis Kenzior <denkenz@gmail.com>2010-06-28 17:39:23 -0500
commit1afd51a8c70ca82219a045589168cc59564d53f3 (patch)
tree4cdd984733bfc85863cd0760a3280dda7747d740 /gatchat/gsmdial.c
parent0725aba03f058a73d981d71f1ac6710b6b93efa6 (diff)
downloadofono-1afd51a8c70ca82219a045589168cc59564d53f3.tar.bz2
gsmdial: Configure network interface for PPP
Diffstat (limited to 'gatchat/gsmdial.c')
-rw-r--r--gatchat/gsmdial.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/gatchat/gsmdial.c b/gatchat/gsmdial.c
index a69a610c..59f1a5c5 100644
--- a/gatchat/gsmdial.c
+++ b/gatchat/gsmdial.c
@@ -38,6 +38,8 @@
#include <gattty.h>
#include <gatppp.h>
+#define IFCONFIG_PATH "/sbin/ifconfig"
+
static const char *none_prefix[] = { NULL };
static const char *cfun_prefix[] = { "+CFUN:", NULL };
static const char *creg_prefix[] = { "+CREG:", NULL };
@@ -221,16 +223,43 @@ out:
return FALSE;
}
+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_data)
{
+ char buf[512];
+
/* print out the negotiated address and dns server */
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);
+
+ if (getuid() != 0) {
+ g_print("Need root priviledge to config PPP interface\n");
+ return;
+ }
+
+ 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);
}
static void ppp_disconnect(GAtPPPDisconnectReason reason, gpointer user_data)