2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
31 * Copyright (c) 1982, 1986, 1989, 1993
32 * The Regents of the University of California. All rights reserved.
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions
37 * 1. Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 * 2. Redistributions in binary form must reproduce the above copyright
40 * notice, this list of conditions and the following disclaimer in the
41 * documentation and/or other materials provided with the distribution.
42 * 3. All advertising materials mentioning features or use of this software
43 * must display the following acknowledgement:
44 * This product includes software developed by the University of
45 * California, Berkeley and its contributors.
46 * 4. Neither the name of the University nor the names of its contributors
47 * may be used to endorse or promote products derived from this software
48 * without specific prior written permission.
50 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62 * @(#)unpcb.h 8.1 (Berkeley) 6/2/93
68 #include <sys/appleapiopts.h>
69 #include <sys/queue.h>
71 #include <sys/ucred.h>
74 * Protocol control block for an active
75 * instance of a UNIX internal protocol.
77 * A socket may be associated with an vnode in the
78 * file system. If so, the unp_vnode pointer holds
79 * a reference count to this vnode, which should be irele'd
80 * when the socket goes away.
82 * A socket may be connected to another socket, in which
83 * case the control block of the socket to which it is connected
84 * is given by unp_conn.
86 * A socket may be referenced by a number of sockets (e.g. several
87 * sockets may be connected to a datagram socket.) These sockets
88 * are in a linked list starting with unp_refs, linked through
89 * unp_nextref and null-terminated. Note that a socket may be referenced
90 * by a number of other sockets and may also reference a socket (not
91 * necessarily one which is referencing it). This generates
92 * the need for unp_refs and unp_nextref to be separate fields.
94 * Stream sockets keep copies of receive sockbuf sb_cc and sb_mbcnt
95 * so that changes in the sockbuf may be computed to modify
96 * back pressure on the sender accordingly.
99 typedef u_quad_t unp_gen_t
;
102 LIST_HEAD(unp_head
, unpcb
);
104 #define sotounpcb(so) ((struct unpcb *)((so)->so_pcb))
107 LIST_ENTRY(unpcb
) unp_link
; /* glue on list of all PCBs */
108 struct socket
*unp_socket
; /* pointer back to socket */
109 struct vnode
*unp_vnode
; /* if associated with file */
110 ino_t unp_ino
; /* fake inode number */
111 struct unpcb
*unp_conn
; /* control block of connected socket */
112 struct unp_head unp_refs
; /* referencing socket linked list */
113 LIST_ENTRY(unpcb
) unp_reflink
; /* link in unp_refs list */
114 struct sockaddr_un
*unp_addr
; /* bound address of socket */
115 int unp_cc
; /* copy of rcv.sb_cc */
116 int unp_mbcnt
; /* copy of rcv.sb_mbcnt */
117 unp_gen_t unp_gencnt
; /* generation count of this instance */
118 int unp_flags
; /* flags */
119 struct xucred unp_peercred
; /* peer credentials, if applicable */
124 * Flags in unp_flags.
126 * UNP_HAVEPC - indicates that the unp_peercred member is filled in
127 * and is really the credentials of the connected peer. This is used
128 * to determine whether the contents should be sent to the user or
131 * UNP_HAVEPCCACHED - indicates that the unp_peercred member is filled
132 * in, but does *not* contain the credentials of the connected peer
133 * (there may not even be a peer). This is set in unp_listen() when
134 * it fills in unp_peercred for later consumption by unp_connect().
136 #define UNP_HAVEPC 0x001
137 #define UNP_HAVEPCCACHED 0x002
140 struct unpcb_compat
{
142 #define unpcb_compat unpcb
145 LIST_ENTRY(unpcb_compat
) unp_link
; /* glue on list of all PCBs */
146 struct socket
*unp_socket
; /* pointer back to socket */
147 struct vnode
*unp_vnode
; /* if associated with file */
148 ino_t unp_ino
; /* fake inode number */
149 struct unpcb_compat
*unp_conn
; /* control block of connected socket */
150 struct unp_head unp_refs
; /* referencing socket linked list */
151 LIST_ENTRY(unpcb_compat
) unp_reflink
; /* link in unp_refs list */
152 struct sockaddr_un
*unp_addr
; /* bound address of socket */
153 int unp_cc
; /* copy of rcv.sb_cc */
154 int unp_mbcnt
; /* copy of rcv.sb_mbcnt */
155 unp_gen_t unp_gencnt
; /* generation count of this instance */
158 /* Hack alert -- this structure depends on <sys/socketvar.h>. */
159 #ifdef _SYS_SOCKETVAR_H_
161 size_t xu_len
; /* length of this structure */
162 struct unpcb_compat
*xu_unpp
; /* to help netstat, fstat */
163 struct unpcb_compat xu_unp
; /* our information */
165 struct sockaddr_un xuu_addr
; /* our bound address */
168 #define xu_addr xu_au.xuu_addr
170 struct sockaddr_un xuu_caddr
; /* their bound address */
173 #define xu_caddr xu_cau.xuu_caddr
174 struct xsocket xu_socket
;
175 u_quad_t xu_alignment_hack
;
177 #endif /* _SYS_SOCKETVAR_H_ */
187 #endif /* _SYS_UNPCB_H_ */