From: Ken Clark <kclark@direct.ca>
To: perkins@netmass.com
Subject: Patches for OPENSTEP 4.x
X-Listprocessor-Version: 6.0 -- ListProcessor by Anastasios Kotsikonas
X-Comment: To unsubscribe send message to listproc@listproc.thoughtport.com
X-Mailer: Mozilla 3.0 (Win95; I)

I have ported NeXT-ppp2.3-0.5.0 to Mach OPENSTEP 4.1 for
Intel.  Here are my patches against native ppp-2.3b3 plus
NeXT-ppp2.3-0.5.0.  It works well enough that I can send this mail, but
I have seen at least one panic so far, so caveat emptor.  I tried to
tread lightly on the sources.

Cheers


Ken Clark
diff -r -c -N -d ppp-2.3b3/NeXT/Makefile ppp-2.3b3.ken/NeXT/Makefile
*** ppp-2.3b3/NeXT/Makefile	Wed Oct  9 14:14:44 1996
--- ppp-2.3b3.ken/NeXT/Makefile	Tue Nov 12 15:25:12 1996
***************
*** 49,61 ****
  #
  #
  
! DFLAGS = -DINET -DKERNEL -DMACH -DPOSIX_KERN \
  	-DNUM_PPP=2 -DVJC -DPPP_COMPRESS \
  	-DDEBUG -DNEW_CLOCAL -DNBPFILTER -DOPTIMIZE_PPPREND
  
  IFLAGS = -I. -I.. -I../pppd
  
! CFLAGS = -pipe -posix $(ARCHFLAGS) $(DFLAGS) $(IFLAGS) 
  
  OBJS = bsd-comp.o if_ppp.o nbq.o ppp_tty.o vjcompress.o
  SRCS = $(OBJS:.o=.c)
--- 49,62 ----
  #
  #
  
! DFLAGS = -DNS_TARGET=41 -D_POSIX_SOURCE -D__BIT_TYPES_DEFINED__ \
! 	-DINET -DKERNEL -DMACH -DPOSIX_KERN \
  	-DNUM_PPP=2 -DVJC -DPPP_COMPRESS \
  	-DDEBUG -DNEW_CLOCAL -DNBPFILTER -DOPTIMIZE_PPPREND
  
  IFLAGS = -I. -I.. -I../pppd
  
! CFLAGS = -pipe -static $(ARCHFLAGS) $(DFLAGS) $(IFLAGS) 
  
  OBJS = bsd-comp.o if_ppp.o nbq.o ppp_tty.o vjcompress.o
  SRCS = $(OBJS:.o=.c)
***************
*** 66,72 ****
  #
  all:	ppp_reloc
  	cd bpf; $(MAKE) ARCHFLAGS="$(ARCHFLAGS)" all
- 
  
  install: all
  	/bin/mkdirs $(ETCDIR) $(LKS_DIR)
--- 67,72 ----
diff -r -c -N -d ppp-2.3b3/NeXT/Makefile.top ppp-2.3b3.ken/NeXT/Makefile.top
*** ppp-2.3b3/NeXT/Makefile.top	Wed Oct  9 14:38:58 1996
--- ppp-2.3b3.ken/NeXT/Makefile.top	Tue Nov 12 16:53:17 1996
***************
*** 13,18 ****
--- 13,19 ----
  ARCHFLAGS =
  
  all:
+ 	cd libposix; $(MAKE) -f Makefile.NeXT ARCHFLAGS="$(ARCHFLAGS)" all
  	cd chat; $(MAKE) -f Makefile.NeXT ARCHFLAGS="$(ARCHFLAGS)" all
  	cd pppstats; $(MAKE) -f Makefile.NeXT ARCHFLAGS="$(ARCHFLAGS)" all
  	cd pppd; $(MAKE) -f Makefile.NeXT ARCHFLAGS="$(ARCHFLAGS)" all
***************
*** 30,35 ****
--- 31,37 ----
  
  clean: 
  	rm -f *~
+ 	(cd libposix; $(MAKE) -f Makefile.NeXT clean)
  	(cd chat; $(MAKE) -f Makefile.NeXT clean)
  	(cd pppstats; $(MAKE) -f Makefile.NeXT clean)
  	(cd pppd; $(MAKE) -f Makefile.NeXT clean)
diff -r -c -N -d ppp-2.3b3/NeXT/README.4x ppp-2.3b3.ken/NeXT/README.4x
*** ppp-2.3b3/NeXT/README.4x	Wed Dec 31 16:00:00 1969
--- ppp-2.3b3.ken/NeXT/README.4x	Wed Nov 13 13:19:33 1996
***************
*** 0 ****
--- 1,86 ----
+ I have merged the ppp3.2 sources with the ppp-5 port by NeXT for OPENSTEP 4.x.  
+ ppp-5 is what NeXT calls ppp2.2b3 plus NeXT-ppp2.2-0.4.5.  I am using
+ OPENSTEP 4.1 for Mach GAMMA as a build environment.
+ 
+ In general I tried to tread lightly on the code (mainly because I don't
+ really know what I am doing ¬.
+ 
+ Here are random notes on the port of ppp3.2 to OPENSTEP 4.1 GAMMA.
+ 
+ Ken Clark
+ kclark@direct.ca
+ 
+ (0)
+ 
+ The userland stuff sufferes from NeXT's lack of POSIX support.  I added
+ an emulation library "libposix" to that end.  See libposix/libposix.c
+ for details.
+ 
+ (1)
+ 
+ 4.1 does not seem to have a kern/lock.h, but does have a kernserv/lock.h.  Is
+ that what we want?  I have included kernserv/lock.h for now for NS_TARGET
+ >= 41 and kern/lock.h for NS_TARGET==40.  
+ 
+ originally if_ppp.c had:
+ 
+ #if NS_TARGET >= 40
+ #include <kern/lock.h>
+ #endif /* NS_TARGET */
+ 
+ while ppp_tty.c had
+ 
+ #ifdef NS_TARGET
+ #include <kern/lock.h>
+ #endif /* NS_TARGET */
+ 
+ I assume the latter was a type-o.
+ 
+ (2)
+ 
+ 4.1 GAMMA does not seem to define NS_TARGET as 41.  Sheesh.
+ 
+ (3)
+ 
+ 4.1 complains whenever sys/user.h is included about an undefined type
+ lock_data_t.  I can't seem to find lock_data_t anywhere, although there
+ is a lock_t and a simple_lock_data_t.  For now, my fix is to
+ typedef simple_lock_data_t lock_data_t where needed before sys/user.h
+ gets included.  Note that sys/proc includes sys/user.h.
+ What is the correct fix for sys/user.h?  What is going on with 
+ these structures?
+ 
+ (4)
+ 
+ NeXT can't seem to decide whether they define bittypes 
+ such as typedef unsigned short u_int16_t.  __BIT_TYPES_DEFINED__ is
+ defined in the Makefiles to be consistent with the user-land stuff.  I removed
+ the typedef from bsd-comp.c as it seems to be defined in if_pppvar.h 
+ anyway.
+ 
+ (5)
+ 
+ As usual, the NeXT code is a colorfull combination of hard and soft
+ tabs.  I followed the convention in the surrounding (nearest) code.  
+ Anyone want to run the code through a beautifier?
+ 
+ (6)
+ 
+ NeXT eliminated the global variable "time" in OPENSTEP 4.x.  It is 
+ replaced by the call to ns_time_to_timeval(clock_value(System), &tv_time).
+ I used tv_time as a variable instead of "time" because that is the
+ way NeXT did it in their ppp2.2 4.x port (presumably in case they change their
+ mind and pollute the namespace with a "time" variable again).  This
+ makes for a lot of #if macros in if_ppp.c.  I don't have a complete
+ grasp of how often I need to check the time.  Check comments that say
+ /*  I am assuming the time is different here than above. */  It is
+ all probably okay, but plan to look into this some more.
+ 
+ (7)
+ 
+ NeXT didn't do a port of the bfd stuff to 4.x and I don't use it myself,
+ so it is neglected.  I did a couple of hacks to get it to compile under
+ 4.1, but nothing more.  It probably doesn't work, but you never know.
+ 
+ 
+ 
diff -r -c -N -d ppp-2.3b3/NeXT/bpf/Makefile ppp-2.3b3.ken/NeXT/bpf/Makefile
*** ppp-2.3b3/NeXT/bpf/Makefile	Wed Oct  9 14:14:50 1996
--- ppp-2.3b3.ken/NeXT/bpf/Makefile	Tue Nov 12 16:41:29 1996
***************
*** 27,37 ****
  #
  #
  
! DFLAGS = -DVJC -DPPP_COMPRESS -DNBPFILTER=5 -DPOSIX_KERN \
  	-DKERNEL -DMACH_USER_API -DMACH
  
  
! CFLAGS = -pipe -O -posix $(ARCHFLAGS) $(DFLAGS) $(IFLAGS) 
  
  OBJS = promisc.o bpf_filter.o bpf.o NeXT_Support.o ../nbq.o
  SRCS = $(OBJS:.o=.c)
--- 27,38 ----
  #
  #
  
! DFLAGS = -DNS_TARGET=41 -D_POSIX_SOURCE -D__BIT_TYPES_DEFINED__ \
! 	-DVJC -DPPP_COMPRESS -DNBPFILTER=5 -DPOSIX_KERN \
  	-DKERNEL -DMACH_USER_API -DMACH
  
  
! CFLAGS = -pipe -static -O $(ARCHFLAGS) $(DFLAGS) $(IFLAGS) 
  
  OBJS = promisc.o bpf_filter.o bpf.o NeXT_Support.o ../nbq.o
  SRCS = $(OBJS:.o=.c)
diff -r -c -N -d ppp-2.3b3/NeXT/bpf/NeXT_Support.c ppp-2.3b3.ken/NeXT/bpf/NeXT_Support.c
*** ppp-2.3b3/NeXT/bpf/NeXT_Support.c	Mon Oct  7 17:16:42 1996
--- ppp-2.3b3.ken/NeXT/bpf/NeXT_Support.c	Tue Nov 12 16:48:27 1996
***************
*** 11,16 ****
--- 11,19 ----
  #include "netbuf.h"
  #include <sys/buf.h>
  #include <sys/time.h>
+ #if NS_TARGET >= 41
+ typedef simple_lock_data_t lock_data_t;		/* XXX */
+ #endif /* NS_TARGET */
  #include <sys/proc.h>
  #include <machine/user.h>
  #include <sys/ioctl.h>
diff -r -c -N -d ppp-2.3b3/NeXT/bpf/bpf.c ppp-2.3b3.ken/NeXT/bpf/bpf.c
*** ppp-2.3b3/NeXT/bpf/bpf.c	Mon Oct  7 17:16:43 1996
--- ppp-2.3b3.ken/NeXT/bpf/bpf.c	Tue Nov 12 16:47:28 1996
***************
*** 58,63 ****
--- 58,66 ----
  #include "netbuf.h"
  #include <sys/buf.h>
  #include <sys/time.h>
+ #if NS_TARGET >= 41
+ typedef simple_lock_data_t lock_data_t;		/* XXX */
+ #endif /* NS_TARGET */
  #include <sys/proc.h>
  #include <machine/user.h>
  #include <sys/ioctl.h>
***************
*** 1217,1223 ****
  	register struct bpf_hdr *hp;
  	register int totlen, curlen;
  	register int hdrlen = d->bd_bif->bif_hdrlen;
! 
  
  	/*
  	 * Figure out how many bytes to move.  If the packet is
--- 1220,1228 ----
  	register struct bpf_hdr *hp;
  	register int totlen, curlen;
  	register int hdrlen = d->bd_bif->bif_hdrlen;
! #if NS_TARGET >= 40
! 	struct timeval tv_time;
! #endif
  
  	/*
  	 * Figure out how many bytes to move.  If the packet is
***************
*** 1268,1274 ****
--- 1273,1284 ----
  #elif defined(sun)
  	uniqtime(&hp->bh_tstamp);
  #else
+ #if NS_TARGET >= 40
+ 	ns_time_to_timeval(clock_value(System), &tv_time);
+ 	hp->bh_tstamp = tv_time;
+ #else
  	hp->bh_tstamp = time;
+ #endif /* NS_TARGET */
  #endif
  
  	hp->bh_datalen = pktlen;
diff -r -c -N -d ppp-2.3b3/NeXT/bpf/promisc.c ppp-2.3b3.ken/NeXT/bpf/promisc.c
*** ppp-2.3b3/NeXT/bpf/promisc.c	Mon Oct  7 17:16:48 1996
--- ppp-2.3b3.ken/NeXT/bpf/promisc.c	Tue Nov 12 16:38:07 1996
***************
*** 51,56 ****
--- 51,59 ----
  #define INET 1
  
  #include <sys/param.h>
+ #if NS_TARGET >= 41
+ typedef simple_lock_data_t lock_data_t;		/* XXX */
+ #endif /* NS_TARGET */
  #include <sys/proc.h>
  #include <sys/user.h>
  #include "netbuf.h"
diff -r -c -N -d ppp-2.3b3/NeXT/bsd-comp.c ppp-2.3b3.ken/NeXT/bsd-comp.c
*** ppp-2.3b3/NeXT/bsd-comp.c	Wed Oct  9 14:14:46 1996
--- ppp-2.3b3.ken/NeXT/bsd-comp.c	Tue Nov 12 15:32:43 1996
***************
*** 54,60 ****
  
  #include <sys/types.h>
  #include <sys/param.h>
- #include <sys/types.h>
  #include <sys/socket.h>
  
  #define	KERNEL 1
--- 54,59 ----
***************
*** 62,67 ****
--- 61,67 ----
  #include <net/if.h>
  
  #include <net/ppp_defs.h>
+ 
  #include <net/if_ppp.h>
  
  #include "nbq.h"
***************
*** 93,99 ****
  #include <netinet/ip.h>
  
  #define	mtod(m,type)	((type)NB_MAP(m))
- typedef unsigned short u_int16_t;
  
  /*
   * PPP "BSD compress" compression
--- 93,98 ----
diff -r -c -N -d ppp-2.3b3/NeXT/if_ppp.c ppp-2.3b3.ken/NeXT/if_ppp.c
*** ppp-2.3b3/NeXT/if_ppp.c	Wed Oct  9 14:14:47 1996
--- ppp-2.3b3.ken/NeXT/if_ppp.c	Tue Nov 12 16:35:33 1996
***************
*** 90,97 ****
--- 90,107 ----
  
  /* #include "ppp.h" */
  
+ #if NS_TARGET >= 40
+ #if NS_TARGET >= 41
+ #include <kernserv/lock.h>
+ #else
+ #include <kern/lock.h>
+ #endif /* NS_TARGET */
+ #endif /* NS_TARGET */
  
  #include <sys/param.h>
+ #if NS_TARGET >= 41
+ typedef simple_lock_data_t lock_data_t;		/* XXX */
+ #endif /* NS_TARGET */
  #include <sys/proc.h>
  #include "netbuf.h"
  #include <sys/socket.h>
***************
*** 99,105 ****
--- 109,117 ----
  #include <sys/time.h>
  #include <sys/ioctl.h>
  #include <sys/errno.h>
+ #if !(NS_TARGET >= 40)
  #include <kernserv/prototypes.h>
+ #endif
  #if defined(m68k)
  #import "spl.h"
  #else
***************
*** 357,362 ****
--- 369,377 ----
  {
      int nppp, i;
      struct ppp_softc *sc;
+ #if NS_TARGET >= 40
+     struct timeval tv_time;
+ #endif /* NS_TARGET */
  
      for (nppp = 0, sc = ppp_softc; nppp < NUM_PPP; nppp++, sc++)
  	if (sc->sc_xfer == pid) {
***************
*** 383,389 ****
--- 398,411 ----
      for (i = 0; i < NUM_NP; ++i)
  	sc->sc_npmode[i] = NPMODE_ERROR;
      /* XXX - I'm not sure why the npqueue was zapped here... */
+ 
+ #if NS_TARGET >= 40
+     ns_time_to_timeval(clock_value(System), &tv_time);
+     sc->sc_last_sent = sc->sc_last_recv = tv_time.tv_sec;
+ #else
      sc->sc_last_sent = sc->sc_last_recv = time.tv_sec;
+ #endif
+ 
      sc->sc_compsched = 0;
      sc->sc_decompsched = 0;
  
***************
*** 446,451 ****
--- 468,477 ----
  #ifdef	HAS_BROKEN_TIOCSPGRP
      struct tty *tp = sc->sc_devp;
  #endif
+ #if NS_TARGET >= 40
+ 	struct timeval tv_time;
+ #endif /* NS_TARGET */
+ 
  
      switch (cmd) {
      case FIONREAD:
***************
*** 617,623 ****
--- 643,654 ----
  
      case PPPIOCGIDLE:
  	s = splimp();
+ #if NS_TARGET >= 40
+ 	ns_time_to_timeval(clock_value(System), &tv_time);
+ 	t = tv_time.tv_sec;
+ #else
  	t = time.tv_sec;
+ #endif /* NS_TARGET */
  	((struct ppp_idle *)data)->xmit_idle = t - sc->sc_last_sent;
  	((struct ppp_idle *)data)->recv_idle = t - sc->sc_last_recv;
  	splx(s);
***************
*** 1140,1145 ****
--- 1171,1179 ----
      NETBUF_T m;
      u_char *cp;
      int address, control, protocol;
+ #if NS_TARGET >= 40
+     struct timeval tv_time;
+ #endif
  
      /*
       * Grab a packet to send: first try the fast queue, then the
***************
*** 1160,1176 ****
      control = PPP_CONTROL(cp);
      protocol = PPP_PROTOCOL(cp);
  
  #ifdef NETBUF_PROXY
  	m->pktinfo.second.tv_sec = time.tv_sec;
  	m->pktinfo.second.tv_usec = time.tv_usec;
! #endif
  
      switch (protocol) {
      case PPP_IP:
  	/*
  	 * Update the time we sent the most recent packet.
  	 */
! 	sc->sc_last_sent = time.tv_sec;
  
  #ifdef VJC
  	/*
--- 1194,1223 ----
      control = PPP_CONTROL(cp);
      protocol = PPP_PROTOCOL(cp);
  
+ #if NS_TARGET >= 40
+ 	ns_time_to_timeval(clock_value(System), &tv_time);
+ #endif /* NS_TARGET */
+ 
  #ifdef NETBUF_PROXY
+ #if NS_TARGET >= 40
+ 	m->pktinfo.second.tv_sec = tv_time.tv_sec;
+ 	m->pktinfo.second.tv_usec = tv_time.tv_usec;
+ #else
  	m->pktinfo.second.tv_sec = time.tv_sec;
  	m->pktinfo.second.tv_usec = time.tv_usec;
! #endif /* NS_TARGET */
! #endif /* NETBUF_PROXY */
  
      switch (protocol) {
      case PPP_IP:
  	/*
  	 * Update the time we sent the most recent packet.
  	 */
! #if NS_TARGET >= 40
! 	sc->sc_last_sent = tv_time.tv_sec;
! #else
!         sc->sc_last_sent = time.tv_sec;
! #endif /* NS_TARGET */
  
  #ifdef VJC
  	/*
***************
*** 1299,1306 ****
--- 1346,1360 ----
      }
  
  #ifdef NETBUF_PROXY
+ #if NS_TARGET >= 4.0
+ 	/*  I am assuming the time is different here than above. */
+ 	ns_time_to_timeval(clock_value(System), &tv_time);
+ 	m->pktinfo.third.tv_sec = tv_time.tv_sec;
+ 	m->pktinfo.third.tv_usec = tv_time.tv_usec;
+ #else
  	m->pktinfo.third.tv_sec = time.tv_sec;
  	m->pktinfo.third.tv_usec = time.tv_usec;
+ #endif
  #endif	
  
      s = splimp();
***************
*** 1469,1479 ****
      NETBUF_T dmp;
      u_char *iphdr;
      u_int hlen;
  
  #ifdef NETBUF_PROXY
  	m->pktinfo.third.tv_sec = time.tv_sec;
  	m->pktinfo.third.tv_usec = time.tv_usec;
! #endif	    
  
      incr_cnt(sc->sc_if, if_ipackets);
  
--- 1523,1542 ----
      NETBUF_T dmp;
      u_char *iphdr;
      u_int hlen;
+ #if NS_TARGET >= 40
+     struct timeval tv_time;
+ #endif /* NS_TARGET */
  
  #ifdef NETBUF_PROXY
+ #if NS_TARGET >= 40
+ 	ns_time_to_timeval(clock_value(System), &tv_time);
+ 	m->pktinfo.third.tv_sec = tv_time.tv_sec;
+ 	m->pktinfo.third.tv_usec = tv_time.tv_usec;
+ #else
  	m->pktinfo.third.tv_sec = time.tv_sec;
  	m->pktinfo.third.tv_usec = time.tv_usec;
! #endif /* NS_TARGET */
! #endif NETBUF_PROXY
  
      incr_cnt(sc->sc_if, if_ipackets);
  
***************
*** 1666,1674 ****
  
  #ifdef NETBUF_PROXY
      m->pktinfo.size3 = NB_SIZE(m);
      m->pktinfo.fourth.tv_sec = time.tv_sec;
      m->pktinfo.fourth.tv_usec = time.tv_usec;
! #endif	    
  
  #ifdef NBPFILTER
      /*
--- 1729,1744 ----
  
  #ifdef NETBUF_PROXY
      m->pktinfo.size3 = NB_SIZE(m);
+ #if NS_TARGET >= 40
+     /*  I am assuming the time is different here than above. */
+     ns_time_to_timeval(clock_value(System), &tv_time);
+     m->pktinfo.fourth.tv_sec = tv_time.tv_sec;
+     m->pktinfo.fourth.tv_usec = tv_time.tv_usec;
+ #else
      m->pktinfo.fourth.tv_sec = time.tv_sec;
      m->pktinfo.fourth.tv_usec = time.tv_usec;
! #endif /* NS_TARGET */
! #endif /* NETBUF_PROXY */
  
  #ifdef NBPFILTER
      /*
***************
*** 1699,1705 ****
--- 1769,1781 ----
  	}
  	NB_SHRINK_TOP(m, PPP_HDRLEN);
  	inet_queue(sc->sc_if, NB_TO_nb(m));
+ #if NS_TARGET >= 40
+ 	/*  I am assuming the time is different here than above. */
+ 	ns_time_to_timeval(clock_value(System), &tv_time);
+ 	sc->sc_last_recv = tv_time.tv_sec; /* update time of last pkt rcvd */
+ #else
  	sc->sc_last_recv = time.tv_sec; /* update time of last pkt rcvd */
+ #endif
  	return;
  #endif
  
diff -r -c -N -d ppp-2.3b3/NeXT/if_pppvar.h ppp-2.3b3.ken/NeXT/if_pppvar.h
*** ppp-2.3b3/NeXT/if_pppvar.h	Mon Oct  7 16:51:30 1996
--- ppp-2.3b3.ken/NeXT/if_pppvar.h	Tue Nov 12 15:35:10 1996
***************
*** 20,26 ****
--- 20,28 ----
  /* Portions Copyright (C) 1990 Brad K. Clements (streams support)
   */
  
+ #if !(NS_TARGET >= 40)
  #import <kernserv/prototypes.h>
+ #endif /* NS_TARGET */
  
  /*
   * Supported network protocols.  These values are used for
***************
*** 34,40 ****
--- 36,44 ----
  
  /* only defined in the posix universe... */
  /*typedef	int pid_t; */
+ #ifndef __BIT_TYPES_DEFINED__
  typedef unsigned short u_int16_t;
+ #endif /* __BIT_TYPES_DEFINED */
  
  struct ppp_softc {
  	netif_t	sc_if;		/* network-visible interface */
diff -r -c -N -d ppp-2.3b3/NeXT/nbq.h ppp-2.3b3.ken/NeXT/nbq.h
*** ppp-2.3b3/NeXT/nbq.h	Mon Oct  7 17:05:50 1996
--- ppp-2.3b3.ken/NeXT/nbq.h	Tue Nov 12 14:46:03 1996
***************
*** 15,21 ****
--- 15,23 ----
  #define KERNEL 1
  
  #include <sys/types.h>
+ #if !(NS_TARGET >= 40)
  #include <kernserv/prototypes.h>
+ #endif /* NS_TARGET */
  
  #include "netbuf.h"
  typedef u_int mark_t;
diff -r -c -N -d ppp-2.3b3/NeXT/ppp_tty.c ppp-2.3b3.ken/NeXT/ppp_tty.c
*** ppp-2.3b3/NeXT/ppp_tty.c	Mon Oct  7 16:57:39 1996
--- ppp-2.3b3.ken/NeXT/ppp_tty.c	Wed Nov 13 14:18:40 1996
***************
*** 91,97 ****
--- 91,108 ----
  #define KERNEL_FEATURES 1
  #define INET 1
  
+ #if NS_TARGET >= 40
+ #if NS_TARGET >= 41
+ #include <kernserv/lock.h>
+ #else
+ #include <kern/lock.h>
+ #endif /* NS_TARGET */
+ #endif /* NS_TARGET */
+ 
  #include <sys/param.h>
+ #if NS_TARGET >= 41
+ typedef simple_lock_data_t lock_data_t;		/* XXX */
+ #endif /* NS_TARGET */
  #include <sys/proc.h>
  #include <sys/user.h>
  #include "netbuf.h"
***************
*** 103,110 ****
  #include <sys/dk.h>
  #include <sys/uio.h>
  #include <sys/errno.h>
  #include <machine/param.h>
! 
  
  #include <kernserv/prototypes.h>
  /* NeXT broke spl.h in 3.2/m68k. Thanks EPS! */
--- 114,123 ----
  #include <sys/dk.h>
  #include <sys/uio.h>
  #include <sys/errno.h>
+ #if !(NS_TARGET >= 40)
+ /*  XXX what happened to this header file? */
  #include <machine/param.h>
! #endif
  
  #include <kernserv/prototypes.h>
  /* NeXT broke spl.h in 3.2/m68k. Thanks EPS! */
***************
*** 804,810 ****
--- 817,827 ----
       * drained the t_outq.
       */
      if (!idle && (sc->sc_flags & SC_TIMEOUT) == 0) {
+ #if NS_TARGET >= 40
+ 	timeout(ppp_timeout, (void *) sc, 1);
+ #else
  	ns_timeout(ppp_timeout, (void *) sc, 1 * (1000000000L / HZ), CALLOUT_PRI_SOFTINT0);
+ #endif /*NS_TARGET */
  	sc->sc_flags |= SC_TIMEOUT;
      }
  
diff -r -c -N -d ppp-2.3b3/chat/Makefile.NeXT ppp-2.3b3.ken/chat/Makefile.NeXT
*** ppp-2.3b3/chat/Makefile.NeXT	Mon Oct  7 11:27:25 1996
--- ppp-2.3b3.ken/chat/Makefile.NeXT	Tue Nov 12 13:30:29 1996
***************
*** 12,17 ****
--- 12,18 ----
  
  SRCS =	 chat.c
  OBJS =	 chat.o
+ LIBS =   ../libposix/libposix.o
  
  MANPAGES = chat.8
  
***************
*** 22,28 ****
  all:	chat
  
  chat:	$(OBJS)
! 	$(CC) -o chat $(CFLAGS) $(OBJS)
  
  install:
  	/bin/mkdirs $(MANDIR)/man8 $(BINDIR) 
--- 23,29 ----
  all:	chat
  
  chat:	$(OBJS)
! 	$(CC) -o chat $(CFLAGS) $(OBJS) $(LIBS)
  
  install:
  	/bin/mkdirs $(MANDIR)/man8 $(BINDIR) 
diff -r -c -N -d ppp-2.3b3/libposix/Makefile.NeXT ppp-2.3b3.ken/libposix/Makefile.NeXT
*** ppp-2.3b3/libposix/Makefile.NeXT	Wed Dec 31 16:00:00 1969
--- ppp-2.3b3.ken/libposix/Makefile.NeXT	Tue Nov 12 16:54:15 1996
***************
*** 0 ****
--- 1,10 ----
+ #ARCHFLAGS = -arch i386 -arch m68k
+ ARCHFLAGS =
+ 
+ OBJS = libposix.o
+ CFLAGS = -O $(ARCHFLAGS) -posix
+ 
+ all: $(OBJS)
+ 
+ clean:
+ 	rm -f $(OBJS)
diff -r -c -N -d ppp-2.3b3/libposix/libposix.c ppp-2.3b3.ken/libposix/libposix.c
*** ppp-2.3b3/libposix/libposix.c	Wed Dec 31 16:00:00 1969
--- ppp-2.3b3.ken/libposix/libposix.c	Wed Nov 13 13:11:30 1996
***************
*** 0 ****
--- 1,165 ----
+ /*  Yes, that's right:  of all the platforms supported by ppp, 
+     only Mach OpenStep 4.x doesn't support POSIX.  Sheesh.
+ 
+     Stranger still, the POSIX declatations are still in the 4.x header files,
+     and the gcc -posix still defines _POSIX_SOURCE.  So... 
+     we emulate (sometimes badly) the missing POSIX functions.  This
+     is by no means a complete or general POSIX emulation.  Just enough 
+     to get us by for ppp, so we don't have to pollute the rest of the 
+     sources of every other (non-braindead) platform.  Much of the
+     code was snarfed from NeXT's 4.0 ppp port, the rest inspired by
+     "POSIX Programmers Guide" by Donald Lewine.
+     
+     Maybe if we complain NeXT will upgrade to BSD4.4 libs like the rest of
+     the free world (and maybe pink elephants will fly out of my...  -KC)
+  */
+ 
+ #include <signal.h>
+ #include <termios.h>
+ #include <unistd.h>
+ #include <sys/ioctl.h>
+ #include <sys/time.h>
+ #include <errno.h>
+ 
+ int sigemptyset(sigset_t *set)
+ {
+ 	*set = 0;
+ 	return 0;
+ }
+ 
+ int sigaddset(sigset_t *set, int signo)
+ {
+ 	*set |= 1<<signo;
+ 	return 0;
+ }
+ 
+ int sigprocmask(int how, const sigset_t *set, sigset_t *oset)
+ {
+ 	switch(how) {
+ 	case SIG_BLOCK:
+ 		*oset = sigblock(*set);
+ 		break;
+ 	case SIG_UNBLOCK:
+ 		/* XXX How does one emulate this with ancient BSD? (KC) */
+ 		break;
+ 	case SIG_SETMASK:
+ 		*oset = sigsetmask(*set);
+ 		break;
+ 	}
+ 	return 0;
+ }
+ 
+ int sigsuspend(const sigset_t *sigmask)
+ {
+ 	sigpause(*sigmask);
+ }
+ 
+ int sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
+ {
+ 	struct sigvec vec, ovec;
+ 	int st;
+ 
+ 	vec.sv_handler = act->sa_handler;
+ 	vec.sv_mask = act->sa_mask;
+ 	vec.sv_flags = act->sa_flags;
+ 	
+ 	st = sigvec(sig, &vec, &ovec);
+ 
+ 	if (oact) {
+ 		oact->sa_handler = ovec.sv_handler;
+ 		oact->sa_mask = ovec.sv_mask;
+ 		oact->sa_flags = ovec.sv_flags;
+ 	}
+ 
+ 	return st;
+ }
+ 
+ int tcgetattr(int fildes, struct termios *tp)
+ {
+ 	return ioctl(fildes, TIOCGETA, tp);
+ }
+ 
+ int tcsetattr(int fd, int opt, const struct termios *t)
+ {
+ 	int st;
+ 
+ 	switch(opt) {
+  	case TCSANOW:
+ 		st = ioctl(fd, TIOCSETA, t);
+ 		break;
+ 	case TCSADRAIN:
+ 		st = ioctl(fd, TIOCSETAW, t);
+ 		break;
+ 	case TCSAFLUSH:
+ 		st = ioctl(fd, TIOCSETAF, t);
+ 		break;
+ 	default:
+ 		st = -1;
+ 		errno = EINVAL;
+ 		break;
+ 	}
+ 	return st;
+ }
+ 
+ /*  XXX we ignore duration (which is 0 in chat.c anyway).
+  */
+ int tcsendbreak(int fildes, int duration)
+ {
+ 	struct timeval sleepytime;
+ 
+ 	sleepytime.tv_sec = 0;
+ 	sleepytime.tv_usec = 400000;
+ 	if (ioctl(fildes, TIOCSBRK, 0) != -1)
+ 	{
+ 	    select(0, 0, 0, 0, &sleepytime);
+ 	    (void) ioctl(fildes, TIOCCBRK, 0);
+ 	}
+ }
+ 
+ /*  XXX This is the implementation of cfgetospeed from NeXT's ppp-5
+     pppd/sys-NeXT.c.  I don't know whether returning c_ispeed instead
+     of c_ospeed is deliberate or a type-o.
+  */
+ speed_t cfgetospeed(const struct termios *t)
+ {
+ 	return t->c_ispeed;
+ }
+ 
+ int cfsetospeed(struct termios *t, int speed)
+ { 
+ 	t->c_ospeed = speed; 
+ 	return 0; 
+ }
+ 
+ speed_t cfgetispeed(const struct termios *t)
+ {
+ 	return t->c_ispeed;
+ }
+ 
+ int cfsetispeed(struct termios *t, int speed)
+ { 
+ 	t->c_ispeed = speed; 
+ 	return 0; 
+ }
+ 
+ int setsid(void)
+ {
+     int fd;
+ 
+     setpgrp(0, getpid());
+     
+     if ( (fd = open("/dev/tty", O_RDWR | O_NDELAY)) < 0)
+ 	    return -1;
+     ioctl(fd, TIOCNOTTY, NULL);
+     close(fd);
+ 
+     return 0;
+ }
+ 
+ int waitpid(pid_t pid, int *stat_loc, int options)
+ {
+     if (pid == -1) 
+ 	pid = 0;
+     return wait4(pid, (union wait *) stat_loc, options, NULL);
+ }
+ 
diff -r -c -N -d ppp-2.3b3/pppd/Makefile.NeXT ppp-2.3b3.ken/pppd/Makefile.NeXT
*** ppp-2.3b3/pppd/Makefile.NeXT	Wed Oct  9 13:47:00 1996
--- ppp-2.3b3.ken/pppd/Makefile.NeXT	Wed Nov 13 14:41:46 1996
***************
*** 26,32 ****
  # see the README.MSCHAP80 file at the top level.
  #
  
! COMPILE_FLAGS = -DNO_DRAND48 \
  	-DFIXSIGS -DHAS_BROKEN_IOCTL \
  	-DDEBUGUPAP -DDEBUGCHAP -DDEBUGLCP -DDEBUGIPCP
  
--- 26,32 ----
  # see the README.MSCHAP80 file at the top level.
  #
  
! COMPILE_FLAGS = -D__BIT_TYPES_DEFINED__ -DNO_DRAND48 \
  	-DFIXSIGS -DHAS_BROKEN_IOCTL \
  	-DDEBUGUPAP -DDEBUGCHAP -DDEBUGLCP -DDEBUGIPCP
  
***************
*** 36,41 ****
--- 36,43 ----
  # library is installed, uncomment the following.
  
  #LIBS = -ldes
+ LIBS = ../libposix/libposix.o
+ 
  
  COPTS = $(ARCHFLAGS) -O -posix
  
diff -r -c -N -d ppp-2.3b3/pppd/main.c ppp-2.3b3.ken/pppd/main.c
*** ppp-2.3b3/pppd/main.c	Mon Oct  7 23:43:49 1996
--- ppp-2.3b3.ken/pppd/main.c	Wed Nov 13 13:55:14 1996
***************
*** 119,125 ****
  extern	char	*ttyname __P((int));
  extern	char	*getlogin __P((void));
  
! #ifdef ultrix
  #undef	O_NONBLOCK
  #define	O_NONBLOCK	O_NDELAY
  #endif
--- 119,125 ----
  extern	char	*ttyname __P((int));
  extern	char	*getlogin __P((void));
  
! #if defined(ultrix) 
  #undef	O_NONBLOCK
  #define	O_NONBLOCK	O_NDELAY
  #endif
diff -r -c -N -d ppp-2.3b3/pppd/sys-NeXT.c ppp-2.3b3.ken/pppd/sys-NeXT.c
*** ppp-2.3b3/pppd/sys-NeXT.c	Wed Oct  9 14:15:08 1996
--- ppp-2.3b3.ken/pppd/sys-NeXT.c	Wed Nov 13 14:01:54 1996
***************
*** 46,52 ****
--- 46,55 ----
  #include <netinet/in.h>
  #include <netinet/in_systm.h>
  #include <netinet/in_var.h>
+ #if !(NS_TARGET >= 40)
+ /* XXX get an error "duplicate member ip_v under 4.1 GAMMA */
  #include <netinet/ip.h>
+ #endif /* NS_TARGET */
  #include <netinet/if_ether.h>
  #include <net/route.h>
  #include <netinet/in.h>
diff -r -c -N -d ppp-2.3b3/pppstats/Makefile.NeXT ppp-2.3b3.ken/pppstats/Makefile.NeXT
*** ppp-2.3b3/pppstats/Makefile.NeXT	Mon Oct  7 19:49:48 1996
--- ppp-2.3b3.ken/pppstats/Makefile.NeXT	Tue Nov 12 16:55:37 1996
***************
*** 7,16 ****
  BINDIR = /usr/local/ppp/bin
  MANDIR = /usr/local/ppp/man
  
! CFLAGS = -O -posix $(ARCHFLAGS) -I..
  
  SRCS = pppstats.c
! OBJS = pppstats.o
  
  MANPAGES = chat.8
  
--- 7,17 ----
  BINDIR = /usr/local/ppp/bin
  MANDIR = /usr/local/ppp/man
  
! CFLAGS = -O -posix -D__BIT_TYPES_DEFINED__ $(ARCHFLAGS) -I..
  
  SRCS = pppstats.c
! OBJS = pppstats.o 
! LIBS = ../libposix/libposix.o
  
  MANPAGES = chat.8
  
***************
*** 18,24 ****
  all: pppstats
  
  pppstats: $(OBJS)
! 	$(CC) -o pppstats $(CFLAGS) $(OBJS)
  
  install:
  	/bin/mkdirs $(MANDIR)/man8 $(BINDIR) 
--- 19,25 ----
  all: pppstats
  
  pppstats: $(OBJS)
! 	$(CC) -o pppstats $(CFLAGS) $(OBJS) $(LIBS)
  
  install:
  	/bin/mkdirs $(MANDIR)/man8 $(BINDIR) 
