OSDN Git Service

Add specification of ms-dns arg to pppd.
authorRobert Greenwalt <robdroid@android.com>
Mon, 1 Feb 2010 18:02:28 +0000 (10:02 -0800)
committerRobert Greenwalt <robdroid@android.com>
Mon, 1 Feb 2010 18:02:28 +0000 (10:02 -0800)
This lets us tell the pc to use the tethered android as their dns server.

bug:2281900

CommandListener.cpp
PppController.cpp
PppController.h

index 1747042..eba88de 100644 (file)
@@ -395,7 +395,10 @@ int CommandListener::PppdCmd::runCommand(SocketClient *cli,
     }
 
     if (!strcmp(argv[1], "attach")) {
-        struct in_addr l, r;
+        struct in_addr l, r, dns1, dns2;
+
+        memset(&dns1, sizeof(struct in_addr), 0);
+        memset(&dns2, sizeof(struct in_addr), 0);
 
         if (!inet_aton(argv[3], &l)) {
             cli->sendMsg(ResponseCode::CommandParameterError, "Invalid local address", false);
@@ -405,7 +408,15 @@ int CommandListener::PppdCmd::runCommand(SocketClient *cli,
             cli->sendMsg(ResponseCode::CommandParameterError, "Invalid remote address", false);
             return 0;
         }
-        rc = sPppCtrl->attachPppd(argv[2], l, r);
+        if ((argc > 3) && (!inet_aton(argv[5], &dns1))) {
+            cli->sendMsg(ResponseCode::CommandParameterError, "Invalid dns1 address", false);
+            return 0;
+        }
+        if ((argc > 4) && (!inet_aton(argv[6], &dns2))) {
+            cli->sendMsg(ResponseCode::CommandParameterError, "Invalid dns2 address", false);
+            return 0;
+        }
+        rc = sPppCtrl->attachPppd(argv[2], l, r, dns1, dns2);
     } else if (!strcmp(argv[1], "detach")) {
         rc = sPppCtrl->detachPppd(argv[2]);
     } else {
index 8b32d06..767b74d 100644 (file)
@@ -50,7 +50,8 @@ PppController::~PppController() {
 }
 
 int PppController::attachPppd(const char *tty, struct in_addr local,
-                              struct in_addr remote) {
+                              struct in_addr remote, struct in_addr dns1,
+                              struct in_addr dns2) {
     pid_t pid;
 
     if (mPid) {
@@ -79,6 +80,8 @@ int PppController::attachPppd(const char *tty, struct in_addr local,
     if (!pid) {
         char *l = strdup(inet_ntoa(local));
         char *r = strdup(inet_ntoa(remote));
+        char *d1 = strdup(inet_ntoa(dns1));
+        char *d2 = strdup(inet_ntoa(dns2));
         char dev[32];
         char *lr;
 
@@ -88,8 +91,8 @@ int PppController::attachPppd(const char *tty, struct in_addr local,
 
         // TODO: Deal with pppd bailing out after 99999 seconds of being started
         // but not getting a connection
-        if (execl("/system/bin/pppd", "/system/bin/pppd", "-detach", dev,
-                  "115200", lr, "debug", "lcp-max-configure", "99999", (char *) NULL)) {
+        if (execl("/system/bin/pppd", "/system/bin/pppd", "-detach", dev, "115200",
+                  lr, "ms-dns", d1, "ms-dns", d2, "debug", "lcp-max-configure", "99999", (char *) NULL)) {
             LOGE("execl failed (%s)", strerror(errno));
         }
         LOGE("Should never get here!");
@@ -145,4 +148,3 @@ int PppController::updateTtyList() {
     closedir(d);
     return 0;
 }
-
index 5046822..bb75435 100644 (file)
@@ -32,7 +32,8 @@ public:
     virtual ~PppController();
 
     int attachPppd(const char *tty, struct in_addr local,
-                   struct in_addr remote);
+                   struct in_addr remote, struct in_addr dns1,
+                   struct in_addr dns2);
     int detachPppd(const char *tty);
     TtyCollection *getTtyList();