[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

PPP status (buildable)



Hi there,

I just got PPP building on GNU/FreeBSD (I haven't tested it though).

My patch is attached. Please try it and tell me how it works.

A summary of the changes:

 - With makext"bsd" it was giving me Makefiles for BSD make, so i
   set makext="linux" which brings GNU Makefiles. the only weirdness
   with that is that your Makefiles build Linux-specific components
   (rp-pppoe), so i added "#ifdef __linux__" to the corresponding C files.
 - The ksrc variable is completely bogus. it points to a directory with
   kernel patches that are not applied and a Makefile specific to the
   make program that is "usually" run on that kernel. I've just set it
   to ksrc="linux" to get a GNU Makefile.
 - sys-bsd.c, asides from some sanity fixes to support Glibc, and syncing
   interfaces with the rest of PPP's code, I stole the following missing
   functions:
     - netif_get_mtu from sys-linux.c (hope it won't break the interface)
     - sipxfaddr/cipxfaddr from FreeBSD's sys-bsd.c
     - get/set_flags, *bundle*, netif_set_mtu, tty_*, get_if_hwaddr,
       get_first_ethernet from NetBSD's sys-bsd.c

-- 
Robert Millan
diff -Nur ppp.old/configure ppp/configure
--- ppp.old/configure	2003-07-04 20:11:07.000000000 +0200
+++ ppp/configure	2003-07-04 19:20:07.000000000 +0200
@@ -47,7 +47,7 @@
     else
       echo "C compiler not found; hoping for the best."
     fi;;
-  NetBSD|FreeBSD|ULTRIX|OSF1|NeXTStep|SINIX-?|UNIX_SV|UNIX_System_V)
+  NetBSD|ULTRIX|OSF1|NeXTStep|SINIX-?|UNIX_SV|UNIX_System_V)
     state="notincluded";;
 #    NetBSD)
 #      makext="bsd";
@@ -74,15 +74,18 @@
 #        V4.*)	state="known"; ksrc="osf1";;
 #        V[5-9]*) state="late"; ksrc="osf1";;
 #      esac;;
-#    FreeBSD)
-#      makext="bsd";
-#      case $release in
-#        1.*)	state="known"; ksrc="freebsd-old";;
-#        2.[01]*)	state="known"; ksrc="freebsd-2.0";;
-#        2.2.[2-7]*) state="late"; ksrc="freebsd-2.0";;
-#        2.2.8*)   state="known"; ksrc="freebsd-2.2.8";;
-#        3.[0-1]*)	state="known"; ksrc="freebsd-3.0";;
-#      esac;;
+     FreeBSD)
+       makext="bsd";
+       case $release in
+         1.*)	state="known"; ksrc="freebsd-old";;
+         2.[01]*)	state="known"; ksrc="freebsd-2.0";;
+         2.2.[2-7]*) state="late"; ksrc="freebsd-2.0";;
+         2.2.8*)   state="known"; ksrc="freebsd-2.2.8";;
+         3.[0-1]*)	state="known"; ksrc="freebsd-3.0";;
+         *)	state="known"; ksrc="freebsd";;
+       esac;;
+     GNU/FreeBSD)
+       makext="linux"; state="known"; ksrc="linux";;
 #    NeXTStep)
 #      makext="NeXT";
 #      ksrc="NeXT";
diff -Nur ppp.old/freebsd/Makefile.top ppp/freebsd/Makefile.top
--- ppp.old/freebsd/Makefile.top	1970-01-01 01:00:00.000000000 +0100
+++ ppp/freebsd/Makefile.top	2003-07-04 19:20:07.000000000 +0200
@@ -0,0 +1,13 @@
+#
+# ppp top level makefile for *bsd systems
+#
+
+BINDIR?= /usr/sbin
+
+SUBDIR=	chat pppd pppstats
+MAKE+=  BINDIR=$(BINDIR)
+
+#kernel:
+#	@sh -e freebsd/kinstall.sh
+
+.include <bsd.subdir.mk>
diff -Nur ppp.old/pppd/Makefile.linux ppp/pppd/Makefile.linux
--- ppp.old/pppd/Makefile.linux	2003-06-12 01:56:26.000000000 +0200
+++ ppp/pppd/Makefile.linux	2003-07-04 19:20:07.000000000 +0200
@@ -11,8 +11,9 @@
 TARGETS = pppd
 
 PPPDSRCS = main.c magic.c fsm.c lcp.c ipcp.c upap.c chap-new.c md5.c ccp.c \
-	   ecp.c ipxcp.c auth.c options.c sys-linux.c md4.c chap_ms.c \
+	   ecp.c ipxcp.c auth.c options.c md4.c chap_ms.c \
 	   demand.c utils.c tty.c eap.c chap-md5.c
+PPPDSRCS += sys-bsd.c
 
 HEADERS = ccp.h chap-new.h ecp.h fsm.h ipcp.h \
 	ipxcp.h lcp.h magic.h md5.h patchlevel.h pathnames.h pppd.h \
@@ -20,8 +21,9 @@
 
 MANPAGES = pppd.8
 PPPDOBJS = main.o magic.o fsm.o lcp.o ipcp.o upap.o chap-new.o md5.o ccp.o \
-	   ecp.o auth.o options.o demand.o utils.o sys-linux.o ipxcp.o tty.o \
+	   ecp.o auth.o options.o demand.o utils.o ipxcp.o tty.o \
 	   eap.o chap-md5.o
+PPPDOBJS += sys-bsd.o
 
 #
 # include dependencies if present
@@ -32,7 +34,7 @@
 # CC = gcc
 #
 COPTS = -O2 -pipe -Wall -g
-LIBS =
+LIBS = -lutil
 
 # Uncomment the next 2 lines to include support for Microsoft's
 # MS-CHAP authentication protocol.  Also, edit plugins/radius/Makefile.linux.
diff -Nur ppp.old/pppd/plugins/rp-pppoe/common.c ppp/pppd/plugins/rp-pppoe/common.c
--- ppp.old/pppd/plugins/rp-pppoe/common.c	2001-12-14 03:55:20.000000000 +0100
+++ ppp/pppd/plugins/rp-pppoe/common.c	2003-07-04 19:20:07.000000000 +0200
@@ -13,6 +13,8 @@
 *
 ***********************************************************************/
 
+#ifdef __linux__
+
 static char const RCSID[] =
 "$Id: common.c,v 1.1 2001/12/14 02:55:20 mostrows Exp $";
 
@@ -483,3 +485,4 @@
     }
 }
 
+#endif /* __linux__ */
diff -Nur ppp.old/pppd/plugins/rp-pppoe/debug.c ppp/pppd/plugins/rp-pppoe/debug.c
--- ppp.old/pppd/plugins/rp-pppoe/debug.c	2001-12-14 03:55:20.000000000 +0100
+++ ppp/pppd/plugins/rp-pppoe/debug.c	2003-07-04 19:20:07.000000000 +0200
@@ -13,6 +13,8 @@
 *
 ***********************************************************************/
 
+#ifdef __linux__
+
 static char const RCSID[] =
 "$Id: debug.c,v 1.1 2001/12/14 02:55:20 mostrows Exp $";
 
@@ -141,3 +143,6 @@
 	    (unsigned) packet->ethHdr.h_dest[5]);
     dumpHex(fp, packet->payload, ntohs(packet->length));
 }
+
+#endif /* __linux__ */
+
diff -Nur ppp.old/pppd/plugins/rp-pppoe/discovery.c ppp/pppd/plugins/rp-pppoe/discovery.c
--- ppp.old/pppd/plugins/rp-pppoe/discovery.c	2001-12-14 03:55:20.000000000 +0100
+++ ppp/pppd/plugins/rp-pppoe/discovery.c	2003-07-04 19:20:07.000000000 +0200
@@ -8,6 +8,8 @@
 *
 ***********************************************************************/
 
+#ifdef __linux__
+
 static char const RCSID[] =
 "$Id: discovery.c,v 1.1 2001/12/14 02:55:20 mostrows Exp $";
 
@@ -642,3 +644,5 @@
     return;
 }
 
+#endif /* __linux__ */
+
diff -Nur ppp.old/pppd/plugins/rp-pppoe/if.c ppp/pppd/plugins/rp-pppoe/if.c
--- ppp.old/pppd/plugins/rp-pppoe/if.c	2001-12-14 03:55:20.000000000 +0100
+++ ppp/pppd/plugins/rp-pppoe/if.c	2003-07-04 19:20:07.000000000 +0200
@@ -13,6 +13,8 @@
 *
 ***********************************************************************/
 
+#ifdef __linux__
+
 static char const RCSID[] =
 "$Id: if.c,v 1.1 2001/12/14 02:55:20 mostrows Exp $";
 
@@ -1095,3 +1097,5 @@
 }
 
 #endif /* USE_DLPI */
+
+#endif /* __linux__ */
diff -Nur ppp.old/pppd/plugins/rp-pppoe/plugin.c ppp/pppd/plugins/rp-pppoe/plugin.c
--- ppp.old/pppd/plugins/rp-pppoe/plugin.c	2003-04-07 02:01:46.000000000 +0200
+++ ppp/pppd/plugins/rp-pppoe/plugin.c	2003-07-04 19:20:07.000000000 +0200
@@ -21,6 +21,8 @@
 * 2 of the License, or (at your option) any later version.
 ***********************************************************************/
 
+#ifdef __linux__
+
 static char const RCSID[] =
 "$Id: plugin.c,v 1.9 2003/04/07 00:01:46 paulus Exp $";
 
@@ -435,3 +437,6 @@
     close: NULL,
     cleanup: NULL
 };
+
+#endif /* __linux__ */
+
diff -Nur ppp.old/pppd/sys-bsd.c ppp/pppd/sys-bsd.c
--- ppp.old/pppd/sys-bsd.c	2002-12-06 13:06:45.000000000 +0100
+++ ppp/pppd/sys-bsd.c	2003-07-04 20:16:27.000000000 +0200
@@ -89,6 +89,8 @@
 #include <fcntl.h>
 #include <termios.h>
 #include <signal.h>
+#include <pty.h>
+#include <syslog.h>
 #include <sys/ioctl.h>
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -109,12 +111,16 @@
 #include <net/if_dl.h>
 #include <netinet/in.h>
 
+#ifdef IPX_CHANGE
+#include <netipx/ipx.h>
+#endif
+
 #if RTM_VERSION >= 3
 #include <sys/param.h>
 #if defined(NetBSD) && (NetBSD >= 199703)
 #include <netinet/if_inarp.h>
 #else	/* NetBSD 1.2D or later */
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || defined(__GNU_FreeBSD__)
 #include <netinet/if_ether.h>
 #else
 #include <net/if_ether.h>
@@ -122,6 +128,7 @@
 #endif
 #endif
 
+#include "tty.h"
 #include "pppd.h"
 #include "fsm.h"
 #include "ipcp.h"
@@ -143,7 +150,7 @@
 
 static unsigned char inbuf[512]; /* buffer for chars read from loopback */
 
-static int sockfd;		/* socket for doing interface ioctls */
+static int sock_fd;		/* socket for doing interface ioctls */
 
 static fd_set in_fds;		/* set of fds that wait_input waits for */
 static int max_in_fd;		/* highest fd set in in_fds */
@@ -154,9 +161,40 @@
 static u_int32_t proxy_arp_addr;	/* remote addr for proxy arp */
 
 /* Prototypes for procedures local to this file. */
+static int get_flags __P((int));
+static void set_flags __P((int, int));
 static int dodefaultroute __P((u_int32_t, int));
 static int get_ether_addr __P((u_int32_t, struct sockaddr_dl *));
 
+/********************************************************************
+ *
+ * Functions to read and set the flags value in the device driver
+ */
+
+static int
+get_flags(fd)
+    int fd;
+{    
+    int flags;
+
+    if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &flags) == -1)
+	fatal("ioctl(PPPIOCGFLAGS): %m");
+
+    SYSDEBUG((LOG_DEBUG, "get flags = %x\n", flags));
+    return flags;
+}
+
+/********************************************************************/
+
+static void
+set_flags(fd, flags)
+    int fd, flags;
+{    
+    SYSDEBUG((LOG_DEBUG, "set flags = %x\n", flags));
+
+    if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &flags) == -1)
+	fatal("ioctl(PPPIOCSFLAGS, %x): %m", flags, errno);
+}
 
 /*
  * sys_init - System-dependent initialization.
@@ -165,7 +203,7 @@
 sys_init()
 {
     /* Get an internet socket for doing socket ioctl's on. */
-    if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+    if ((sock_fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
 	fatal("Couldn't create IP socket: %m");
 
     FD_ZERO(&in_fds);
@@ -184,10 +222,10 @@
 
     if (if_is_up) {
 	strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
-	if (ioctl(sockfd, SIOCGIFFLAGS, &ifr) >= 0
+	if (ioctl(sock_fd, SIOCGIFFLAGS, &ifr) >= 0
 	    && ((ifr.ifr_flags & IFF_UP) != 0)) {
 	    ifr.ifr_flags &= ~IFF_UP;
-	    ioctl(sockfd, SIOCSIFFLAGS, &ifr);
+	    ioctl(sock_fd, SIOCSIFFLAGS, &ifr);
 	}
     }
     if (ifaddrs[0] != 0)
@@ -204,7 +242,7 @@
 void
 sys_close()
 {
-    close(sockfd);
+    close(sock_fd);
     if (loop_slave >= 0) {
 	close(loop_slave);
 	close(loop_master);
@@ -252,10 +290,10 @@
 }
 
 /*
- * establish_ppp - Turn the serial port into a ppp interface.
+ * tty_establish_ppp - Turn the serial port into a ppp interface.
  */
 int
-establish_ppp(fd)
+tty_establish_ppp(fd)
     int fd;
 {
     int pppdisc = PPPDISC;
@@ -350,11 +388,11 @@
 
 
 /*
- * disestablish_ppp - Restore the serial port to normal operation.
+ * tty_disestablish_ppp - Restore the serial port to normal operation.
  * This shouldn't call die() because it's called from die().
  */
 void
-disestablish_ppp(fd)
+tty_disestablish_ppp(fd)
     int fd;
 {
     /* Reset non-blocking mode on fd. */
@@ -372,6 +410,91 @@
 }
 
 /*
+ * cfg_bundle - configure the existing bundle.
+ * Used in demand mode.
+ */
+void
+cfg_bundle(mrru, mtru, rssn, tssn)
+    int mrru, mtru, rssn, tssn;
+{
+    abort();
+#ifdef notyet
+    int flags;
+    struct ifreq ifr;
+
+    if (!new_style_driver)
+	return;
+
+    /* set the mrru, mtu and flags */
+    if (ioctl(ppp_dev_fd, PPPIOCSMRRU, &mrru) < 0)
+	error("Couldn't set MRRU: %m");
+    flags = get_flags(ppp_dev_fd);
+    flags &= ~(SC_MP_SHORTSEQ | SC_MP_XSHORTSEQ);
+    flags |= (rssn? SC_MP_SHORTSEQ: 0) | (tssn? SC_MP_XSHORTSEQ: 0)
+	    | (mrru? SC_MULTILINK: 0);
+
+    set_flags(ppp_dev_fd, flags);
+
+    /* connect up the channel */
+    if (ioctl(ppp_fd, PPPIOCCONNECT, &ifunit) < 0)
+	fatal("Couldn't attach to PPP unit %d: %m", ifunit);
+    add_fd(ppp_dev_fd);
+#endif
+}
+
+/*
+ * make_new_bundle - create a new PPP unit (i.e. a bundle)
+ * and connect our channel to it.  This should only get called
+ * if `multilink' was set at the time establish_ppp was called.
+ * In demand mode this uses our existing bundle instead of making
+ * a new one.
+ */
+void
+make_new_bundle(mrru, mtru, rssn, tssn)
+    int mrru, mtru, rssn, tssn;
+{
+    abort();
+#ifdef notyet
+    if (!new_style_driver)
+	return;
+
+    /* make us a ppp unit */
+    if (make_ppp_unit() < 0)
+	die(1);
+
+    /* set the mrru, mtu and flags */
+    cfg_bundle(mrru, mtru, rssn, tssn);
+#endif
+}
+
+/*
+ * bundle_attach - attach our link to a given PPP unit.
+ * We assume the unit is controlled by another pppd.
+ */
+int
+bundle_attach(ifnum)
+	int ifnum;
+{
+    abort();
+#ifdef notyet
+    if (!new_style_driver)
+	return -1;
+
+    if (ioctl(ppp_dev_fd, PPPIOCATTACH, &ifnum) < 0) {
+	if (errno == ENXIO)
+	    return 0;	/* doesn't still exist */
+	fatal("Couldn't attach to interface unit %d: %m\n", ifnum);
+    }
+    if (ioctl(ppp_fd, PPPIOCCONNECT, &ifnum) < 0)
+	fatal("Couldn't connect to interface unit %d: %m", ifnum);
+    set_flags(ppp_dev_fd, get_flags(ppp_dev_fd) | SC_MULTILINK);
+
+    ifunit = ifnum;
+#endif
+    return 1;
+}
+
+/*
  * Check whether the link seems not to be 8-bit clean.
  */
 void
@@ -744,7 +867,104 @@
     return rv;
 }
 
+/*
+ * netif_set_mtu - set the MTU on the PPP network interface.
+ */
+void
+netif_set_mtu(unit, mtu)
+    int unit, mtu;
+{
+    struct ifreq ifr;
+
+    SYSDEBUG((LOG_DEBUG, "netif_set_mtu: mtu = %d\n", mtu));
+
+    memset(&ifr, '\0', sizeof (ifr));
+    strlcpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
+    ifr.ifr_mtu = mtu;
+	
+    if (ifunit >= 0 && ioctl(sock_fd, SIOCSIFMTU, (caddr_t) &ifr) < 0)
+	fatal("ioctl(SIOCSIFMTU): %m");
+}
+
+/*
+ * netif_get_mtu - get the MTU on the PPP network interface.
+ */
+int
+netif_get_mtu(int unit)
+{
+    struct ifreq ifr;
+                                                                                
+    memset (&ifr, '\0', sizeof (ifr));
+    strlcpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
+                                                                                
+    if (ifunit >= 0 && ioctl(sock_fd, SIOCGIFMTU, (caddr_t) &ifr) < 0) {
+        error("ioctl(SIOCGIFMTU): %m (line %d)", __LINE__);
+        return 0;
+    }
+    return ifr.ifr_mtu;
+}
+
+/*
+ * tty_send_config - configure the transmit characteristics of
+ * the ppp interface.
+ */
+void
+tty_send_config(mtu, asyncmap, pcomp, accomp)
+    int mtu;
+    u_int32_t asyncmap;
+    int pcomp, accomp;
+{
+    u_int x;
+#if 0
+    /* Linux code does not do anything with the mtu here */
+    ifnet_set_mtu(-1, mtu);
+#endif
+
+    if (ioctl(ppp_fd, PPPIOCSASYNCMAP, (caddr_t) &asyncmap) < 0)
+	fatal("ioctl(PPPIOCSASYNCMAP): %m");
+
+    x = get_flags(ppp_fd);
+    x = pcomp? x | SC_COMP_PROT: x &~ SC_COMP_PROT;
+    x = accomp? x | SC_COMP_AC: x &~ SC_COMP_AC;
+    x = sync_serial ? x | SC_SYNC : x & ~SC_SYNC;
+    set_flags(ppp_fd, x);
+}
+
+
+/*
+ * ppp_set_xaccm - set the extended transmit ACCM for the interface.
+ */
+void
+tty_set_xaccm(accm)
+    ext_accm accm;
+{
+    if (ioctl(ppp_fd, PPPIOCSXASYNCMAP, accm) < 0 && errno != ENOTTY)
+	warn("ioctl(set extended ACCM): %m");
+}
+
+
+/*
+ * ppp_recv_config - configure the receive-side characteristics of
+ * the ppp interface.
+ */
+void
+tty_recv_config(mru, asyncmap, pcomp, accomp)
+    int mru;
+    u_int32_t asyncmap;
+    int pcomp, accomp;
+{
+    int x;
+
+    if (ioctl(ppp_fd, PPPIOCSMRU, (caddr_t) &mru) < 0)
+	fatal("ioctl(PPPIOCSMRU): %m");
+    if (ioctl(ppp_fd, PPPIOCSRASYNCMAP, (caddr_t) &asyncmap) < 0)
+	fatal("ioctl(PPPIOCSRASYNCMAP): %m");
+    x = get_flags(ppp_fd);
+    x = !accomp? x | SC_REJ_COMP_AC: x &~ SC_REJ_COMP_AC;
+    set_flags(ppp_fd, x);
+}
 
+#if 0
 /*
  * ppp_send_config - configure the transmit characteristics of
  * the ppp interface.
@@ -760,7 +980,7 @@
 
     strlcpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
     ifr.ifr_mtu = mtu;
-    if (ioctl(sockfd, SIOCSIFMTU, (caddr_t) &ifr) < 0)
+    if (ioctl(sock_fd, SIOCSIFMTU, (caddr_t) &ifr) < 0)
 	fatal("ioctl(SIOCSIFMTU): %m");
 
     if (ioctl(ppp_fd, PPPIOCSASYNCMAP, (caddr_t) &asyncmap) < 0)
@@ -774,8 +994,10 @@
     if (ioctl(ppp_fd, PPPIOCSFLAGS, (caddr_t) &x) < 0)
 	fatal("ioctl(PPPIOCSFLAGS): %m");
 }
+#endif
 
 
+#if 0
 /*
  * ppp_set_xaccm - set the extended transmit ACCM for the interface.
  */
@@ -787,8 +1009,10 @@
     if (ioctl(ppp_fd, PPPIOCSXASYNCMAP, accm) < 0 && errno != ENOTTY)
 	warn("ioctl(set extended ACCM): %m");
 }
+#endif
 
 
+#if 0
 /*
  * ppp_recv_config - configure the receive-side characteristics of
  * the ppp interface.
@@ -811,6 +1035,7 @@
     if (ioctl(ppp_fd, PPPIOCSFLAGS, (caddr_t) &x) < 0)
 	fatal("ioctl(PPPIOCSFLAGS): %m");
 }
+#endif
 
 /*
  * ccp_test - ask kernel whether a given compression method
@@ -893,7 +1118,7 @@
 
     memset (&req, 0, sizeof (req));
     strlcpy(req.ifr_name, ifname, sizeof(req.ifr_name));
-    if (ioctl(sockfd, SIOCGPPPSTATS, &req) < 0) {
+    if (ioctl(sock_fd, SIOCGPPPSTATS, &req) < 0) {
 	error("Couldn't get PPP statistics: %m");
 	return 0;
     }
@@ -965,12 +1190,12 @@
     struct ifreq ifr;
 
     strlcpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
-    if (ioctl(sockfd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
+    if (ioctl(sock_fd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
 	error("ioctl (SIOCGIFFLAGS): %m");
 	return 0;
     }
     ifr.ifr_flags |= IFF_UP;
-    if (ioctl(sockfd, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
+    if (ioctl(sock_fd, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
 	error("ioctl(SIOCSIFFLAGS): %m");
 	return 0;
     }
@@ -1016,12 +1241,12 @@
     /* ignore errors, because ppp_fd might have been closed by now. */
 
     strlcpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
-    if (ioctl(sockfd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
+    if (ioctl(sock_fd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
 	error("ioctl (SIOCGIFFLAGS): %m");
 	rv = 0;
     } else {
 	ifr.ifr_flags &= ~IFF_UP;
-	if (ioctl(sockfd, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
+	if (ioctl(sock_fd, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
 	    error("ioctl(SIOCSIFFLAGS): %m");
 	    rv = 0;
 	} else
@@ -1062,11 +1287,11 @@
 	BZERO(&ifra.ifra_mask, sizeof(ifra.ifra_mask));
     BZERO(&ifr, sizeof(ifr));
     strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
-    if (ioctl(sockfd, SIOCDIFADDR, (caddr_t) &ifr) < 0) {
+    if (ioctl(sock_fd, SIOCDIFADDR, (caddr_t) &ifr) < 0) {
 	if (errno != EADDRNOTAVAIL)
 	    warn("Couldn't remove interface address: %m");
     }
-    if (ioctl(sockfd, SIOCAIFADDR, (caddr_t) &ifra) < 0) {
+    if (ioctl(sock_fd, SIOCAIFADDR, (caddr_t) &ifra) < 0) {
 	if (errno != EEXIST) {
 	    error("Couldn't set interface address: %m");
 	    return 0;
@@ -1096,7 +1321,7 @@
     SET_SA_FAMILY(ifra.ifra_broadaddr, AF_INET);
     ((struct sockaddr_in *) &ifra.ifra_broadaddr)->sin_addr.s_addr = h;
     BZERO(&ifra.ifra_mask, sizeof(ifra.ifra_mask));
-    if (ioctl(sockfd, SIOCDIFADDR, (caddr_t) &ifra) < 0) {
+    if (ioctl(sock_fd, SIOCDIFADDR, (caddr_t) &ifra) < 0) {
 	if (errno != EADDRNOTAVAIL)
 	    warn("Couldn't delete interface address: %m");
 	return 0;
@@ -1302,7 +1527,7 @@
     SET_SA_FAMILY(arpreq.arp_pa, AF_INET);
     ((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
     arpreq.arp_flags = ATF_PERM | ATF_PUBL;
-    if (ioctl(sockfd, SIOCSARP, (caddr_t)&arpreq) < 0) {
+    if (ioctl(sock_fd, SIOCSARP, (caddr_t)&arpreq) < 0) {
 	error("Couldn't add proxy arp entry: %m");
 	return 0;
     }
@@ -1324,7 +1549,7 @@
     BZERO(&arpreq, sizeof(arpreq));
     SET_SA_FAMILY(arpreq.arp_pa, AF_INET);
     ((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
-    if (ioctl(sockfd, SIOCDARP, (caddr_t)&arpreq) < 0) {
+    if (ioctl(sock_fd, SIOCDARP, (caddr_t)&arpreq) < 0) {
 	warn("Couldn't delete proxy arp entry: %m");
 	return 0;
     }
@@ -1333,6 +1558,106 @@
 }
 #endif	/* RTM_VERSION */
 
+#ifdef IPX_CHANGE
+/********************************************************************
+ *
+ * sipxfaddr - Config the interface IPX networknumber
+ */
+
+int
+sipxfaddr (int unit, unsigned long int network, unsigned char * node )
+  {
+    int    result = 1;
+
+    int    skfd; 
+    struct sockaddr_ipx  ipx_addr;
+    struct ifreq         ifr;
+    struct sockaddr_ipx *sipx = (struct sockaddr_ipx *) &ifr.ifr_addr;
+    union ipx_net_u net;
+
+    skfd = socket (AF_IPX, SOCK_DGRAM, 0);
+    if (skfd < 0)
+      { 
+	syslog (LOG_DEBUG, "socket(AF_IPX): %m(%d)", errno);
+	result = 0;
+      }
+    else
+      {
+	memset (&ifr, '\0', sizeof (ifr));
+	strcpy (ifr.ifr_name, ifname);
+
+	memcpy (sipx->sipx_addr.x_host.c_host, node, 6);
+	sipx->sipx_len     = sizeof(sipx);
+	sipx->sipx_family  = AF_IPX;
+	sipx->sipx_port    = 0;
+	memset(&net, 0, sizeof(net));
+	net.long_e = htonl (network);
+	sipx->sipx_addr.x_net = net.net_e;
+/*
+ *  Set the IPX device
+ */
+	if (ioctl(skfd, SIOCSIFADDR, (caddr_t) &ifr) < 0)
+	  {
+	    result = 0;
+	    if (errno != EEXIST)
+	      {
+		syslog (LOG_DEBUG,
+			    "ioctl(SIOCAIFADDR, CRTITF): %m(%d)", errno);
+	      }
+	    else
+	      {
+		syslog (LOG_WARNING,
+			"ioctl(SIOCAIFADDR, CRTITF): Address already exists");
+	      }
+	  }
+	close (skfd);
+      }
+    return result;
+  }
+
+/********************************************************************
+ *
+ * cipxfaddr - Clear the information for the IPX network. The IPX routes
+ *	       are removed and the device is no longer able to pass IPX
+ *	       frames.
+ */
+
+int cipxfaddr (int unit)
+  {
+    int    result = 1;
+
+    int    skfd; 
+    struct sockaddr_ipx  ipx_addr;
+    struct ifreq         ifr;
+    struct sockaddr_ipx *sipx = (struct sockaddr_ipx *) &ifr.ifr_addr;
+
+    skfd = socket (AF_IPX, SOCK_DGRAM, 0);
+    if (skfd < 0)
+      { 
+	syslog (LOG_DEBUG, "socket(AF_IPX): %m(%d)", errno);
+	result = 0;
+      }
+    else
+      {
+	memset (&ifr, '\0', sizeof (ifr));
+	strcpy (ifr.ifr_name, ifname);
+
+	sipx->sipx_len     = sizeof(sipx);
+	sipx->sipx_family  = AF_IPX;
+/*
+ *  Set the IPX device
+ */
+	if (ioctl(skfd, SIOCSIFADDR, (caddr_t) &ifr) < 0)
+	  {
+	    syslog (LOG_INFO,
+			"ioctl(SIOCAIFADDR, IPX_DLTITF): %m(%d)", errno);
+	    result = 0;
+	  }
+	close (skfd);
+      }
+    return result;
+  }
+#endif
 
 /*
  * get_ether_addr - get the hardware address of an interface on the
@@ -1354,7 +1679,7 @@
 
     ifc.ifc_len = sizeof(ifs);
     ifc.ifc_req = ifs;
-    if (ioctl(sockfd, SIOCGIFCONF, &ifc) < 0) {
+    if (ioctl(sock_fd, SIOCGIFCONF, &ifc) < 0) {
 	error("ioctl(SIOCGIFCONF): %m");
 	return 0;
     }
@@ -1373,7 +1698,7 @@
 	     * Check that the interface is up, and not point-to-point
 	     * or loopback.
 	     */
-	    if (ioctl(sockfd, SIOCGIFFLAGS, &ifreq) < 0)
+	    if (ioctl(sock_fd, SIOCGIFFLAGS, &ifreq) < 0)
 		continue;
 	    if ((ifreq.ifr_flags &
 		 (IFF_UP|IFF_BROADCAST|IFF_POINTOPOINT|IFF_LOOPBACK|IFF_NOARP))
@@ -1382,7 +1707,7 @@
 	    /*
 	     * Get its netmask and check that it's on the right subnet.
 	     */
-	    if (ioctl(sockfd, SIOCGIFNETMASK, &ifreq) < 0)
+	    if (ioctl(sock_fd, SIOCGIFNETMASK, &ifreq) < 0)
 		continue;
 	    mask = ((struct sockaddr_in *) &ifreq.ifr_addr)->sin_addr.s_addr;
 	    if ((ipaddr & mask) != (ina & mask))
@@ -1418,6 +1743,75 @@
 }
 
 /*
+ * get_if_hwaddr - get the hardware address for the specified
+ * network interface device.
+ */
+int
+get_if_hwaddr(addr, name)
+    u_char *addr;
+    char *name;
+{
+    struct ifreq ifreq;
+    struct sockaddr_dl *sdl = (struct sockaddr_dl *) &ifreq.ifr_addr;
+    int fd;
+
+    if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
+	return 0;
+    (void)memset(sdl, 0, sizeof(*sdl));
+    sdl->sdl_family = AF_LINK;
+    (void)strlcpy(ifreq.ifr_name, name, sizeof(ifreq.ifr_name));
+    if (ioctl(fd, SIOCGIFADDR, &ifreq) == -1) {
+	(void)close(fd);
+	return 0;
+    }
+    (void)close(fd);
+    (void)memcpy(addr, LLADDR(sdl), sdl->sdl_alen);
+    return sdl->sdl_nlen;
+}
+
+/*
+ * get_first_ethernet - return the name of the first ethernet-style
+ * interface on this system.
+ */
+char *
+get_first_ethernet()
+{
+    struct ifreq *ifr, *ifend;
+    static struct ifreq ifreq;
+    struct ifconf ifc;
+    struct ifreq ifs[MAX_IFS];
+
+    /*
+     * Scan through the system's network interfaces.
+     */
+    ifc.ifc_len = sizeof(ifs);
+    ifc.ifc_req = ifs;
+    if (ioctl(sock_fd, SIOCGIFCONF, &ifc) < 0) {
+	warn("ioctl(SIOCGIFCONF): %m");
+	return NULL;
+    }
+    ifend = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
+    for (ifr = ifc.ifc_req; ifr < ifend; ifr = (struct ifreq *)
+	((char *)&ifr->ifr_addr + ifr->ifr_addr.sa_len)) {
+	/*
+	 * Check the interface's internet address.
+	 */
+	if (ifr->ifr_addr.sa_family != AF_INET)
+	    continue;
+	/*
+	 * Check that the interface is up, and not point-to-point or loopback.
+	 */
+	strlcpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name));
+	if (ioctl(sock_fd, SIOCGIFFLAGS, &ifreq) < 0)
+	    continue;
+	if ((ifreq.ifr_flags & (IFF_UP|IFF_POINTOPOINT|IFF_LOOPBACK))
+	    != IFF_UP)
+	    return ifreq.ifr_name;
+    }
+    return NULL;
+}
+
+/*
  * Return user specified netmask, modified by any mask we might determine
  * for address `addr' (in network byte order).
  * Here we scan through the system's list of interfaces, looking for
@@ -1449,7 +1843,7 @@
      */
     ifc.ifc_len = sizeof(ifs);
     ifc.ifc_req = ifs;
-    if (ioctl(sockfd, SIOCGIFCONF, &ifc) < 0) {
+    if (ioctl(sock_fd, SIOCGIFCONF, &ifc) < 0) {
 	warn("ioctl(SIOCGIFCONF): %m");
 	return mask;
     }
@@ -1468,7 +1862,7 @@
 	 * Check that the interface is up, and not point-to-point or loopback.
 	 */
 	strlcpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name));
-	if (ioctl(sockfd, SIOCGIFFLAGS, &ifreq) < 0)
+	if (ioctl(sock_fd, SIOCGIFFLAGS, &ifreq) < 0)
 	    continue;
 	if ((ifreq.ifr_flags & (IFF_UP|IFF_POINTOPOINT|IFF_LOOPBACK))
 	    != IFF_UP)
@@ -1476,7 +1870,7 @@
 	/*
 	 * Get its netmask and OR it into our mask.
 	 */
-	if (ioctl(sockfd, SIOCGIFNETMASK, &ifreq) < 0)
+	if (ioctl(sock_fd, SIOCGIFNETMASK, &ifreq) < 0)
 	    continue;
 	mask |= ((struct sockaddr_in *)&ifreq.ifr_addr)->sin_addr.s_addr;
     }
diff -Nur ppp.old/pppd/tty.c ppp/pppd/tty.c
--- ppp.old/pppd/tty.c	2003-04-07 02:01:46.000000000 +0200
+++ ppp/pppd/tty.c	2003-07-04 20:15:34.000000000 +0200
@@ -125,11 +125,11 @@
 static int open_socket __P((char *));
 static void maybe_relock __P((void *, int));
 
-static int pty_master;		/* fd for master side of pty */
-static int pty_slave;		/* fd for slave side of pty */
-static int real_ttyfd;		/* fd for actual serial port (not pty) */
-static int ttyfd;		/* Serial port file descriptor */
-static char speed_str[16];	/* Serial port speed as string */
+static int pty_master;          /* fd for master side of pty */
+static int pty_slave;           /* fd for slave side of pty */
+static int real_ttyfd;          /* fd for actual serial port (not pty) */
+int ttyfd;                      /* Serial port file descriptor */
+static char speed_str[16];      /* Serial port speed as string */
 
 mode_t tty_mode = (mode_t)-1;	/* Original access permissions to tty */
 int baud_rate;			/* Actual bits/second for serial device */
diff -Nur ppp.old/pppd/tty.h ppp/pppd/tty.h
--- ppp.old/pppd/tty.h	1970-01-01 01:00:00.000000000 +0100
+++ ppp/pppd/tty.h	2003-07-04 20:09:00.000000000 +0200
@@ -0,0 +1 @@
+extern int ttyfd;               /* Serial port file descriptor */

Reply to: