home *** CD-ROM | disk | FTP | other *** search
/ Network PC / Network PC.iso / amiga utilities / communication / internet / amitcp3.0b / src.lha / src / amitcp / net / raw_cb.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-08  |  6.3 KB  |  222 lines

  1. RCS_ID_C="$Id: raw_cb.c,v 1.7 1993/06/04 11:16:15 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.  * raw_cb.c --- Raw Socket Control Blocks
  8.  *
  9.  * Last modified: Fri Jun  4 00:39:07 1993 jraja
  10.  *
  11.  * HISTORY
  12.  * $Log: raw_cb.c,v $
  13.  * Revision 1.7  1993/06/04  11:16:15  jraja
  14.  * Fixes for first public release.
  15.  *
  16.  * Revision 1.6  1993/05/16  21:09:43  ppessi
  17.  * RCS version changed.
  18.  *
  19.  * Revision 1.5  1993/05/05  16:10:29  puhuri
  20.  * Fixes for final demo.
  21.  *
  22.  * Revision 1.4  93/04/05  17:46:13  17:46:13  jraja (Jarno Tapio Rajahalme)
  23.  * Changed spl storage variables to spl_t.
  24.  * Changed every .c file to use conf.h.
  25.  * 
  26.  * Revision 1.3  93/03/05  03:12:44  03:12:44  ppessi (Pekka Pessi)
  27.  * Compiles with SASC. Initial test version
  28.  * 
  29.  * Revision 1.2  93/02/25  19:52:21  19:52:21  ppessi (Pekka Pessi)
  30.  *  Added prototypes
  31.  * 
  32.  * Revision 1.1  92/11/20  13:32:31  13:32:31  jraja (Jarno Tapio Rajahalme)
  33.  * Initial revision
  34.  * 
  35.  *
  36.  */
  37.  
  38. /* 
  39.  * Mach Operating System
  40.  * Copyright (c) 1992 Carnegie Mellon University
  41.  * All Rights Reserved.
  42.  * 
  43.  * Permission to use, copy, modify and distribute this software and its
  44.  * documentation is hereby granted, provided that both the copyright
  45.  * notice and this permission notice appear in all copies of the
  46.  * software, derivative works or modified versions, and any portions
  47.  * thereof, and that both notices appear in supporting documentation.
  48.  * 
  49.  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
  50.  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
  51.  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  52.  * 
  53.  * Carnegie Mellon requests users of this software to return to
  54.  * 
  55.  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
  56.  *  School of Computer Science
  57.  *  Carnegie Mellon University
  58.  *  Pittsburgh PA 15213-3890
  59.  * 
  60.  * any improvements or extensions that they make and grant Carnegie Mellon 
  61.  * the rights to redistribute these changes.
  62.  */
  63. /*
  64.  * HISTORY
  65.  * Log:    raw_cb.c,v
  66.  * Revision 2.1  92/04/21  17:13:41  rwd
  67.  * BSDSS
  68.  * 
  69.  *
  70.  */
  71.  
  72. /*
  73.  * Copyright (c) 1980, 1986 Regents of the University of California.
  74.  * All rights reserved.
  75.  *
  76.  * Redistribution and use in source and binary forms, with or without
  77.  * modification, are permitted provided that the following conditions
  78.  * are met:
  79.  * 1. Redistributions of source code must retain the above copyright
  80.  *    notice, this list of conditions and the following disclaimer.
  81.  * 2. Redistributions in binary form must reproduce the above copyright
  82.  *    notice, this list of conditions and the following disclaimer in the
  83.  *    documentation and/or other materials provided with the distribution.
  84.  * 3. All advertising materials mentioning features or use of this software
  85.  *    must display the following acknowledgement:
  86.  *    This product includes software developed by the University of
  87.  *    California, Berkeley and its contributors.
  88.  * 4. Neither the name of the University nor the names of its contributors
  89.  *    may be used to endorse or promote products derived from this software
  90.  *    without specific prior written permission.
  91.  *
  92.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  93.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  94.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  95.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  96.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  97.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  98.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  99.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  100.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  101.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  102.  * SUCH DAMAGE.
  103.  *
  104.  *    @(#)raw_cb.c    7.11 (Berkeley) 6/28/90
  105.  */
  106.  
  107. #include <conf.h>
  108.  
  109. #include <sys/param.h>
  110. #include <sys/systm.h>
  111. #include <sys/malloc.h>
  112. #include <sys/mbuf.h>
  113. #include <sys/socket.h>
  114. #include <sys/socketvar.h>
  115. #include <sys/domain.h>
  116. #include <sys/protosw.h>
  117. #include <sys/errno.h>
  118.  
  119. #include <net/if.h>
  120. #include <net/route.h>
  121. #include <net/raw_cb.h>
  122. #include <netinet/in.h>
  123.  
  124. #include <protos/kern/uipc_socket_protos.h>
  125. #include <protos/kern/uipc_socket2_protos.h>
  126.  
  127. /* --- start moved from raw_cb.h --- */
  128. struct rawcb rawcb = {0};    /* head of list */
  129. /* --- end moved from raw_cb.h --- */
  130.  
  131. /*
  132.  * Routines to manage the raw protocol control blocks. 
  133.  *
  134.  * TODO:
  135.  *    hash lookups by protocol family/protocol + address family
  136.  *    take care of unique address problems per AF?
  137.  *    redo address binding to allow wildcards
  138.  */
  139.  
  140. u_long    raw_sendspace = RAWSNDQ;
  141. u_long    raw_recvspace = RAWRCVQ;
  142.  
  143. /*
  144.  * Allocate a control block and a nominal amount
  145.  * of buffer space for the socket.
  146.  */
  147. int
  148. raw_attach(register struct socket *so,
  149.        int proto)
  150. {
  151.     register struct rawcb *rp = sotorawcb(so);
  152.     int error;
  153.  
  154.     /*
  155.      * It is assumed that raw_attach is called
  156.      * after space has been allocated for the
  157.      * rawcb.
  158.      */
  159.     if (rp == 0)
  160.         return (ENOBUFS);
  161.     if (error = soreserve(so, raw_sendspace, raw_recvspace))
  162.         return (error);
  163.     rp->rcb_socket = so;
  164.     rp->rcb_proto.sp_family = so->so_proto->pr_domain->dom_family;
  165.     rp->rcb_proto.sp_protocol = proto;
  166.     insque(rp, &rawcb);
  167.     return (0);
  168. }
  169.  
  170. /*
  171.  * Detach the raw connection block and discard
  172.  * socket resources.
  173.  */
  174. void
  175. raw_detach(register struct rawcb *rp)
  176. {
  177.     struct socket *so = rp->rcb_socket;
  178.  
  179.     so->so_pcb = 0;
  180.     sofree(so);
  181.     remque(rp);
  182. #ifdef notdef
  183.     if (rp->rcb_laddr)
  184.         m_freem(dtom(rp->rcb_laddr));
  185.     rp->rcb_laddr = 0;
  186. #endif
  187.     bsd_free((caddr_t)(rp), M_PCB);
  188. }
  189.  
  190. /*
  191.  * Disconnect and possibly release resources.
  192.  */
  193. void
  194. raw_disconnect(struct rawcb *rp)
  195. {
  196.  
  197. #ifdef notdef
  198.     if (rp->rcb_faddr)
  199.         m_freem(dtom(rp->rcb_faddr));
  200.     rp->rcb_faddr = 0;
  201. #endif
  202.     if (rp->rcb_socket->so_state & SS_NOFDREF)
  203.         raw_detach(rp);
  204. }
  205.  
  206. #ifdef notdef
  207. raw_bind(so, nam)
  208.     register struct socket *so;
  209.     struct mbuf *nam;
  210. {
  211.     struct sockaddr *addr = mtod(nam, struct sockaddr *);
  212.     register struct rawcb *rp;
  213.  
  214.     if (ifnet == 0)
  215.         return (EADDRNOTAVAIL);
  216.     rp = sotorawcb(so);
  217.     nam = m_copym(nam, 0, M_COPYALL, M_WAITOK);
  218.     rp->rcb_laddr = mtod(nam, struct sockaddr *);
  219.     return (0);
  220. }
  221. #endif
  222.