Blob Blame History Raw
Index: routing.c
===================================================================
RCS file: /cvsroot/pptpclient/pptp-linux/routing.c,v
retrieving revision 1.1
diff -u -r1.1 routing.c
--- routing.c	2 Aug 2006 07:07:37 -0000	1.1
+++ routing.c	25 Mar 2009 13:58:28 -0000
@@ -23,9 +23,26 @@
 #include <stdio.h>
 #include <string.h>
 #include "routing.h"
+#include "config.h"
 
+#if defined (__SVR4) && defined (__sun) /* Solaris */
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <net/if.h>
+#include <arpa/inet.h>
+#include <errno.h>
+#include "util.h"
+/* PF_ROUTE socket*/
+int rts; 
+/* Destination and gateway addresses */
+struct sockaddr_in rdst, rgw;
+/* Request sequence */
+int rseq;
+int dorouting;
+#else /* Solaris */
 /* route to the server */
 char *route;
+#endif /* Solaris */
 
 /*
 
@@ -54,26 +71,113 @@
 */
 
 void routing_init(char *ip) {
+#if defined (__SVR4) && defined (__sun) /* Solaris */
+  rdst.sin_family = AF_INET;
+  if ( ! inet_pton(AF_INET, ip, &rdst.sin_addr) ) {
+    log("Cannot convert address: %s", strerror(errno));
+    return;
+  }
+
+  if ( (rts = socket(PF_ROUTE, SOCK_RAW, AF_INET )) < 0 ) {
+    log("Cannot open routing socket: %s", strerror(errno));
+    return;
+  }
+
+  struct rt_msg rtm = {
+    .hdr.rtm_msglen = sizeof(struct rt_msg),
+    .hdr.rtm_version = RTM_VERSION,
+    .hdr.rtm_type = RTM_GET,
+    .hdr.rtm_addrs = RTA_DST,
+    .hdr.rtm_pid = getpid(),
+    .hdr.rtm_seq = ++rseq,
+    .addrs[RTAX_DST] = rdst
+  };
+
+  if ( write(rts, &rtm, rtm.hdr.rtm_msglen) != rtm.hdr.rtm_msglen ) {
+    log("Error writing to routing socket: %s", strerror(errno));
+    close(rts);
+    return;
+  }
+
+  while ( read(rts, &rtm, sizeof(struct rt_msg)) > 0 )
+    if ( rtm.hdr.rtm_pid == getpid() && rtm.hdr.rtm_seq == rseq) {
+      /* Check if host route already present */
+      if ( ( rtm.hdr.rtm_flags & RTF_HOST ) != RTF_HOST ) {
+        rgw = rtm.addrs[RTAX_GATEWAY];
+        dorouting = 1;
+      }
+      break;
+    }
+#else /* Solaris */ 
   char buf[256];
-  snprintf(buf, 255, "/bin/ip route get %s", ip);
-  FILE *p = popen(buf, "r");
+  FILE *p;
+
+  snprintf(buf, 255, "%s route get %s", IP_BINARY, ip);
+  p = popen(buf, "r");
   fgets(buf, 255, p);
   /* TODO: check for failure of fgets */
   route = strdup(buf);
   pclose(p);
   /* TODO: check for failure of command */
+#endif /* Solaris */
 }
 
 void routing_start() {
+#if defined (__SVR4) && defined (__sun) /* Solaris */
+  if ( ! dorouting )
+     return;
+
+  struct rt_msg rtm = {
+    .hdr.rtm_msglen = sizeof(struct rt_msg),
+    .hdr.rtm_version = RTM_VERSION,
+    .hdr.rtm_type = RTM_ADD,
+    .hdr.rtm_flags = RTF_HOST | RTF_GATEWAY | RTF_STATIC,
+    .hdr.rtm_addrs = RTA_DST | RTA_GATEWAY,
+    .hdr.rtm_pid = getpid(),
+    .hdr.rtm_seq = ++rseq,
+    .addrs[RTAX_DST] = rdst,
+    .addrs[RTAX_GATEWAY] = rgw
+  };
+
+  if ( write(rts, &rtm, rtm.hdr.rtm_msglen) != rtm.hdr.rtm_msglen ) {
+    log("Error adding route: %s", strerror(errno));
+  }
+#else /* Solaris */
   char buf[256];
-  snprintf(buf, 255, "/bin/ip route replace %s", route);
-  FILE *p = popen(buf, "r");
+  FILE *p;
+
+  snprintf(buf, 255, "%s route replace %s", IP_BINARY, route);
+  p = popen(buf, "r");
   pclose(p);
+#endif /* Solaris */
 }
 
 void routing_end() {
+#if defined (__SVR4) && defined (__sun) /* Solaris */
+  if ( ! dorouting)
+    return;
+
+  struct rt_msg rtm = {
+    .hdr.rtm_msglen = sizeof(struct rt_msg),
+    .hdr.rtm_version = RTM_VERSION,
+    .hdr.rtm_type = RTM_DELETE,
+    .hdr.rtm_flags = RTF_HOST | RTF_GATEWAY | RTF_STATIC,
+    .hdr.rtm_addrs = RTA_DST | RTA_GATEWAY,
+    .hdr.rtm_pid = getpid(),
+    .hdr.rtm_seq = ++rseq,
+    .addrs[RTAX_DST] = rdst,
+    .addrs[RTAX_GATEWAY] = rgw
+  };
+
+  if ( write(rts, &rtm, rtm.hdr.rtm_msglen) != rtm.hdr.rtm_msglen ) {
+    log("Error deleting route: %s", strerror(errno));
+  }
+#else /* Solaris */
   char buf[256];
-  snprintf(buf, 255, "/bin/ip route delete %s", route);
-  FILE *p = popen(buf, "r");
+  FILE *p;
+
+  snprintf(buf, 255, "%s route delete %s", IP_BINARY, route);
+  p = popen(buf, "r");
   pclose(p);
+#endif /* Solaris */
 }
Index: Makefile
===================================================================
RCS file: /cvsroot/pptpclient/pptp-linux/Makefile,v
retrieving revision 1.47
retrieving revision 1.49
diff -u -r1.47 -r1.49
--- Makefile	14 May 2008 06:32:52 -0000	1.47
+++ Makefile	24 Jul 2008 05:37:47 -0000	1.49
@@ -1,10 +1,13 @@
-# $Id: Makefile,v 1.47 2008/05/14 06:32:52 quozl Exp $
+# $Id: Makefile,v 1.49 2008/07/24 05:37:47 quozl Exp $
 VERSION=1.7.2
 RELEASE=
 
 #################################################################
-# CHANGE THIS LINE to point to the location of your pppd binary.
+# CHANGE THIS LINE to point to the location of binaries
 PPPD = /usr/sbin/pppd
+# Solaris
+# PPPD = /usr/bin/pppd
+IP = /bin/ip
 #################################################################
 
 BINDIR=$(DESTDIR)/usr/sbin
@@ -47,6 +52,7 @@
 	echo "/* text added by Makefile target config.h */" > config.h
 	echo "#define PPTP_LINUX_VERSION \"$(VERSION)$(RELEASE)\"" >> config.h
 	echo "#define PPPD_BINARY \"$(PPPD)\"" >> config.h
+	echo "#define IP_BINARY \"$(IP)\"" >> config.h
 
 vector_test: vector_test.o vector.o
 	$(CC) -o vector_test vector_test.o vector.o