home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD2.bin / bbs / comm / amitcp-3.0ß2.lha / AmiTCP / src / amitcp / kern / uipc_socket.c < prev    next >
C/C++ Source or Header  |  1993-12-18  |  32KB  |  1,305 lines

  1. RCS_ID_C="$Id: uipc_socket.c,v 1.28 1993/12/18 15:28:09 jraja Exp $";
  2. /*
  3.  * Copyright (c) 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>
  4.  *                    Helsinki University of Technology, Finland.
  5.  *                    All rights reserved.
  6.  *
  7.  * HISTORY
  8.  * $Log: uipc_socket.c,v $
  9.  * Revision 1.28  1993/12/18  15:28:09  jraja
  10.  * Disabled code using M_EOR, unless USE_M_EOR is defined.
  11.  *
  12.  * Revision 1.27  1993/11/17  12:12:48  jraja
  13.  * Added check for the SB_SEL flag to sohasoutofband() to prevent superfluous
  14.  * calls to selwakeup().
  15.  *
  16.  * Revision 1.26  1993/11/17  09:20:33  jraja
  17.  * Fixed selwakeup bug in sohasoutofband(), there was mixture of net2 & bsdss
  18.  * -style selwakeup usage.
  19.  *
  20.  * Revision 1.25  1993/06/04  11:16:15  jraja
  21.  * Fixes for first public release.
  22.  *
  23.  * Revision 1.24  1993/05/17  01:07:47  ppessi
  24.  * Changed RCS version.
  25.  *
  26.  * Revision 1.23  1993/04/28  13:42:48  too
  27.  * Fixed setting of linger value in getsockopt()
  28.  *
  29.  * Revision 1.22  93/04/26  11:54:49  11:54:49  too (Tomi Ollila)
  30.  * Changed include paths of amiga_api.h, amiga_libcallentry.h and amiga_raf.h
  31.  * from kern to api
  32.  * 
  33.  * Revision 1.21  93/04/24  22:45:52  22:45:52  jraja (Jarno Tapio Rajahalme)
  34.  * Removed Define for USECLUSTERS
  35.  * 
  36.  * Revision 1.20  93/04/24  17:52:15  17:52:15  jraja (Jarno Tapio Rajahalme)
  37.  * Changed MCLBYTES to mbconf.mclbytes.
  38.  * 
  39.  * Revision 1.19  93/04/12  00:37:56  00:37:56  jraja (Jarno Tapio Rajahalme)
  40.  * Added #include <kern/amiga_includes.h> for Signal().
  41.  * 
  42.  * Revision 1.18  93/04/12  00:29:11  00:29:11  jraja (Jarno Tapio Rajahalme)
  43.  * Added signalling of task (SIGURG).
  44.  * 
  45.  * Revision 1.17  93/04/11  22:28:37  22:28:37  jraja (Jarno Tapio Rajahalme)
  46.  * Removed one extra argument from call to pr_usrreq.
  47.  * Added parenthesis around &&'s inside ||'s.
  48.  * 
  49.  * Revision 1.16  93/04/06  15:16:08  15:16:08  jraja (Jarno Tapio Rajahalme)
  50.  * Changed spl function return value storage to spl_t,
  51.  * changed bcopys and bzeros to aligned and/or const when possible,
  52.  * added inclusion of conf.h to every .c file.
  53.  * 
  54.  * Revision 1.15  93/03/21  16:59:37  16:59:37  jraja (Jarno Tapio Rajahalme)
  55.  * Changed linger time to seconds. Removed obsolete test on timeout value for
  56.  * send/receive timeout (was checked to fit in a short, but since the timeouts are
  57.  * now timeval's the check is not needed.
  58.  * 
  59.  * Revision 1.14  93/03/19  14:14:56  14:14:56  too (Tomi Ollila)
  60.  * Code changes at night 17-18 March 1993
  61.  * 
  62.  * Revision 1.13  93/03/17  12:06:35  12:06:35  jraja (Jarno Tapio Rajahalme)
  63.  * Fixed tsleep() call to find socket base if necessary and to give NULL
  64.  * timeout if timeval is all zeroes.
  65.  * 
  66.  * Revision 1.12  93/03/16  19:47:16  19:47:16  too (Tomi Ollila)
  67.  * uses multible mbufs (broken)
  68.  * 
  69.  * Revision 1.11  93/03/13  17:13:06  17:13:06  ppessi (Pekka Pessi)
  70.  * Fixed bugs with variable initializations. Works with UDP.
  71.  * 
  72.  * Revision 1.10  93/03/05  03:26:23  03:26:23  ppessi (Pekka Pessi)
  73.  * Compiles with SASC. Initial test version.
  74.  * 
  75.  * Revision 1.9  93/03/04  10:57:17  10:57:17  jraja (Jarno Tapio Rajahalme)
  76.  * Added prototype inclusion for kern/uipc_domain_protos_.h.h
  77.  * 
  78.  * Revision 1.8  93/03/04  09:53:45  09:53:45  jraja (Jarno Tapio Rajahalme)
  79.  * Removed some redundant includes.
  80.  * 
  81.  * Revision 1.7  93/02/27  11:03:55  11:03:55  too (Tomi Ollila)
  82.  * Added Prototypes
  83.  * 
  84.  * Revision 1.6  93/02/25  13:01:48  13:01:48  too (Tomi Ollila)
  85.  * Added static inlines, sys/cdefs etc.
  86.  * 
  87.  * Revision 1.5  93/02/24  18:14:47  18:14:47  too (Tomi Ollila)
  88.  * Compiles. support for so_linger and sb_timeo as struct timeval type added.
  89.  * 
  90.  * Revision 1.4  93/02/23  11:37:56  11:37:56  too (Tomi Ollila)
  91.  * Made AMITCP combatible, not compiled yet
  92.  * 
  93.  * Revision 1.3  93/01/09  12:56:26  12:56:26  jraja (Jarno Tapio Rajahalme)
  94.  * Added #ifdef USECLUSTERS to disable cluster dependant code.
  95.  * 
  96.  * Revision 1.2  92/11/20  15:14:49  15:14:49  jraja (Jarno Tapio Rajahalme)
  97.  * Added #ifndef AMITCP's to make this compile.
  98.  * 
  99.  * Revision 1.1  92/11/19  12:07:27  12:07:27  jraja (Jarno Tapio Rajahalme)
  100.  * Initial revision
  101.  * 
  102.  *
  103.  */
  104.  
  105. /* 
  106.  * Mach Operating System
  107.  * Copyright (c) 1992 Carnegie Mellon University
  108.  * All Rights Reserved.
  109.  * 
  110.  * Permission to use, copy, modify and distribute this software and its
  111.  * documentation is hereby granted, provided that both the copyright
  112.  * notice and this permission notice appear in all copies of the
  113.  * software, derivative works or modified versions, and any portions
  114.  * thereof, and that both notices appear in supporting documentation.
  115.  * 
  116.  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
  117.  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
  118.  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  119.  * 
  120.  * Carnegie Mellon requests users of this software to return to
  121.  * 
  122.  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
  123.  *  School of Computer Science
  124.  *  Carnegie Mellon University
  125.  *  Pittsburgh PA 15213-3890
  126.  * 
  127.  * any improvements or extensions that they make and grant Carnegie Mellon 
  128.  * the rights to redistribute these changes.
  129.  */
  130. /*
  131.  * HISTORY
  132.  * Log:    uipc_socket.c,v
  133.  * Revision 2.1  92/04/21  17:12:32  rwd
  134.  * BSDSS
  135.  * 
  136.  *
  137.  */
  138.  
  139. /*
  140.  * Copyright (c) 1982, 1986, 1988, 1990 Regents of the University of California.
  141.  * All rights reserved.
  142.  *
  143.  * Redistribution and use in source and binary forms, with or without
  144.  * modification, are permitted provided that the following conditions
  145.  * are met:
  146.  * 1. Redistributions of source code must retain the above copyright
  147.  *    notice, this list of conditions and the following disclaimer.
  148.  * 2. Redistributions in binary form must reproduce the above copyright
  149.  *    notice, this list of conditions and the following disclaimer in the
  150.  *    documentation and/or other materials provided with the distribution.
  151.  * 3. All advertising materials mentioning features or use of this software
  152.  *    must display the following acknowledgement:
  153.  *    This product includes software developed by the University of
  154.  *    California, Berkeley and its contributors.
  155.  * 4. Neither the name of the University nor the names of its contributors
  156.  *    may be used to endorse or promote products derived from this software
  157.  *    without specific prior written permission.
  158.  *
  159.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  160.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  161.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  162.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  163.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  164.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  165.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  166.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  167.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  168.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  169.  * SUCH DAMAGE.
  170.  *
  171.  *    @(#)uipc_socket.c    7.28 (Berkeley) 5/4/91
  172.  */
  173.  
  174. #include <conf.h>
  175.  
  176. #include <sys/param.h>
  177. #include <sys/systm.h>
  178. #include <sys/malloc.h>
  179. #include <sys/mbuf.h>
  180. #include <sys/domain.h>
  181. #include <sys/kernel.h>
  182. #include <sys/protosw.h>
  183. #include <sys/socket.h>
  184. #include <sys/socketvar.h>
  185.  
  186. #include <sys/synch.h>
  187. #include <api/amiga_api.h>
  188.  
  189. #include <kern/amiga_includes.h>
  190.  
  191. #include <kern/uipc_socket_protos.h>
  192. #include <kern/uipc_socket2_protos.h>
  193. #include <kern/uipc_domain_protos.h>
  194. #include <kern/amiga_select_protos.h>
  195.  
  196. /*
  197.  * Socket operation routines.
  198.  * These routines are called by the routines in
  199.  * sys_socket.c or from a system process, and
  200.  * implement the semantics of socket operations by
  201.  * switching out to the protocol specific routines.
  202.  */
  203. int
  204. socreate(dom, aso, type, proto)
  205.         int dom;
  206.         struct socket **aso;
  207.     register int type;
  208.     int proto;
  209. {
  210. #ifndef AMITCP
  211.         struct proc *p = (struct proc*)cthread_data(cthread_self());
  212. #endif /* AMITCP */
  213.     register struct protosw *prp;
  214.     register struct socket *so;
  215.     register int error;
  216.  
  217.     if (proto)
  218.         prp = pffindproto(dom, proto, type);
  219.     else
  220.         prp = pffindtype(dom,