v01i011: Latest version of uipc code, Part04/05

Bradley E. Smith brad at bradley.bradley.edu
Wed Feb 20 12:29:16 AEST 1991


Submitted-by: brad at bradley.bradley.edu (Bradley E. Smith)
Posting-number: Volume 1, Issue 11
Archive-name: uipc/part04

# This is a shell archive.  Remove anything before this line,
# then unpack it by saving it in a file and typing "sh file".
#
# Wrapped by bradley!brad on Fri Feb 15 22:33:23 CST 1991
# Contents:  uipc/lib/ uipc/uipc/ uipc/lib/Makefile uipc/lib/Makefile.m4
#	uipc/lib/__cerror.s uipc/lib/gencall.m4 uipc/lib/generic.m4
#	uipc/lib/perror.c uipc/lib/syserr.s uipc/uipc/conf.h uipc/uipc/domain.h
#	uipc/uipc/fproto.h uipc/uipc/mbuf.h uipc/uipc/protosw.h
#	uipc/uipc/socket.h uipc/uipc/socketvar.h uipc/uipc/un.h
#	uipc/uipc/unpcb.h
 
echo mkdir - uipc/lib
mkdir uipc/lib
chmod u=rwx,g=rx,o=rx uipc/lib
 
echo x - uipc/lib/Makefile
sed 's/^@//' > "uipc/lib/Makefile" <<'@//E*O*F uipc/lib/Makefile//'
#
#	@(#)Makefile	1.1	(Alex Crain) 6/20/89
#
# Makefile for user interface to the uipc loadable driver.
#
# copyright (c) 1989 Alex Crain
#

# CC=gcc
RM=/bin/rm
MV=/bin/mv
ECHO=/bin/echo
M4=/usr/bin/m4
SHELL=/bin/sh
GET=/usr/bin/get
CFLAGS= -O $(VFLAG)

SCCSDIR=../sccs/lib

#
# the various file catagories.
#
CALLS=xxx
SSUPPORT=syserr.o __cerror.o 
CSUPPORT=perror.o 
CSOURCE=perror.c
SCCSFILES=Makefile.m4 gencall.m4 generic.m4 sockpipe.m4\
syserr.s __cerror.s perror.c

all: Makefile.m4
	make libuipc.a CALLS="`m4 Makefile.m4`"

libuipc.a: $(CALLS) $(SSUPPORT) $(CSUPPORT)
	rm -f libuipc.a
	ar cq libuipc.a $(CALLS) $(SSUPPORT) $(CSUPPORT)

$(CALLS): ../sysconfig.m4 gencall.m4 generic.m4
	$(ECHO) "define(MYSELF,$@)" | $(M4) - gencall.m4 > tmp.s
	$(AS) -o $@ tmp.s
	$(RM) tmp.s

$(CSUPPORT): $(?:.o=.c)
	$(CC) $(CFLAGS) -c $(?:.o=.c)

$(SSUPPORT): $(?:.o=.s)
	$(AS) $(?:.o=.s)

$(SCCSFILES):
	$(GET) $(GFLAGS) -p $(SCCSDIR)/s.$@ > $@

depend:
	cat Makefile | sed -e "/^### DEPEND LINE/q" > Make.tmp
	$(CC) -I. -M $(SOURCES) >> Make.tmp
	$(MV) Make.tmp Makefile

clean:
	$(RM) -f libuipc.a *.o \#* *~ core


### DEPEND LINE --- do not delete! ###
@//E*O*F uipc/lib/Makefile//
chmod u=rw,g=rw,o=rw uipc/lib/Makefile
 
echo x - uipc/lib/Makefile.m4
sed 's/^@//' > "uipc/lib/Makefile.m4" <<'@//E*O*F uipc/lib/Makefile.m4//'
divert(-1)
#	@(#)Makefile.m4	1.1	(Alex Crain)	6/19/89
#
#  This file is used to generate the arguments for Makefile.
#
define(concat,$1$2$3$4$5)
define(RESULT,)
define(DEFSYSCALL,`define(`RESULT',concat(RESULT,$2,.o,` '))')
include(../sysconfig.m4)
divert
RESULT
@//E*O*F uipc/lib/Makefile.m4//
chmod u=rw,g=rw,o=rw uipc/lib/Makefile.m4
 
echo x - uipc/lib/__cerror.s
sed 's/^@//' > "uipc/lib/__cerror.s" <<'@//E*O*F uipc/lib/__cerror.s//'
#
	text
	asciz	"@(#)__cerror.s	1.1	(Alex Crain) 6/19/89"
#
#  Error handler for system call stub functions
#
	global	__cerror
__cerror:

	mov.l	%d0,errno
	mov.l	&-1,%d0
	mov.l	&0xffffffff,%a0
	rts

	data

@//E*O*F uipc/lib/__cerror.s//
chmod u=rw,g=rw,o=rw uipc/lib/__cerror.s
 
echo x - uipc/lib/gencall.m4
sed 's/^@//' > "uipc/lib/gencall.m4" <<'@//E*O*F uipc/lib/gencall.m4//'
divert(-1)
#
#	@(#)gencall.m4	1.1	(Alex Crain) 6/20/89
#
# gencall.m4 - generate a system call stub function
#
# This file is used with the command
#
#	echo "define(MYSELF,<syscall>.o)" | m4 - gencall.m4 > <syscall>.s
#
# where syscall is the system call function to be generated. The call must
# be defined in sysconfig.h with a DEFSYSCALL macro.
#
# The resulting stub function is patterened after the code in generic.m4, 
# unless the the file <syscall>.m4 exists, in which case that code will be
# used instead.
#
define(MYNAME,substr(MYSELF,0,eval(len(MYSELF)-2)))
define(DEFSYSCALL,
	`ifelse($2,MYNAME,
		`define(SYSCALL_NUMBER,incr(SYSENT_OFFSET))')
	 define(`SYSENT_OFFSET',incr(SYSENT_OFFSET))')
define(CONCAT,$1$2$3$4)
include(../sysconfig.m4)
include(generic.m4)
sinclude(CONCAT(MYNAME,.m4))
define(SYSCALL_NAME,MYNAME)
define(SCCSDEF,`CONCAT(MYSELF,.s,`	(Alex Crain)	6/1/89')')
divert
PROCEDURE
@//E*O*F uipc/lib/gencall.m4//
chmod u=rw,g=rw,o=rw uipc/lib/gencall.m4
 
echo x - uipc/lib/generic.m4
sed 's/^@//' > "uipc/lib/generic.m4" <<'@//E*O*F uipc/lib/generic.m4//'
#
#	@(#)generic.m4	1.1	(Alex Crain)	6/19/89
#
#	generic form for system calls
#
#
define(PROCEDURE,
`#
	text
	global SYSCALL_NAME
SYSCALL_NAME:
	mov.l	(%sp),-(%sp)			# move the return address
	mov.l	&SYSCALL_NUMBER,4(%sp)			# insert the first argument
	mov.w	&SYSL_SYSCALL,%d0				#
	trap	&0				# trap to syslocal()
	bcc	noerror				# return if status = 0
	jmp	__cerror			# otherwise __cerror()
noerror:					#
	rts					#
')
@//E*O*F uipc/lib/generic.m4//
chmod u=rw,g=rw,o=rw uipc/lib/generic.m4
 
echo x - uipc/lib/perror.c
sed 's/^@//' > "uipc/lib/perror.c" <<'@//E*O*F uipc/lib/perror.c//'
#ifndef LINT
static char * sccsdef = "@(#)perror.c	1.1	(Alex Crain) 6/19/89";
#endif

/*
 *
 * Replace ment for the perror(3c) subroutine. Note that sys_errlist and
 * sys_nerr have been renamed to uipc_errlist and uipc_lasterr, and that 
 * uipc_firsterr has been added. uipc_firsterr and uipc_lasterr represent
 * the maximum negative and posative offsets to uipc_errlist, respectively.
 *
 * Note also that we don't check for overflow of the print buffer, but 1024
 * should be enough.
 */

void
perror(str)
  char * str;
{
   extern int errno;
   extern int uipc_lasterr;
   extern int uipc_firsterr;
   extern char * uipc_errlist[];
   int offset = (int) ((char) errno);
   char buffer[1024];

   if (str && strlen (str))
    {
       strcpy (buffer, str);
       strcat (buffer, ": ");
    }
   else
       buffer[0] = '\0';

   if (offset == 0 ||
       (offset < 0 && offset >= uipc_firsterr) ||
       (offset > 0 && offset <= uipc_lasterr))

    {
       strcat (buffer, uipc_errlist[offset]);
       strcat (buffer, ".\n");
    }
   else
       sprintf (&buffer[strlen (buffer)], "Unknown error # %d.\n", errno);

   write (2, buffer, strlen (buffer));
   return;
}
@//E*O*F uipc/lib/perror.c//
chmod u=rw,g=rw,o=rw uipc/lib/perror.c
 
echo x - uipc/lib/syserr.s
sed 's/^@//' > "uipc/lib/syserr.s" <<'@//E*O*F uipc/lib/syserr.s//'
#
		text
		asciz	"@(#)syserr.s	1.1	(Alex Crain) 6/19/89"

#
#  System error messages for uipc perror() function.
#

ERROR0:		asciz	"Error 0"			# 0

#
#  Standard unix errors
#

EPERM:		asciz	"Not super-user"		# 1
ENOENT:		asciz	"No such file or directory"	# 2
ESRCH:		asciz	"No such process"		# 3
EINTR:		asciz	"interrupted system call"	# 4
EIO:		asciz	"I/O error"			# 5
ENXIO:		asciz	"No such device or address"	# 6
E2BIG:		asciz	"Arg list too long"		# 7
ENOEXEC:	asciz	"Exec format error"		# 8
EBADF:		asciz	"Bad file number"		# 9
ECHILD:		asciz	"No children"			# 10
EAGAIN:		asciz	"No more processes"		# 11
ENOMEM:		asciz	"Not enough core"		# 12
EACCES:		asciz	"Permission denied"		# 13
EFAULT:		asciz	"Bad address"			# 14
ENOTBLK:	asciz	"Block device required"		# 15
EBUSY:		asciz	"Mount device busy"		# 16
EEXIST:		asciz	"File exists"			# 17
EXDEV:		asciz	"Cross-device link"		# 18
ENODEV:		asciz	"No such device"		# 19
ENOTDIR:	asciz	"Not a directory"		# 20
EISDIR:		asciz	"Is a directory"		# 21
EINVAL:		asciz	"Invalid argument"		# 22
ENFILE:		asciz	"File table overflow"		# 23
EMFILE:		asciz	"Too many open files"		# 24
ENOTTY:		asciz	"Not a typewriter"		# 25
ETXTBSY:	asciz	"Text file busy"		# 26
EFBIG:		asciz	"File too large"		# 27
ENOSPC:		asciz	"No space left on device"	# 28
ESPIPE:		asciz	"Illegal seek"			# 29
EROFS:		asciz	"Read only file system"		# 30
EMLINK:		asciz	"Too many links"		# 31
EPIPE:		asciz	"Broken pipe"			# 32
EDOM:		asciz	"Math arg out of domain of func"# 33
ERANGE:		asciz	"Math result not representable"	# 34
ENOMSG:		asciz	"No message of desired type"	# 35
EIDRM:		asciz	"Identifier removed"		# 36
ECHRNG:		asciz	"Channel number out of range"	# 37
EL2NSYNC:	asciz	"Level 2 not synchronized"	# 38
EL3HLT:		asciz	"Level 3 halted"		# 39
EL3RST:		asciz	"Level 3 reset"			# 40
ELNRNG:		asciz	"Link number out of range"	# 41
EUNATCH:	asciz	"Protocol driver not attached"	# 42
ENOCSI:		asciz	"No CSI structure available"	# 43
EL2HLT:		asciz	"Level 2 halted"		# 44

#
#  filler messages
#

ERROR45:	asciz	"Error 45"			# 45
ERROR46:	asciz	"Error 46"			# 46
ERROR47:	asciz	"Error 47"			# 47
ERROR48:	asciz	"Error 48"			# 48
ERROR49:	asciz	"Error 49"			# 49

#
#  Convergent Errors
#

EBADE:		asciz	"invalid exchange"		# 50
EBADR:		asciz	"invalid request descriptor"	# 51
EXFULL:		asciz	"exchange full"			# 52
ENOANO:		asciz	"no anode"			# 53
EBADRQC:	asciz	"invalid request code"		# 54
EBADSLT:	asciz	"invalid slot"			# 55
EDEADLOCK:	asciz	"file locking deadlock error"	# 56
EBFONT:		asciz	"bad font file fmt"		# 57

# For BASSLOCKING

ENOLCK:		asciz	"no more locks available"	# 58
EDEADLK:	asciz	"file locking deadlock error"	# 59

#
# Hardware specific errors 
#

ENOHDW:		asciz	"No hardware available for operation"	# -32
EBADFS:		asciz	"bitmapped filesystem is marked dirty"	# -31

#
#  4.[23] BSD error numbers & messages
#
#  errors for non-blocking I/O.
#

EWOULDBLOCK:	asciz	"Operation would block"			# -30
EINPROGRESS:	asciz	"Operation now in progress"		# -29
EALREADY:	asciz	"Operation already in progress"		# -28

#
#  Uipc errors
#
#  Argument errors
#

ENOTSOCK:	asciz	"Socket operation on non-socket"	# -27
EDESTADDRREQ:	asciz	"Destination address required"		# -26
EMSGSIZE:	asciz	"Message too long"			# -25
EPROTOTYPE:	asciz	"Protocol wrong type for socket"	# -24
EPROTONOSUPPORT:	asciz	"Protocol not supported"	# -23
ESOCKTNOSUPPORT:	asciz	"Socket type not supported"	# -22
EOPNOTSUPP:	asciz	"Operation not supported on socket"	# -21
EPFNOSUPPORT:	asciz	"Protocol family not supported"		# -20
EAFNOSUPPORT:	asciz	"Address family not supported by protocol family" # -19
EADDRINUSE:	asciz	"Address already in use"		# -18
EADDRNOTAVAIL:	asciz	"Can't assign requested address"	# -17

#
#  Network errors
#

ENETDOWN:	asciz	"Network is down"			# -16
ENETUNREACH:	asciz	"Network is unreachable"		# -15
ENETRESET:	asciz	"Network dropped connection on reset"	# -14
ECONNABORTED:	asciz	"Software caused connection abort"	# -13
ECONNRESET:	asciz	"Connection reset by peer"		# -12
ENOBUFS:	asciz	"No buffer space available"		# -11
EISCONN:	asciz	"Socket is already connected"		# -10
ENOTCONN:	asciz	"Socket is not connected"		# -9
ESHUTDOWN:	asciz	"Can't send after socket shutdown"	# -8
ETOOMANYREFS:	asciz	"Too many references: can't splice"	# -7
ETIMEDOUT:	asciz	"Connection timed out"			# -6
ECONNREFUSED:	asciz	"Connection refused"			# -5
EHOSTDOWN:	asciz	"Host is down"				# -4
EHOSTUNREACH:	asciz	"No route to host"			# -3
ENOPROTOOPT:	asciz	"Protocol not available"		# -2

ERROR_1:	asciz	"Error -1"				# -1

#
#  The system error table
#
	data
	even

	long	ENOHDW
	long	EBADFS
	long	EWOULDBLOCK
	long	EINPROGRESS
	long	EALREADY
	long	ENOTSOCK
	long	EDESTADDRREQ
	long	EMSGSIZE
	long	EPROTOTYPE
	long	EPROTONOSUPPORT
	long	ESOCKTNOSUPPORT
	long	EOPNOTSUPP
	long	EPFNOSUPPORT
	long	EAFNOSUPPORT
	long	EADDRINUSE
	long	EADDRNOTAVAIL
	long	ENETDOWN
	long	ENETUNREACH
	long	ENETRESET
	long	ECONNABORTED
	long	ECONNRESET
	long	ENOBUFS
	long	EISCONN
	long	ENOTCONN
	long	ESHUTDOWN
	long	ETOOMANYREFS
	long	ETIMEDOUT
	long	ECONNREFUSED
	long	EHOSTDOWN
	long	EHOSTUNREACH
	long	ENOPROTOOPT
	long	ERROR_1

	global uipc_errlist
uipc_errlist:
	long	ERROR0
	long	EPERM
	long	ENOENT
	long	ESRCH
	long	EINTR
	long	EIO
	long	ENXIO
	long	E2BIG
	long	ENOEXEC
	long	EBADF
	long	ECHILD
	long	EAGAIN
	long	ENOMEM
	long	EACCES
	long	EFAULT
	long	ENOTBLK
	long	EBUSY
	long	EEXIST
	long	EXDEV
	long	ENODEV
	long	ENOTDIR
	long	EISDIR
	long	EINVAL
	long	ENFILE
	long	EMFILE
	long	ENOTTY
	long	ETXTBSY
	long	EFBIG
	long	ENOSPC
	long	ESPIPE
	long	EROFS
	long	EMLINK
	long	EPIPE
	long	EDOM
	long	ERANGE
	long	ENOMSG
	long	EIDRM
	long	ECHRNG
	long	EL2NSYNC
	long	EL3HLT
	long	EL3RST
	long	ELNRNG
	long	EUNATCH
	long	ENOCSI
	long	EL2HLT
	long	ERROR45
	long	ERROR46
	long	ERROR47
	long	ERROR48
	long	ERROR49
	long	EBADE
	long	EBADR
	long	EXFULL
	long	ENOANO
	long	EBADRQC
	long	EBADSLT
	long	EDEADLOCK
	long	EBFONT
	long	ENOLCK
	long	EDEADLK

	even

	global uipc_firsterr
uipc_firsterr:
	long	-32

	global uipc_lasterr
uipc_lasterr:
	long	59

@//E*O*F uipc/lib/syserr.s//
chmod u=rw,g=rw,o=rw uipc/lib/syserr.s
 
echo mkdir - uipc/uipc
mkdir uipc/uipc
chmod u=rwx,g=rx,o=rx uipc/uipc
 
echo x - uipc/uipc/conf.h
sed 's/^@//' > "uipc/uipc/conf.h" <<'@//E*O*F uipc/uipc/conf.h//'
/*
 *	@(#)conf.h	1.1	(Alex Crain)	6/20/89
 *
 *  conf.h - 3b1 specifics for the uipc driver.
 *
 *  (C) Copyright 1989 Alex Crain
 *
 */

#ifndef _conf_h_
#define _conf_h_

/*
 *  Useful spls. 
 */

#define splimp	spl7
#define splnet	spl5

/*
 *  Useful macros
 */

#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))

/*
 *  stdata is a pointer to a streams structure, and is referenced in 
 *  sys/inode.h. We rename it here and use it for a socket pointer.
 */

#define stdata socket
#define i_sptr i_socket

/*
 *  I never understood why at&t doesn't offer a complete set of these.
 *  ushort and uint are found in types.h, but uchar() is a kernel function,
 *  so we invent a complete set from scratch.
 */

typedef unsigned long	u_long;
typedef unsigned int	u_int;
typedef unsigned short	u_short;
typedef unsigned char	u_char; /* may or maynot need it */

/*
 *  The number of available mbufs
 */

#define NMBUF 512

/*
 *  New signals. The signal numbers are not the same as BSD.
 */

#define SIGURG		22
#define SIGIO		23

/*
 *  New flags for (struct file *)->i_flag
 */

#define FMARK		00040
#define FDEFER		00100

/*
 *  Flags for iomove (addr, len, flag)
 */

#define IO_WRITE	0		/* u.u_base -> addr	*/
#define IO_READ		1		/* addr -> u.u_base	*/

/*
 *  Flags for useracc (addr, len, flag)
 */

#define UACC_READ	0
#define UACC_WRITE	1

/*
 *  define the relationship between file structures and sockets
 */

#define filesock(FP)	mtod (ptom ((FP)->f_offset), struct socket *)
#define sockoffset(SO)	mtop (dtom (SO), off_t)

#endif /* _conf_h_ */
@//E*O*F uipc/uipc/conf.h//
chmod u=rw,g=rw,o=rw uipc/uipc/conf.h
 
echo x - uipc/uipc/domain.h
sed 's/^@//' > "uipc/uipc/domain.h" <<'@//E*O*F uipc/uipc/domain.h//'
/*
 *	@(#)domain.h	1.1	(Alex Crain)	6/20/89
 *
 *  domain.h - domain stucture definitions.
 *
 *  Written by Alex Crain.
 *
 *  This file is based in the Berkeley header file of the same
 *  name, but is *not* guarenteed to be in any way compatable. It is
 *  close enough to the berkeley code that the following applies...
 *
 *  Copyright (c) 1982, 1986, 1988 Regents of the University of California.
 *  All rights reserved.
 * 
 *  Redistribution and use in source and binary forms are permitted
 *  provided that this notice is preserved and that due credit is given
 *  to the University of California at Berkeley. The name of the University
 *  may not be used to endorse or promote products derived from this
 *  software without specific prior written permission. This software
 *  is provided "as is" without express or implied warranty.
 *
 */

#ifndef _domain_h_
#define _domain_h_

#include <uipc/conf.h>

struct domain {
   int 		dom_family;
   char 	* dom_name;
   int		(* dom_init) ();
   int		(* dom_externalize) ();
   int		(* dom_dispose) ();
   struct	protosw * dom_protosw, * dom_protoswNPROTOSW;
   struct 	domain * dom_next;
};

#ifdef KERNEL
struct domain * domains;
#endif

#endif _domain_h_
@//E*O*F uipc/uipc/domain.h//
chmod u=rw,g=rw,o=rw uipc/uipc/domain.h
 
echo x - uipc/uipc/fproto.h
sed 's/^@//' > "uipc/uipc/fproto.h" <<'@//E*O*F uipc/uipc/fproto.h//'
/*
 *	@(#)fproto.h	1.1	(Alex Crain)	6/20/89
 *
 *  fproto.h - function prototypes for uipc driver.
 *
 *  Written by Alex Crain.
 *
 *  This file contains ANSI function prototypes for the entire uipc 
 *  package and many of the existing system entry points. The prototypes 
 *  are blocked within a "#ifdef __STDC__" construct, the with an alternate
 *  "#else" block of old-style function declarations.
 */

#ifndef _fproto_h_
#define _fproto_h_

#ifdef __STDC__
/*
 *  Declarations from debug.c
 */

void dump_mbuf (struct mbuf *m, char *func);

/*
 *  Declarations from domain.c
 */

void domaininit (void);
struct protosw *pffindtype (int family, int type);
struct protosw *pffindproto (int family, int protocol, int type);

/*
 *  Declarations from interface.c
 */

void uipcinit (void);
void dosyscall(void);
int uipcrelease (void);
void uipc_write (void);
void uipc_read (void);
void uipc_close (off_t sp);
void bzero (char *s, int n);
int ufavail (void);

/*
 *  Declarations from mbuf.c
 */

void mbinit(void);
struct mbuf *m_get (int canwait, int type);
struct mbuf *m_getclr (int canwait, int type);
struct mbuf *m_free (struct mbuf *m);
struct mbuf *m_more (int canwait, int type);
void m_freem (struct mbuf *m);
struct mbuf *m_copy (struct mbuf *m, int off, int len);

/*
 *  Declarations from socket.c
 */

int socreate (int domain, struct socket ** sop, int type, int proto);
int sobind (struct socket *so, struct mbuf *nam);
int solisten (struct socket *so, int backlog);
void sofree (struct socket *so);
int soclose (struct socket *so);
int soabort (struct socket *so);
int soaccept (struct socket *so, struct mbuf *nam);
int soconnect (struct socket *so, struct mbuf *nam);
int soconnect2 (struct socket *so1, struct socket *so2);
int sodisconnect (struct socket *so);
int sosend (struct socket *so, struct mbuf *nam, int flags, struct mbuf *rights);
int soreceive (struct socket *so, struct mbuf **nam, int flags, struct mbuf **rights);
void sorflush (struct socket *so);
int sosetopt (struct socket *so, int level, int optname, struct mbuf *m0);
int sogetopt (struct socket *so, int level, int optname, struct mbuf **mp);
void sohasoutofband (struct socket *so);

/*
 *  Declarations from socket2.c
 */


void soisconnecting (struct socket *so);
void soisconnected (struct socket *so);
void soisdisconnecting (struct socket *so);
void soisdisconnected (struct socket *so);
struct socket *sonewconn (struct socket *head);
void soinsque (struct socket *head, struct socket *so, int q);
int soqremque (struct socket *so, int q);
void socantsendmore (struct socket *so);
void socantrcvmore (struct socket *so);
void sbselqueue (struct sockbuf *sb);
void sbwait (struct sockbuf *sb);
void sbwakeup (struct sockbuf *sb);
void sowakeup (struct socket *so, struct sockbuf *sb);
int soreserve (struct socket *so, int sndcc, int rcvcc);
int sbreserve (struct sockbuf *sb, int cc);
void sbrelease (struct sockbuf *sb);
void sbappend (struct sockbuf *sb, struct mbuf *m);
void sbappendrecord (struct sockbuf *sb, struct mbuf *m0);
int sbappendaddr (struct sockbuf *sb, struct sockaddr *asa, struct mbuf *m0, struct mbuf *rights0);
int sbappendrights (struct sockbuf *sb, struct mbuf *m0, struct mbuf *rights);
void sbcompress (struct sockbuf *sb, struct mbuf *m, struct mbuf *n);
void sbflush (struct sockbuf *sb);
void sbdrop (struct sockbuf *sb, int len);
void sbdroprecord (struct sockbuf *sb);

/*
 *  Declarations from syscalls.c
 */

int select (void);

int socket (void);
int bind (void);
int listen (void);
int accept (void);
int connect (void);
int socketpair (void);
int sendto (void);
int send (void);
int sendmsg (void);
void sendit (int s, struct msghdr * mp, int flags);
int recvfrom (void);
int recv (void);
int recvmsg (void);
void recvit (int s, struct msghdr * mp, int flags, caddr_t np, caddr_t rp);
int setsockopt (void);
int getsockopt (void);
int sockpipe (void);
void getsockname (void);
int sockargs (struct mbuf **aname, caddr_t name, int namelen, int type);
struct file *getsock (int fd);

/*
 *  Declarations from usrreq.c
 */

int uipc_usrreq (struct socket *so, int req, struct mbuf *m, struct mbuf *nam, struct mbuf *rights);
int unp_attach (struct socket *so);
void unp_detach (struct unpcb *unp);
int unp_bind (struct unpcb *unp, struct mbuf *nam);
int unp_connect (struct socket *so, struct mbuf *nam);
int unp_connect2 (struct socket *so1, struct socket *so2);
void unp_disconnect (struct unpcb *unp);
void unp_usrclosed (struct unpcb *unp);
int unp_externalize (struct mbuf *rights);
int unp_internalize (struct mbuf *rights);
void unp_gc (void);
void unp_dispose (struct mbuf *m);
void unp_scan (struct mbuf *m0, int (*op)());
void unp_mark (struct file *fp);
void unp_discard (struct file *fp);
void unp_drop (struct unpcb *unp, int errno);


/*
 *  declarations left out of systm.h
 */

int suser (void);
int fuword (int * addr);
int useracc (caddr_t address, int length, int flag);

short spl7 (void);
short spl6 (void);
short spl5 (void);
short spl4 (void);
short spl3 (void);
short spl2 (void);
short spl1 (void);
short splx (short sp);

int sleep (caddr_t addr, int p);
int wakeup (caddr_t addr);
void signal (int pgrp, int sig);
void psignal (struct proc * p, int sig);
int setjmp (label_t env);
void longjmp (label_t env, int val);

void panic (caddr_t msg);
void printf();
void eprintf();

int access (struct inode * ip, int mode);
extern struct inode * iget ();
void iput (struct inode * ip);
void prele (struct inode * ip);
int ufalloc (int fp);
void closef (struct file * fp);
void locsys ();

#else ! __STDC__

/*
 *  Declarations from debug.c
 */

void dump_mbuf ();

/*
 *  Declarations from domain.c
 */

void domaininit ();
struct protosw *pffindtype ();
struct protosw *pffindproto ();

/*
 *  Declarations from interface.c
 */

void uipcinit ();
void dosyscall();
int uipcrelease ();
void uipc_write ();
void uipc_read ();
void uipc_close ();
void bzero ();
int ufavail ();

/*
 *  Declarations from mbuf.c
 */

void mbinit();
struct mbuf *m_get ();
struct mbuf *m_getclr ();
struct mbuf *m_free ();
struct mbuf *m_more ();
void m_freem ();
struct mbuf *m_copy ();

/*
 *  Declarations from socket.c
 */

int select ();

int socreate ();
int sobind ();
int solisten ();
void sofree ();
int soclose ();
int soabort ();
int soaccept ();
int soconnect ();
int soconnect2 ();
int sodisconnect ();
int sosend ();
int soreceive ();
void sorflush ();
int sosetopt ();
int sogetopt ();
void sohasoutofband ();

/*
 *  Declarations from socket2.c
 */


void soisconnecting ();
void soisconnected ();
void soisdisconnecting ();
void soisdisconnected ();
struct socket *sonewconn ();
void soinsque ();
int soqremque ();
void socantsendmore ();
void socantrcvmore ();
void sbselqueue ();
void sbwait ();
void sbwakeup ();
void sowakeup ();
int soreserve ();
int sbreserve ();
void sbrelease ();
void sbappend ();
void sbappendrecord ();
int sbappendaddr ();
int sbappendrights ();
void sbcompress ();
void sbflush ();
void sbdrop ();
void sbdroprecord ();

/*
 *  Declarations from syscalls.c
 */

int socket ();
int bind ();
int listen ();
int accept ();
int connect ();
int socketpair ();
int sockpipe ();
int sendto();
int send();
int recvfrom();
int recv ();
int setsockopt();
int getsockopt();
void sendit ();
int sockpipe ();
void getsockname ();
void recvit ();
int sockargs ();
struct file *getsock ();

/*
 *  Declarations from usrreq.c
 */

int uipc_usrreq ();
int unp_attach ();
void unp_detach ();
int unp_bind ();
int unp_connect ();
int unp_connect2 ();
void unp_disconnect ();
void unp_usrclosed ();
void unp_drop ();
int unp_externalize ();
int unp_internalize ();
void unp_gc ();
void unp_dispose ();
void unp_scan ();
void unp_mark ();
void unp_discard ();

/*
 *  declarations left out of systm.h
 */

short spl7 ();
short spl6 ();
short spl5 ();
short spl4 ();
short spl3 ();
short spl2 ();
short spl1 ();
short splx ();

int sleep ();
int wakeup ();

void panic ();
void eprintf();
void signal ();
void psignal ();

int setjmp ();
void longjmp ();

int suser ();

#endif __STDC__
#endif _fproto_h_
@//E*O*F uipc/uipc/fproto.h//
chmod u=rw,g=rw,o=rw uipc/uipc/fproto.h
 
echo x - uipc/uipc/mbuf.h
sed 's/^@//' > "uipc/uipc/mbuf.h" <<'@//E*O*F uipc/uipc/mbuf.h//'
/*
 *	@(#)mbuf.h	1.1	(Alex Crain)	6/20/89
 *
 *  mbuf.h - mbuf description macros
 *
 *  Written by Alex Crain.
 *
 *  This file is loosly based in the Berkeley header file of the 
 *  same name, but is *not* guarenteed to be in any way compatable. It is
 *  close enough to the berkeley code that the following applies...
 *
 *  Copyright (c) 1982, 1986, 1988 Regents of the University of California.
 *  All rights reserved.
 * 
 *  Redistribution and use in source and binary forms are permitted
 *  provided that this notice is preserved and that due credit is given
 *  to the University of California at Berkeley. The name of the University
 *  may not be used to endorse or promote products derived from this
 *  software without specific prior written permission. This software
 *  is provided "as is" without express or implied warranty.
 *
 */

#ifndef _mbuf_h_
#define _mbuf_h_

#include <uipc/conf.h>

#define MSIZE		128

#define MMINOFF		12
#define MTAIL		4
#define MMAXOFF		(MSIZE - MTAIL)
#define MLEN		(MSIZE - MMINOFF - MTAIL)

#define dtom(x)		((struct mbuf *)((int)(x) & ~(MSIZE - 1)))
#define mtod(m, t)	((t)((int)(m) + (m)->m_off))

#define ptom(x)		((struct mbuf *)(((int)(x) << 7) | mbmask))
#define mtop(x, t)	((t)(((int)(x) >> 7) & 0xFFFF))

struct mbuf {
   struct	mbuf * m_next;
   u_long	m_off;
   short	m_len;
   short	m_type;
   u_char	m_dat[MLEN];
   struct	mbuf * m_act;
};

#define MT_FREE		0
#define MT_DATA		1
#define MT_HEADER	2
#define MT_SOCKET	3
#define MT_PCB		4
#define MT_SONAME	8
#define MT_SOOPTS	10
#define MT_RIGHTS	12

/* flags to mget */
#define M_DONTWAIT	0
#define M_WAIT		1

/* length to m_copy to copy all */
#define M_COPYALL	10000000

#define MGET(m, i, t)	\
{  int _s = splimp ();		\
   if ((m) = mfree)	\
    {  if ((m)->m_type != MT_FREE) panic("mget"); (m)->m_type = t; \
       mfree = (m)->m_next; (m)->m_next = (struct mbuf *) 0; \
       (m)->m_off = MMINOFF; } \
   else \
       (m) = m_more (i, t); \
   splx (_s); }

#define MFREE(m, n) \
{  int _s = splimp (); \
   if ((m)->m_type == MT_FREE) panic ("mfree"); \
   (m)->m_type = MT_FREE; \
   (n) = (m)->m_next; (m)->m_next = mfree; mfree = (m); \
   (m)->m_off = 0; (m)->m_act = 0;\
   splx (_s); \
   if (m_want) \
    { m_want = 0; \
      wakeup((caddr_t)&mfree); }}

#ifdef KERNEL
struct mbuf * mfree, * mbmem;
unsigned int mbmask;
int m_want;
struct mbuf * m_get (), * m_getclr(), *m_free (), * m_more (), * m_copy ();
void m_freem ();
#endif

#endif _mbuf_h_
@//E*O*F uipc/uipc/mbuf.h//
chmod u=rw,g=rw,o=rw uipc/uipc/mbuf.h
 
echo x - uipc/uipc/protosw.h
sed 's/^@//' > "uipc/uipc/protosw.h" <<'@//E*O*F uipc/uipc/protosw.h//'
/*
 *	@(#)protosw.h	1.1	(Alex Crain)	6/20/89
 *
 *  protosw.h - protocol switch definition
 *
 *  Written by Alex Crain.
 *
 *  This file is based in the Berkeley header file of the 
 *  same name, but is *not* guarenteed to be in any way compatable. It is
 *  close enough to the berkeley code that the following applies...
 *
 *  Copyright (c) 1982, 1986, 1988 Regents of the University of California.
 *  All rights reserved.
 * 
 *  Redistribution and use in source and binary forms are permitted
 *  provided that this notice is preserved and that due credit is given
 *  to the University of California at Berkeley. The name of the University
 *  may not be used to endorse or promote products derived from this
 *  software without specific prior written permission. This software
 *  is provided "as is" without express or implied warranty.
 *
 */

#ifndef _proto_h_
#define _proto_h_

#include <uipc/conf.h>

struct protosw {
   short	pr_type;
   struct	domain * pr_domain;
   short	pr_protocol;
   short	pr_flags;
   int 		(* pr_input) ();
   int		(* pr_output) ();
   int		(* pr_ctlinput) ();
   int		(* pr_ctloutput) ();
   int		(* pr_usrreq) ();
   int		(* pr_init) ();
   int		(* pr_fasttimo) ();
   int		(* pr_slowtimo) ();
   int		(* pr_drain) ();
};

#define PR_SLOWHZ	2
#define PR_FASTHZ	5

/*
 *  values for pr_flags
 */

#define PR_ATOMIC	0x01		/* exchange atomic messages only     */
#define PR_ADDR		0x02		/* addresses given w/ messages	     */
#define PR_CONNREQUIRED	0x04		/* connection reuired by protocol    */
#define PR_WANTRCVD	0x08		/* want PRU_RCVD calls		     */
#define PR_RIGHTS	0x10		/* passes capabilities		     */

/*
 *  arguments to usrreq
 */

#define PRU_ATTACH	0
#define PRU_DETACH	1
#define PRU_BIND	2
#define PRU_LISTEN	3
#define PRU_CONNECT	4
#define PRU_ACCEPT	5
#define PRU_DISCONNECT	6
#define PRU_SHUTDOWN	7
#define PRU_RCVD	8
#define PRU_SEND	9
#define PRU_ABORT	10
#define PRU_CONTROL	11
#define PRU_SENSE	12
#define PRU_RCVOOB	13
#define PRU_SENDOOB	14
#define PRU_SOCKADDR	15
#define PRU_PEERADDR	16
#define PRU_CONNECT2	17
#define PRU_FASTTIMO	18
#define PRU_SLOWTIMO	19
#define PRU_PROTORCV	20
#define PRU_PROTOSEND	21

#define PRE_NREQ	21

#define PRCO_GETOPT	0
#define PRCO_SETOPT	1

#endif /* _proto_h_ */
@//E*O*F uipc/uipc/protosw.h//
chmod u=rw,g=rw,o=rw uipc/uipc/protosw.h
 
echo x - uipc/uipc/socket.h
sed 's/^@//' > "uipc/uipc/socket.h" <<'@//E*O*F uipc/uipc/socket.h//'
/*
 *	@(#)socket.h	1.1	(Alex Crain)	6/20/89
 *
 *  socket.h - socket related definitions
 *
 *  Written by Alex Crain.
 *
 *  This file is loosly based in the Berkeley header file of the 
 *  same name, but is *not* guarenteed to be in any way compatable. It is
 *  close enough to the berkeley code that the following applies...
 *
 *  Copyright (c) 1982, 1986, 1988 Regents of the University of California.
 *  All rights reserved.
 * 
 *  Redistribution and use in source and binary forms are permitted
 *  provided that this notice is preserved and that due credit is given
 *  to the University of California at Berkeley. The name of the University
 *  may not be used to endorse or promote products derived from this
 *  software without specific prior written permission. This software
 *  is provided "as is" without express or implied warranty.
 *
 */

#ifndef _socket_h_
#define _socket_h_

#include <uipc/conf.h>

/*
 *  Socket types
 */

#define SOCK_STREAM	1		/* stream socket	*/
#define SOCK_DGRAM	2		/* datagram socket	*/
#ifdef notdef
#define SOCK_RAW	3		/* raw socket		*/
#endif

/*
 *  Socket option flags
 */

#define SO_DEBUG	0x0001
#define SO_ACCEPTCONN	0x0002
#define SO_REUSEADDR	0x0004
#define SO_KEEPALIVE	0x0008
#define SO_DONTROUTE	0x0010
#define SO_BROADCAST	0x0020
#define SO_USELOOPBACK	0x0040
#define SO_LINGER	0x0080
#define SO_OOBINLINE	0x0100
/*
 *  Extra socket options
 */

#define SO_SNDBUF	0x1001
#define SO_RCVBUF	0x1002
#define SO_SNDLOWAT	0x1003
#define SO_RCVLOWAT	0x1004
#define SO_SNDTIMEO	0x1005
#define SO_RCVTIMEO	0x1006
#define SO_ERROR	0x1007
#define SO_TYPE		0x1008

/*
 *  Linger structure
 */

struct linger {
   int	l_onoff;
   int	l_linger;
};

#define SOL_SOCKET	0xffff

/*
 *  Address families
 */

#define AF_UNSPEC	0
#define AF_UNIX		1
#define AF_INIT		2

#define AF_MAX		3

/*
 *  Structure for address specs.
 */

struct sockaddr {
   u_short	sa_family;		/* address family	*/
   char		sa_data[14];		/* address spec		*/
};

/*
 *  Protocol families
 */

#define PF_UNSPEC	AF_UNSPEC
#define PF_UNIX		AF_UNIX
#define PF_INET		AF_INET

#define PF_MAX		AF_MAX

/*
 *  maximum queue length for listen ()
 */

#define SOMAXCONN	5


/*
 *  message header for recvmsg and sendmsg calls.
 */

struct msghdr {
   caddr_t	msg_name;
   int		msg_namelen;
   caddr_t	msg_accrights;
   int		msg_accrightslen;
};

#define MSG_OOB		0x01		/* flag for out-of-band data	*/
#define MSG_PEEK	0x02		/* peek at incomming message	*/
#define MSG_DONTROUTE	0x04		/* send without routing tables	*/

#endif /* _socket_h_ */
@//E*O*F uipc/uipc/socket.h//
chmod u=rw,g=rw,o=rw uipc/uipc/socket.h
 
echo x - uipc/uipc/socketvar.h
sed 's/^@//' > "uipc/uipc/socketvar.h" <<'@//E*O*F uipc/uipc/socketvar.h//'
/*
 *	@(#)socketvar.h	1.1	(Alex Crain)	6/20/89
 *
 *  socketvar.h - socket related definitions
 *
 *  Written by Alex Crain.
 *
 *  This file is loosly based in the Berkeley header file of the 
 *  same name, but is *not* guarenteed to be in any way compatable. It is
 *  close enough to the berkeley code that the following applies...
 *
 *  Copyright (c) 1982, 1986, 1988 Regents of the University of California.
 *  All rights reserved.
 * 
 *  Redistribution and use in source and binary forms are permitted
 *  provided that this notice is preserved and that due credit is given
 *  to the University of California at Berkeley. The name of the University
 *  may not be used to endorse or promote products derived from this
 *  software without specific prior written permission. This software
 *  is provided "as is" without express or implied warranty.
 *
 */

#ifndef _socketvar_h_
#define _socketvar_h_

#include <uipc/conf.h>

/*
 *  structure describing a socket.
 */

typedef ushort socketptr;

struct socket {
   short	so_type;
   short	so_options;
   short	so_linger;
   short	so_state;
   caddr_t	so_pcb;
   struct	protosw * so_proto;

   struct	socket * so_head;
   struct	socket * so_q0;
   struct	socket * so_q;
   short	so_q0len;
   short	so_qlen;
   short	so_qlimit;
   short	so_timeo;
   ushort	so_error;
   short	so_pgrp;
   u_long	so_oobmark;

   struct	sockbuf {
      u_long	sb_cc;
      u_long	sb_hiwat;
      u_long	sb_mbcnt;
      u_long	sb_mbmax;
      u_long	sb_lowat;
      struct	mbuf * sb_mb;
      struct	proc * sb_sel;
      short	sb_timeo;
      short	sb_flags;
   } so_rcv, so_snd;

#define SB_MAX		(64 * 1024)
#define SB_LOCK		0x01
#define SB_WANT		0x02
#define SB_WAIT		0x04
#define SB_SEL		0x08
#ifdef notdef
#define SB_COLL		0x10
#endif
};

/*
 *  Socket states
 */
#define SS_NOFDREF		0x001
#define SS_ISCONNECTED		0x002
#define SS_ISCONNECTING		0x004
#define SS_ISDISCONNECTING	0x008
#define SS_CANTSENDMORE		0x010
#define SS_CANTRCVMORE		0x020
#define SS_RCVATMARK		0x040

#define SS_PRIV			0x080
#define SS_NBIO			0x100
#define SS_ASYNC		0x200


/*
 *  Socket macros
 */
   
#define sbspace(sb) \
 (MIN ((long) ((sb)->sb_hiwat - (sb)->sb_cc), \
       (long) ((sb)->sb_mbmax - (sb)->sb_mbcnt)))

#define sendallatonce(so) \
 ((so)->so_proto->pr_flags & PR_ATOMIC)

#define soreadable(so) \
 ((so)->so_rcv.sb_cc || ((so)->so_state & SS_CANTRCVMORE) || \
  (so)->so_qlen || (so)->so_error)

#define sowriteable(so) \
 (sbspace (&(so)->so_snd) > 0 && \
  (((so)->so_state & SS_ISCONNECTED) || \
   ((so)->so_proto->pr_flags & PR_CONNREQUIRED) == 0) || \
  ((so)->so_state & SS_CANTSENDMORE) || \
  (so)->so_error)

#define sballoc(sb, m) \
{  (sb)->sb_cc += (m)->m_len; \
   (sb)->sb_mbcnt += MSIZE; }

#define sbfree(sb, m) \
{  (sb)->sb_cc -= (m)->m_len; \
   (sb)->sb_mbcnt -= MSIZE; }

#define sblock(sb) \
{   while ((sb)->sb_flags & SB_LOCK) \
     {  (sb)->sb_flags |= SB_WANT; \
	 (void) sleep ((caddr_t) &(sb)->sb_flags, PZERO+1); } \
    (sb)->sb_flags |= SB_LOCK; }

#define sbunlock(sb) \
{  (sb)->sb_flags &= ~SB_LOCK; \
   if ((sb)->sb_flags & SB_WANT) \
    {  (sb)->sb_flags &= ~SB_WANT; \
       wakeup ((caddr_t) &(sb)->sb_flags); }}

#define sorwakeup(so)	sowakeup (so, &(so)->so_rcv)
#define sowwakeup(so)	sowakeup (so, &(so)->so_snd)

#ifdef KERNEL
#ifdef __STDC__
struct socket * sonewconn (struct socket *);
#else  /* __STDC__ */
struct socket * sonewconn ();
#endif /* __STDC__ */

#endif KERNAL

#endif /* _socketvar_h_ */
@//E*O*F uipc/uipc/socketvar.h//
chmod u=rw,g=rw,o=rw uipc/uipc/socketvar.h
 
echo x - uipc/uipc/un.h
sed 's/^@//' > "uipc/uipc/un.h" <<'@//E*O*F uipc/uipc/un.h//'
/*
 *	@(#)un.h	1.1	(Alex Crain)	6/20/89
 *
 *  UNIX Domain definitions
 */

#ifndef _un_h_
#define _un_h_

#include <uipc/conf.h>

struct sockaddr_un {
   short	sun_family;		/* AF_UNIX		*/
   char		sun_path[108];		/* path name		*/
};

#endif /* _un_h_ */
@//E*O*F uipc/uipc/un.h//
chmod u=rw,g=rw,o=rw uipc/uipc/un.h
 
echo x - uipc/uipc/unpcb.h
sed 's/^@//' > "uipc/uipc/unpcb.h" <<'@//E*O*F uipc/uipc/unpcb.h//'
/*
 *	@(#)unpcb.h	1.1	(Alex Crain)	6/20/89
 *
 *  unpcb.h - unix intern protocol control block.
 *
 *  Written by Alex Crain.
 *
 *  This file is loosly based in the Berkeley file unpcb.h,
 *  but is *not* guarenteed to be in any way compatable. It is
 *  close enough to the Berkeley code that the following applies...
 *
 *  Copyright (c) 1982, 1986, 1988 Regents of the University of California.
 *  All rights reserved.
 * 
 *  Redistribution and use in source and binary forms are permitted
 *  provided that this notice is preserved and that due credit is given
 *  to the University of California at Berkeley. The name of the University
 *  may not be used to endorse or promote products derived from this
 *  software without specific prior written permission. This software
 *  is provided "as is" without express or implied warranty.
 *
 */

#ifndef _unpcb_h_
#define _unpcb_h_

#include <uipc/conf.h>

struct unpcb {
   struct	socket * unp_socket;	/* backpointer to socket	     */
   struct	inode * unp_inode;	/* file reference		     */
   ino_t	unp_ino;		/* fake inode number		     */
   struct	unpcb * unp_conn;	/* control block of connected socket */
   struct	unpcb * unp_refs;	/* referencing socket liked list     */
   struct	unpcb * unp_nextref;	/* link in unp_refs list	     */
   struct	mbuf * unp_addr;	/* bound address of socket	     */
   int		unp_cc;			/* copy of rcv.sb_cc		     */
   int		unp_mbcnt;		/* copy of rcv.sb_mbcnt		     */
};

#define sotounpcb(so)	((struct unpcb *)((so)->so_pcb))

#endif /* _unpcb_h_ */
@//E*O*F uipc/uipc/unpcb.h//
chmod u=rw,g=rw,o=rw uipc/uipc/unpcb.h
 
exit 0
-- 
David H. Brierley
Home: dave at galaxia.newport.ri.us; Work: dhb at quahog.ssd.ray.com
Send comp.sources.3b1 submissions to comp-sources-3b1 at galaxia.newport.ri.us
%% Can I be excused, my brain is full. **



More information about the Comp.sources.3b1 mailing list