⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iso_pcb.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
/*- * Copyright (c) 1991, 1993 *	The Regents of the University of California.  All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software *    must display the following acknowledgement: *	This product includes software developed by the University of *	California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors *    may be used to endorse or promote products derived from this software *    without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * *	@(#)iso_pcb.c	8.1 (Berkeley) 6/10/93 *//***********************************************************		Copyright IBM Corporation 1987                      All Rights ReservedPermission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and thatboth that copyright notice and this permission notice appear in supporting documentation, and that the name of IBM not beused in advertising or publicity pertaining to distribution of thesoftware without specific, written prior permission.  IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDINGALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALLIBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES ORANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THISSOFTWARE.******************************************************************//* * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison *//* * $Header: iso_pcb.c,v 4.5 88/06/29 14:59:56 hagens Exp $ * $Source: /usr/argo/sys/netiso/RCS/iso_pcb.c,v $ * * Iso address family net-layer(s) pcb stuff. NEH 1/29/87 */#ifdef ISO#include <sys/param.h>#include <sys/systm.h>#include <sys/mbuf.h>#include <sys/socket.h>#include <sys/socketvar.h>#include <sys/errno.h>#include <netiso/argo_debug.h>#include <netiso/iso.h>#include <netiso/clnp.h>#include <netinet/in_systm.h>#include <net/if.h>#include <net/route.h>#include <netiso/iso_pcb.h>#include <netiso/iso_var.h>#include <sys/protosw.h>#ifdef TPCONS#include <netccitt/x25.h>#include <netccitt/pk.h>#include <netccitt/pk_var.h>#endif#define PCBNULL (struct isopcb *)0struct	iso_addr zeroiso_addr = {	0};/* * FUNCTION:		iso_pcballoc * * PURPOSE:			creates an isopcb structure in an mbuf, *					with socket (so), and  *					puts it in the queue with head (head) * * RETURNS:			0 if OK, ENOBUFS if can't alloc the necessary mbuf */intiso_pcballoc(so, head)	struct socket *so;	struct isopcb *head;{	register struct isopcb *isop;	IFDEBUG(D_ISO)		printf("iso_pcballoc(so 0x%x)\n", so);	ENDDEBUG	MALLOC(isop, struct isopcb *, sizeof(*isop), M_PCB, M_NOWAIT);	if (isop == NULL)		return ENOBUFS;	bzero((caddr_t)isop, sizeof(*isop));	isop->isop_head = head;	isop->isop_socket = so;	insque(isop, head);	if (so)		so->so_pcb = (caddr_t)isop;	return 0;}	/* * FUNCTION:		iso_pcbbind * * PURPOSE:			binds the address given in *(nam) to the socket *					specified by the isopcb in *(isop) *					If the given address is zero, it makes sure the *					address isn't already in use and if it's got a network *					portion, we look for an interface with that network *					address.  If the address given is zero, we allocate *					a port and stuff it in the (nam) structure. * * RETURNS:			errno E* or 0 if ok. * * SIDE EFFECTS:	increments head->isop_lport if it allocates a port # * * NOTES:			 */#define	satosiso(sa)	((struct sockaddr_iso *)(sa))intiso_pcbbind(isop, nam)	register struct isopcb *isop;	struct mbuf *nam;{	register struct isopcb *head = isop->isop_head;	register struct sockaddr_iso *siso;	struct iso_ifaddr *ia;	union {		char data[2];		u_short s;	} suf;	IFDEBUG(D_ISO)		printf("iso_pcbbind(isop 0x%x, nam 0x%x)\n", isop, nam);	ENDDEBUG	suf.s = 0;	if (iso_ifaddr == 0) /* any interfaces attached? */		return EADDRNOTAVAIL;	if (isop->isop_laddr)  /* already bound */		return EADDRINUSE;	if(nam == (struct mbuf *)0) {		isop->isop_laddr = &isop->isop_sladdr;		isop->isop_sladdr.siso_len = sizeof(struct sockaddr_iso);		isop->isop_sladdr.siso_family = AF_ISO;		isop->isop_sladdr.siso_tlen = 2;		isop->isop_sladdr.siso_nlen = 0;		isop->isop_sladdr.siso_slen = 0;		isop->isop_sladdr.siso_plen = 0;		goto noname;	}	siso = mtod(nam, struct sockaddr_iso *);	IFDEBUG(D_ISO)		printf("iso_pcbbind(name len 0x%x)\n", nam->m_len);		printf("The address is %s\n", clnp_iso_addrp(&siso->siso_addr));	ENDDEBUG	/*	 * We would like sort of length check but since some OSI addrs	 * do not have fixed length, we can't really do much.	 * The ONLY thing we can say is that an osi addr has to have	 * at LEAST an afi and one more byte and had better fit into	 * a struct iso_addr.	 * However, in fact the size of the whole thing is a struct	 * sockaddr_iso, so probably this is what we should check for.	 */	if( (nam->m_len < 2) || (nam->m_len < siso->siso_len)) {			return ENAMETOOLONG;	}	if (siso->siso_nlen) {		/* non-zero net addr- better match one of our interfaces */		IFDEBUG(D_ISO)			printf("iso_pcbbind: bind to NOT zeroisoaddr\n");		ENDDEBUG		for (ia = iso_ifaddr; ia; ia = ia->ia_next) 			if (SAME_ISOADDR(siso, &ia->ia_addr))				break;		if (ia == 0)			return EADDRNOTAVAIL;	} 	if (siso->siso_len <= sizeof (isop->isop_sladdr)) {		isop->isop_laddr = &isop->isop_sladdr;	} else {		if ((nam = m_copy(nam, 0, (int)M_COPYALL)) == 0)			return ENOBUFS;		isop->isop_laddr = mtod(nam, struct sockaddr_iso *);	}	bcopy((caddr_t)siso, (caddr_t)isop->isop_laddr, siso->siso_len);	if (siso->siso_tlen == 0)		goto noname;	if ((isop->isop_socket->so_options & SO_REUSEADDR) == 0 &&		iso_pcblookup(head, 0, (caddr_t)0, isop->isop_laddr))		return EADDRINUSE;	if (siso->siso_tlen <= 2) {		bcopy(TSEL(siso), suf.data, sizeof(suf.data));		suf.s = ntohs(suf.s);		if((suf.s < ISO_PORT_RESERVED) &&		   (isop->isop_socket->so_state && SS_PRIV) == 0)			return EACCES;	} else {		register char *cp;noname:		cp = TSEL(isop->isop_laddr);	IFDEBUG(D_ISO)		printf("iso_pcbbind noname\n");	ENDDEBUG		do {			if (head->isop_lport++ < ISO_PORT_RESERVED ||			    head->isop_lport > ISO_PORT_USERRESERVED)				head->isop_lport = ISO_PORT_RESERVED;			suf.s = htons(head->isop_lport);			cp[0] = suf.data[0];			cp[1] = suf.data[1];		} while (iso_pcblookup(head, 0, (caddr_t)0, isop->isop_laddr));	}	IFDEBUG(D_ISO)		printf("iso_pcbbind returns 0, suf 0x%x\n", suf);	ENDDEBUG	return 0;}/* * FUNCTION:		iso_pcbconnect * * PURPOSE:			Make the isopcb (isop) look like it's connected. *					In other words, give it the peer address given in  *					the mbuf * (nam).   Make sure such a combination *					of local, peer addresses doesn't already exist *					for this protocol.  Internet mentality prevails here, *					wherein a src,dst pair uniquely identifies a connection. * 					Both net address and port must be specified in argument  *					(nam). * 					If we don't have a local address for this socket yet,  *					we pick one by calling iso_pcbbind(). * * RETURNS:			errno E* or 0 if ok. * * SIDE EFFECTS:	Looks up a route, which may cause one to be left *					in the isopcb. * * NOTES:			 */intiso_pcbconnect(isop, nam)	register struct isopcb *isop;	struct mbuf *nam;{	register struct sockaddr_iso	*siso = mtod(nam, struct sockaddr_iso *);	int								local_zero, error = 0;	struct iso_ifaddr 				*ia;	IFDEBUG(D_ISO)		printf("iso_pcbconnect(isop 0x%x sock 0x%x nam 0x%x",					isop, isop->isop_socket, nam);		printf("nam->m_len 0x%x), addr:\n", nam->m_len);		dump_isoaddr(siso);	ENDDEBUG	if (nam->m_len < siso->siso_len)		return EINVAL; 	if (siso->siso_family != AF_ISO)		return EAFNOSUPPORT;	if (siso->siso_nlen == 0) {		if (ia = iso_ifaddr) {			int nlen = ia->ia_addr.siso_nlen;			ovbcopy(TSEL(siso), nlen + TSEL(siso),				siso->siso_plen + siso->siso_tlen + siso->siso_slen);			bcopy((caddr_t)&ia->ia_addr.siso_addr,				  (caddr_t)&siso->siso_addr, nlen + 1);			/* includes siso->siso_nlen = nlen; */		} else			return EADDRNOTAVAIL;	}	/*	 * Local zero means either not bound, or bound to a TSEL, but no	 * particular local interface.  So, if we want to send somebody	 * we need to choose a return address.	 */	local_zero = 		((isop->isop_laddr == 0) || (isop->isop_laddr->siso_nlen == 0));	if (local_zero) {		int flags;		IFDEBUG(D_ISO)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -