1*aca3beaaSApple OSS Distributions /* 2*aca3beaaSApple OSS Distributions * Copyright (c) 2008-2017 Apple Inc. All rights reserved. 3*aca3beaaSApple OSS Distributions * 4*aca3beaaSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5*aca3beaaSApple OSS Distributions * 6*aca3beaaSApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code 7*aca3beaaSApple OSS Distributions * as defined in and that are subject to the Apple Public Source License 8*aca3beaaSApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in 9*aca3beaaSApple OSS Distributions * compliance with the License. The rights granted to you under the License 10*aca3beaaSApple OSS Distributions * may not be used to create, or enable the creation or redistribution of, 11*aca3beaaSApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to 12*aca3beaaSApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any 13*aca3beaaSApple OSS Distributions * terms of an Apple operating system software license agreement. 14*aca3beaaSApple OSS Distributions * 15*aca3beaaSApple OSS Distributions * Please obtain a copy of the License at 16*aca3beaaSApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file. 17*aca3beaaSApple OSS Distributions * 18*aca3beaaSApple OSS Distributions * The Original Code and all software distributed under the License are 19*aca3beaaSApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20*aca3beaaSApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21*aca3beaaSApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22*aca3beaaSApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23*aca3beaaSApple OSS Distributions * Please see the License for the specific language governing rights and 24*aca3beaaSApple OSS Distributions * limitations under the License. 25*aca3beaaSApple OSS Distributions * 26*aca3beaaSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27*aca3beaaSApple OSS Distributions */ 28*aca3beaaSApple OSS Distributions /*! 29*aca3beaaSApple OSS Distributions * @header kpi_socket.h 30*aca3beaaSApple OSS Distributions * This header defines an API for creating and interacting with sockets 31*aca3beaaSApple OSS Distributions * in the kernel. It is possible to create sockets in the kernel 32*aca3beaaSApple OSS Distributions * without an associated file descriptor. In some cases, a reference to 33*aca3beaaSApple OSS Distributions * the socket may be known while the file descriptor is not. These 34*aca3beaaSApple OSS Distributions * functions can be used for interacting with sockets in the kernel. 35*aca3beaaSApple OSS Distributions * The API is similar to the user space socket API. 36*aca3beaaSApple OSS Distributions */ 37*aca3beaaSApple OSS Distributions #ifndef __KPI_SOCKET__ 38*aca3beaaSApple OSS Distributions #define __KPI_SOCKET__ 39*aca3beaaSApple OSS Distributions 40*aca3beaaSApple OSS Distributions #include <sys/types.h> 41*aca3beaaSApple OSS Distributions #include <sys/kernel_types.h> 42*aca3beaaSApple OSS Distributions #include <sys/socket.h> 43*aca3beaaSApple OSS Distributions 44*aca3beaaSApple OSS Distributions #ifndef PRIVATE 45*aca3beaaSApple OSS Distributions #include <Availability.h> 46*aca3beaaSApple OSS Distributions #define __NKE_API_DEPRECATED __API_DEPRECATED("Network Kernel Extension KPI is deprecated", macos(10.4, 10.15)) 47*aca3beaaSApple OSS Distributions #else 48*aca3beaaSApple OSS Distributions #define __NKE_API_DEPRECATED 49*aca3beaaSApple OSS Distributions #endif /* PRIVATE */ 50*aca3beaaSApple OSS Distributions 51*aca3beaaSApple OSS Distributions __BEGIN_DECLS 52*aca3beaaSApple OSS Distributions 53*aca3beaaSApple OSS Distributions struct timeval; 54*aca3beaaSApple OSS Distributions 55*aca3beaaSApple OSS Distributions /*! 56*aca3beaaSApple OSS Distributions * @typedef sock_upcall 57*aca3beaaSApple OSS Distributions * 58*aca3beaaSApple OSS Distributions * @discussion sock_upcall is used by a socket to notify an in kernel 59*aca3beaaSApple OSS Distributions * client that data is waiting. Instead of making blocking calls in 60*aca3beaaSApple OSS Distributions * the kernel, a client can specify an upcall which will be called 61*aca3beaaSApple OSS Distributions * when data is available or the socket is ready for sending. 62*aca3beaaSApple OSS Distributions * 63*aca3beaaSApple OSS Distributions * Calls to your upcall function are not serialized and may be 64*aca3beaaSApple OSS Distributions * called concurrently from multiple threads in the kernel. 65*aca3beaaSApple OSS Distributions * 66*aca3beaaSApple OSS Distributions * Your upcall function will be called: 67*aca3beaaSApple OSS Distributions * when there is data more than the low water mark for reading, 68*aca3beaaSApple OSS Distributions * or when there is space for a write, 69*aca3beaaSApple OSS Distributions * or when there is a connection to accept, 70*aca3beaaSApple OSS Distributions * or when a socket is connected, 71*aca3beaaSApple OSS Distributions * or when a socket is closed or disconnected 72*aca3beaaSApple OSS Distributions * 73*aca3beaaSApple OSS Distributions * @param so A reference to the socket that's ready. 74*aca3beaaSApple OSS Distributions * @param cookie The cookie passed in when the socket was created. 75*aca3beaaSApple OSS Distributions * @param waitf Indicates whether or not it's safe to block. 76*aca3beaaSApple OSS Distributions */ 77*aca3beaaSApple OSS Distributions typedef void (*sock_upcall)(socket_t so, void *cookie, int waitf); 78*aca3beaaSApple OSS Distributions 79*aca3beaaSApple OSS Distributions #ifdef KERNEL_PRIVATE 80*aca3beaaSApple OSS Distributions /*! 81*aca3beaaSApple OSS Distributions * @typedef sock_evupcall 82*aca3beaaSApple OSS Distributions * 83*aca3beaaSApple OSS Distributions * @discussion sock_evupcall is used by a socket to notify an in kernel 84*aca3beaaSApple OSS Distributions * client when an event occurs. Instead of making blocking calls in 85*aca3beaaSApple OSS Distributions * the kernel, a client can specify an upcall which will be called 86*aca3beaaSApple OSS Distributions * when an event status is available. 87*aca3beaaSApple OSS Distributions * @param so A reference to the socket that's ready. 88*aca3beaaSApple OSS Distributions * @param cookie The cookie passed in when the socket was created. 89*aca3beaaSApple OSS Distributions * @param event Indicates the event as defined by SO_FILT_HINT_* 90*aca3beaaSApple OSS Distributions */ 91*aca3beaaSApple OSS Distributions typedef void (*sock_evupcall)(socket_t so, void *cookie, uint32_t event); 92*aca3beaaSApple OSS Distributions #endif /* KERNEL_PRIVATE */ 93*aca3beaaSApple OSS Distributions 94*aca3beaaSApple OSS Distributions /*! 95*aca3beaaSApple OSS Distributions * @function sock_accept 96*aca3beaaSApple OSS Distributions * @discussion Accepts an incoming connection on a socket. See 'man 2 97*aca3beaaSApple OSS Distributions * accept' for more information. Allocating a socket in this manner 98*aca3beaaSApple OSS Distributions * creates a socket with no associated file descriptor. 99*aca3beaaSApple OSS Distributions * @param so The listening socket you'd like to accept a connection on. 100*aca3beaaSApple OSS Distributions * @param from A pointer to a socket address that will be filled in 101*aca3beaaSApple OSS Distributions * with the address the connection is from. 102*aca3beaaSApple OSS Distributions * @param fromlen Maximum length of from. 103*aca3beaaSApple OSS Distributions * @param flags Supports MSG_DONTWAIT and MSG_USEUPCALL. If 104*aca3beaaSApple OSS Distributions * MSG_DONTWAIT is set, accept will return EWOULDBLOCK if there are 105*aca3beaaSApple OSS Distributions * no connections ready to be accepted. If MSG_USEUPCALL is set, 106*aca3beaaSApple OSS Distributions * the created socket will use the same upcall function attached to 107*aca3beaaSApple OSS Distributions * the original socket. 108*aca3beaaSApple OSS Distributions * @param callback A notifier function to be called when an event 109*aca3beaaSApple OSS Distributions * occurs on the socket. This may be NULL. 110*aca3beaaSApple OSS Distributions * @param cookie A cookie passed directly to the callback. 111*aca3beaaSApple OSS Distributions * @param new_so Upon success, *new_so will be a reference to a new 112*aca3beaaSApple OSS Distributions * socket for tracking the connection. 113*aca3beaaSApple OSS Distributions * @result 0 on success otherwise the errno error. 114*aca3beaaSApple OSS Distributions */ 115*aca3beaaSApple OSS Distributions #ifdef KERNEL_PRIVATE 116*aca3beaaSApple OSS Distributions extern errno_t sock_accept_internal(socket_t so, struct sockaddr *from, int fromlen, 117*aca3beaaSApple OSS Distributions int flags, sock_upcall callback, void *cookie, socket_t *new_so); 118*aca3beaaSApple OSS Distributions 119*aca3beaaSApple OSS Distributions #define sock_accept(so, from, fromlen, flags, callback, cookie, new_so) \ 120*aca3beaaSApple OSS Distributions sock_accept_internal((so), (from), (fromlen), (flags), (callback), \ 121*aca3beaaSApple OSS Distributions (cookie), (new_so)) 122*aca3beaaSApple OSS Distributions #else 123*aca3beaaSApple OSS Distributions extern errno_t sock_accept(socket_t so, struct sockaddr *from, int fromlen, 124*aca3beaaSApple OSS Distributions int flags, sock_upcall callback, void *cookie, socket_t *new_so) 125*aca3beaaSApple OSS Distributions __NKE_API_DEPRECATED; 126*aca3beaaSApple OSS Distributions #endif /* KERNEL_PRIVATE */ 127*aca3beaaSApple OSS Distributions 128*aca3beaaSApple OSS Distributions /*! 129*aca3beaaSApple OSS Distributions * @function sock_bind 130*aca3beaaSApple OSS Distributions * @discussion Binds a socket to a specific address. See 'man 2 bind' 131*aca3beaaSApple OSS Distributions * for more information. 132*aca3beaaSApple OSS Distributions * @param so The socket to be bound. 133*aca3beaaSApple OSS Distributions * @param to The local address the socket should be bound to. 134*aca3beaaSApple OSS Distributions * @result 0 on success otherwise the errno error. 135*aca3beaaSApple OSS Distributions */ 136*aca3beaaSApple OSS Distributions extern errno_t sock_bind(socket_t so, const struct sockaddr *to) 137*aca3beaaSApple OSS Distributions __NKE_API_DEPRECATED; 138*aca3beaaSApple OSS Distributions 139*aca3beaaSApple OSS Distributions /*! 140*aca3beaaSApple OSS Distributions * @function sock_connect 141*aca3beaaSApple OSS Distributions * @discussion Initiates a connection on the socket. See 'man 2 142*aca3beaaSApple OSS Distributions * connect' for more information. 143*aca3beaaSApple OSS Distributions * @param so The socket to be connect. 144*aca3beaaSApple OSS Distributions * @param to The remote address the socket should connect to. 145*aca3beaaSApple OSS Distributions * @param flags Flags for connecting. The only flag supported so far is 146*aca3beaaSApple OSS Distributions * MSG_DONTWAIT. MSG_DONTWAIT will perform a non-blocking connect. 147*aca3beaaSApple OSS Distributions * sock_connect will return immediately with EINPROGRESS. The 148*aca3beaaSApple OSS Distributions * upcall, if supplied, will be called when the connection is 149*aca3beaaSApple OSS Distributions * completed. 150*aca3beaaSApple OSS Distributions * @result 0 on success, EINPROGRESS for a non-blocking connect that 151*aca3beaaSApple OSS Distributions * has not completed, otherwise the errno error. 152*aca3beaaSApple OSS Distributions */ 153*aca3beaaSApple OSS Distributions extern errno_t sock_connect(socket_t so, const struct sockaddr *to, int flags) 154*aca3beaaSApple OSS Distributions __NKE_API_DEPRECATED; 155*aca3beaaSApple OSS Distributions 156*aca3beaaSApple OSS Distributions #ifdef KERNEL_PRIVATE 157*aca3beaaSApple OSS Distributions /* 158*aca3beaaSApple OSS Distributions * This function was added to support NFS. NFS does something funny, 159*aca3beaaSApple OSS Distributions * setting a short timeout and checking to see if it should abort the 160*aca3beaaSApple OSS Distributions * connect every two seconds. Ideally, NFS would use the upcall to be 161*aca3beaaSApple OSS Distributions * notified when the connect is complete. 162*aca3beaaSApple OSS Distributions * 163*aca3beaaSApple OSS Distributions * If you feel you need to use this function, please contact us to 164*aca3beaaSApple OSS Distributions * explain why. 165*aca3beaaSApple OSS Distributions * 166*aca3beaaSApple OSS Distributions * @function sock_connectwait 167*aca3beaaSApple OSS Distributions * @discussion Allows a caller to wait on a socket connect. 168*aca3beaaSApple OSS Distributions * @param so The socket being connected. 169*aca3beaaSApple OSS Distributions * @param tv The amount of time to wait. 170*aca3beaaSApple OSS Distributions * @result 0 on success otherwise the errno error. EINPROGRESS will be 171*aca3beaaSApple OSS Distributions * returned if the connection did not complete in the timeout 172*aca3beaaSApple OSS Distributions * specified. 173*aca3beaaSApple OSS Distributions */ 174*aca3beaaSApple OSS Distributions extern errno_t sock_connectwait(socket_t so, const struct timeval *tv); 175*aca3beaaSApple OSS Distributions #endif /* KERNEL_PRIVATE */ 176*aca3beaaSApple OSS Distributions 177*aca3beaaSApple OSS Distributions /*! 178*aca3beaaSApple OSS Distributions * @function sock_getpeername 179*aca3beaaSApple OSS Distributions * @discussion Retrieves the remote address of a connected socket. See 180*aca3beaaSApple OSS Distributions * 'man 2 getpeername'. 181*aca3beaaSApple OSS Distributions * @param so The socket. 182*aca3beaaSApple OSS Distributions * @param peername Storage for the peer name. 183*aca3beaaSApple OSS Distributions * @param peernamelen Length of storage for the peer name. 184*aca3beaaSApple OSS Distributions * @result 0 on success otherwise the errno error. 185*aca3beaaSApple OSS Distributions */ 186*aca3beaaSApple OSS Distributions extern errno_t sock_getpeername(socket_t so, struct sockaddr *peername, 187*aca3beaaSApple OSS Distributions int peernamelen) 188*aca3beaaSApple OSS Distributions __NKE_API_DEPRECATED; 189*aca3beaaSApple OSS Distributions 190*aca3beaaSApple OSS Distributions /*! 191*aca3beaaSApple OSS Distributions * @function sock_getsockname 192*aca3beaaSApple OSS Distributions * @discussion Retrieves the local address of a socket. See 'man 2 193*aca3beaaSApple OSS Distributions * getsockname'. 194*aca3beaaSApple OSS Distributions * @param so The socket. 195*aca3beaaSApple OSS Distributions * @param sockname Storage for the local name. 196*aca3beaaSApple OSS Distributions * @param socknamelen Length of storage for the socket name. 197*aca3beaaSApple OSS Distributions * @result 0 on success otherwise the errno error. 198*aca3beaaSApple OSS Distributions */ 199*aca3beaaSApple OSS Distributions extern errno_t sock_getsockname(socket_t so, struct sockaddr *sockname, 200*aca3beaaSApple OSS Distributions int socknamelen) 201*aca3beaaSApple OSS Distributions __NKE_API_DEPRECATED; 202*aca3beaaSApple OSS Distributions 203*aca3beaaSApple OSS Distributions /*! 204*aca3beaaSApple OSS Distributions * @function sock_getsockopt 205*aca3beaaSApple OSS Distributions * @discussion Retrieves a socket option. See 'man 2 getsockopt'. 206*aca3beaaSApple OSS Distributions * @param so The socket. 207*aca3beaaSApple OSS Distributions * @param level Level of the socket option. 208*aca3beaaSApple OSS Distributions * @param optname The option name. 209*aca3beaaSApple OSS Distributions * @param optval The option value. 210*aca3beaaSApple OSS Distributions * @param optlen The length of optval, returns the actual length. 211*aca3beaaSApple OSS Distributions * @result 0 on success otherwise the errno error. 212*aca3beaaSApple OSS Distributions */ 213*aca3beaaSApple OSS Distributions extern errno_t sock_getsockopt(socket_t so, int level, int optname, 214*aca3beaaSApple OSS Distributions void *optval, int *optlen) 215*aca3beaaSApple OSS Distributions __NKE_API_DEPRECATED; 216*aca3beaaSApple OSS Distributions 217*aca3beaaSApple OSS Distributions /*! 218*aca3beaaSApple OSS Distributions * @function sock_ioctl 219*aca3beaaSApple OSS Distributions * @discussion Performs an ioctl operation on a socket. See 'man 2 ioctl'. 220*aca3beaaSApple OSS Distributions * @param so The socket. 221*aca3beaaSApple OSS Distributions * @param request The ioctl name. 222*aca3beaaSApple OSS Distributions * @param argp The argument. 223*aca3beaaSApple OSS Distributions * @result 0 on success otherwise the errno error. 224*aca3beaaSApple OSS Distributions */ 225*aca3beaaSApple OSS Distributions extern errno_t sock_ioctl(socket_t so, unsigned long request, void *argp) 226*aca3beaaSApple OSS Distributions __NKE_API_DEPRECATED; 227*aca3beaaSApple OSS Distributions 228*aca3beaaSApple OSS Distributions /*! 229*aca3beaaSApple OSS Distributions * @function sock_setsockopt 230*aca3beaaSApple OSS Distributions * @discussion Sets a socket option. See 'man 2 setsockopt'. 231*aca3beaaSApple OSS Distributions * @param so The socket. 232*aca3beaaSApple OSS Distributions * @param level Level of the socket option. 233*aca3beaaSApple OSS Distributions * @param optname The option name. 234*aca3beaaSApple OSS Distributions * @param optval The option value. 235*aca3beaaSApple OSS Distributions * @param optlen The length of optval. 236*aca3beaaSApple OSS Distributions * @result 0 on success otherwise the errno error. 237*aca3beaaSApple OSS Distributions */ 238*aca3beaaSApple OSS Distributions extern errno_t sock_setsockopt(socket_t so, int level, int optname, 239*aca3beaaSApple OSS Distributions const void *optval, int optlen) 240*aca3beaaSApple OSS Distributions __NKE_API_DEPRECATED; 241*aca3beaaSApple OSS Distributions 242*aca3beaaSApple OSS Distributions #ifdef KERNEL_PRIVATE 243*aca3beaaSApple OSS Distributions /* 244*aca3beaaSApple OSS Distributions * This function was added to support AFP setting the traffic class 245*aca3beaaSApple OSS Distributions * for a backup stream within a wireless LAN or over link-local address. 246*aca3beaaSApple OSS Distributions * 247*aca3beaaSApple OSS Distributions * If you feel you need to use this function, please contact us to 248*aca3beaaSApple OSS Distributions * explain why. 249*aca3beaaSApple OSS Distributions * 250*aca3beaaSApple OSS Distributions * @function sock_settclassopt 251*aca3beaaSApple OSS Distributions * @discussion Allows a caller to set the traffic class. 252*aca3beaaSApple OSS Distributions * @param so The socket. 253*aca3beaaSApple OSS Distributions * @param optval The option value. 254*aca3beaaSApple OSS Distributions * @param optlen The length of optval. 255*aca3beaaSApple OSS Distributions * @result 0 on success otherwise the errno error. 256*aca3beaaSApple OSS Distributions */ 257*aca3beaaSApple OSS Distributions extern errno_t sock_settclassopt(socket_t so, const void* optval, size_t optlen); 258*aca3beaaSApple OSS Distributions 259*aca3beaaSApple OSS Distributions /* 260*aca3beaaSApple OSS Distributions * This function was added to support AFP getting the traffic class 261*aca3beaaSApple OSS Distributions * set on a stream. 262*aca3beaaSApple OSS Distributions * 263*aca3beaaSApple OSS Distributions * This is also a private API, please contact us if you need to use it. 264*aca3beaaSApple OSS Distributions * 265*aca3beaaSApple OSS Distributions * @function sockgettclassopt 266*aca3beaaSApple OSS Distributions * @discussion Allows a caller to get the traffic class. 267*aca3beaaSApple OSS Distributions * @param so The socket. 268*aca3beaaSApple OSS Distributions * @param optval The option value. 269*aca3beaaSApple OSS Distributions * @param optlen The length of optval, returns the actual length. 270*aca3beaaSApple OSS Distributions * @result 0 on success otherwise the errno error. 271*aca3beaaSApple OSS Distributions */ 272*aca3beaaSApple OSS Distributions extern errno_t sock_gettclassopt(socket_t so, void* optval, size_t* optlen); 273*aca3beaaSApple OSS Distributions 274*aca3beaaSApple OSS Distributions #ifdef XNU_KERNEL_PRIVATE 275*aca3beaaSApple OSS Distributions extern void socket_set_traffic_mgt_flags_locked(socket_t so, u_int8_t flags); 276*aca3beaaSApple OSS Distributions extern void socket_clear_traffic_mgt_flags_locked(socket_t so, u_int8_t flags); 277*aca3beaaSApple OSS Distributions #endif /* XNU_KERNEL_PRIVATE */ 278*aca3beaaSApple OSS Distributions #ifdef BSD_KERNEL_PRIVATE 279*aca3beaaSApple OSS Distributions extern void socket_set_traffic_mgt_flags(socket_t so, u_int8_t flags); 280*aca3beaaSApple OSS Distributions extern void socket_clear_traffic_mgt_flags(socket_t so, u_int8_t flags); 281*aca3beaaSApple OSS Distributions extern errno_t socket_defunct(struct proc *, socket_t so, int); 282*aca3beaaSApple OSS Distributions extern errno_t sock_receive_internal(socket_t, struct msghdr *, mbuf_t *, 283*aca3beaaSApple OSS Distributions int, size_t *); 284*aca3beaaSApple OSS Distributions #endif /* BSD_KERNEL_PRIVATE */ 285*aca3beaaSApple OSS Distributions #endif /* KERNEL_PRIVATE */ 286*aca3beaaSApple OSS Distributions 287*aca3beaaSApple OSS Distributions /*! 288*aca3beaaSApple OSS Distributions * @function sock_listen 289*aca3beaaSApple OSS Distributions * @discussion Indicate that the socket should start accepting incoming 290*aca3beaaSApple OSS Distributions * connections. See 'man 2 listen'. 291*aca3beaaSApple OSS Distributions * @param so The socket. 292*aca3beaaSApple OSS Distributions * @param backlog The maximum length of the queue of pending connections. 293*aca3beaaSApple OSS Distributions * @result 0 on success otherwise the errno error. 294*aca3beaaSApple OSS Distributions */ 295*aca3beaaSApple OSS Distributions extern errno_t sock_listen(socket_t so, int backlog) 296*aca3beaaSApple OSS Distributions __NKE_API_DEPRECATED; 297*aca3beaaSApple OSS Distributions 298*aca3beaaSApple OSS Distributions /*! 299*aca3beaaSApple OSS Distributions * @function sock_receive 300*aca3beaaSApple OSS Distributions * @discussion Receive data from a socket. Similar to recvmsg. See 'man 301*aca3beaaSApple OSS Distributions * 2 recvmsg' for more information about receiving data. 302*aca3beaaSApple OSS Distributions * @param so The socket. 303*aca3beaaSApple OSS Distributions * @param msg The msg describing how the data should be received. 304*aca3beaaSApple OSS Distributions * @param flags See 'man 2 recvmsg'. 305*aca3beaaSApple OSS Distributions * @param recvdlen Number of bytes received, same as return value of 306*aca3beaaSApple OSS Distributions * userland recvmsg. 307*aca3beaaSApple OSS Distributions * @result 0 on success, EWOULDBLOCK if non-blocking and operation 308*aca3beaaSApple OSS Distributions * would cause the thread to block, otherwise the errno error. 309*aca3beaaSApple OSS Distributions */ 310*aca3beaaSApple OSS Distributions extern errno_t sock_receive(socket_t so, struct msghdr *msg, int flags, 311*aca3beaaSApple OSS Distributions size_t *recvdlen) 312*aca3beaaSApple OSS Distributions __NKE_API_DEPRECATED; 313*aca3beaaSApple OSS Distributions 314*aca3beaaSApple OSS Distributions /*! 315*aca3beaaSApple OSS Distributions * @function sock_receivembuf 316*aca3beaaSApple OSS Distributions * @discussion Receive data from a socket. Similar to sock_receive 317*aca3beaaSApple OSS Distributions * though data is returned as a chain of mbufs. See 'man 2 recvmsg' 318*aca3beaaSApple OSS Distributions * for more information about receiving data. 319*aca3beaaSApple OSS Distributions * @param so The socket. 320*aca3beaaSApple OSS Distributions * @param msg The msg describing how the data should be received. May 321*aca3beaaSApple OSS Distributions * be NULL. The msg_iov is ignored. 322*aca3beaaSApple OSS Distributions * @param data Upon return *data will be a reference to an mbuf chain 323*aca3beaaSApple OSS Distributions * containing the data received. This eliminates copying the data 324*aca3beaaSApple OSS Distributions * out of the mbufs. Caller is responsible for freeing the mbufs. 325*aca3beaaSApple OSS Distributions * @param flags See 'man 2 recvmsg'. 326*aca3beaaSApple OSS Distributions * @param recvlen Maximum number of bytes to receive in the mbuf chain. 327*aca3beaaSApple OSS Distributions * Upon return, this value will be set to the number of bytes 328*aca3beaaSApple OSS Distributions * received, same as return value of userland recvmsg. 329*aca3beaaSApple OSS Distributions * @result 0 on success, EWOULDBLOCK if non-blocking and operation 330*aca3beaaSApple OSS Distributions * would cause the thread to block, otherwise the errno error. 331*aca3beaaSApple OSS Distributions */ 332*aca3beaaSApple OSS Distributions extern errno_t sock_receivembuf(socket_t so, struct msghdr *msg, mbuf_t *data, 333*aca3beaaSApple OSS Distributions int flags, size_t *recvlen) 334*aca3beaaSApple OSS Distributions __NKE_API_DEPRECATED; 335*aca3beaaSApple OSS Distributions 336*aca3beaaSApple OSS Distributions /*! 337*aca3beaaSApple OSS Distributions * @function sock_send 338*aca3beaaSApple OSS Distributions * @discussion Send data on a socket. Similar to sendmsg. See 'man 2 339*aca3beaaSApple OSS Distributions * sendmsg' for more information about sending data. 340*aca3beaaSApple OSS Distributions * @param so The socket. 341*aca3beaaSApple OSS Distributions * @param msg The msg describing how the data should be sent. Any 342*aca3beaaSApple OSS Distributions * pointers must point to data in the kernel. 343*aca3beaaSApple OSS Distributions * @param flags See 'man 2 sendmsg'. 344*aca3beaaSApple OSS Distributions * @param sentlen The number of bytes sent. 345*aca3beaaSApple OSS Distributions * @result 0 on success, EWOULDBLOCK if non-blocking and operation 346*aca3beaaSApple OSS Distributions * would cause the thread to block, otherwise the errno error. 347*aca3beaaSApple OSS Distributions */ 348*aca3beaaSApple OSS Distributions extern errno_t sock_send(socket_t so, const struct msghdr *msg, int flags, 349*aca3beaaSApple OSS Distributions size_t *sentlen) 350*aca3beaaSApple OSS Distributions __NKE_API_DEPRECATED; 351*aca3beaaSApple OSS Distributions 352*aca3beaaSApple OSS Distributions /*! 353*aca3beaaSApple OSS Distributions * @function sock_sendmbuf 354*aca3beaaSApple OSS Distributions * @discussion Send data in an mbuf on a socket. Similar to sock_send 355*aca3beaaSApple OSS Distributions * only the data to be sent is taken from the mbuf chain. 356*aca3beaaSApple OSS Distributions * @param so The socket. 357*aca3beaaSApple OSS Distributions * @param msg The msg describing how the data should be sent. The 358*aca3beaaSApple OSS Distributions * msg_iov is ignored. msg may be NULL. 359*aca3beaaSApple OSS Distributions * @param data The mbuf chain of data to send. 360*aca3beaaSApple OSS Distributions * @param flags See 'man 2 sendmsg'. 361*aca3beaaSApple OSS Distributions * @param sentlen The number of bytes sent. 362*aca3beaaSApple OSS Distributions * @result 0 on success, EWOULDBLOCK if non-blocking and operation 363*aca3beaaSApple OSS Distributions * would cause the thread to block, otherwise the errno error. 364*aca3beaaSApple OSS Distributions * Regardless of return value, the mbuf chain 'data' will be freed. 365*aca3beaaSApple OSS Distributions */ 366*aca3beaaSApple OSS Distributions extern errno_t sock_sendmbuf(socket_t so, const struct msghdr *msg, mbuf_t data, 367*aca3beaaSApple OSS Distributions int flags, size_t *sentlen) 368*aca3beaaSApple OSS Distributions __NKE_API_DEPRECATED; 369*aca3beaaSApple OSS Distributions 370*aca3beaaSApple OSS Distributions #ifdef KERNEL_PRIVATE 371*aca3beaaSApple OSS Distributions /*! 372*aca3beaaSApple OSS Distributions * @function sock_sendmbuf_can_wait 373*aca3beaaSApple OSS Distributions * @discussion Variation of sock_sendmbuf that can wait for the send socket 374*aca3beaaSApple OSS Distributions * buffer to drain when it is full instead of returning EMSGSIZE. 375*aca3beaaSApple OSS Distributions * @param so The socket. 376*aca3beaaSApple OSS Distributions * @param msg The msg describing how the data should be sent. The 377*aca3beaaSApple OSS Distributions * msg_iov is ignored. msg may be NULL. 378*aca3beaaSApple OSS Distributions * @param data The mbuf chain of data to send. 379*aca3beaaSApple OSS Distributions * @param flags See 'man 2 sendmsg'. 380*aca3beaaSApple OSS Distributions * @param sentlen The number of bytes sent. 381*aca3beaaSApple OSS Distributions * @result 0 on success, EWOULDBLOCK if non-blocking and operation 382*aca3beaaSApple OSS Distributions * would cause the thread to block, otherwise the errno error. 383*aca3beaaSApple OSS Distributions * Regardless of return value, the mbuf chain 'data' will be freed. 384*aca3beaaSApple OSS Distributions */ 385*aca3beaaSApple OSS Distributions extern errno_t sock_sendmbuf_can_wait(socket_t so, const struct msghdr *msg, mbuf_t data, 386*aca3beaaSApple OSS Distributions int flags, size_t *sentlen); 387*aca3beaaSApple OSS Distributions #define HAS_SOCK_SENDMBUF_CAN_WAIT 1 388*aca3beaaSApple OSS Distributions 389*aca3beaaSApple OSS Distributions #endif /* KERNEL_PRIVATE */ 390*aca3beaaSApple OSS Distributions 391*aca3beaaSApple OSS Distributions /*! 392*aca3beaaSApple OSS Distributions * @function sock_shutdown 393*aca3beaaSApple OSS Distributions * @discussion Shutdown one or both directions of a connection. See 394*aca3beaaSApple OSS Distributions * 'man 2 shutdown' for more information. 395*aca3beaaSApple OSS Distributions * @param so The socket. 396*aca3beaaSApple OSS Distributions * @param how SHUT_RD - shutdown receive. 397*aca3beaaSApple OSS Distributions * SHUT_WR - shutdown send. 398*aca3beaaSApple OSS Distributions * SHUT_RDWR - shutdown both. 399*aca3beaaSApple OSS Distributions * @result 0 on success otherwise the errno error. 400*aca3beaaSApple OSS Distributions */ 401*aca3beaaSApple OSS Distributions extern errno_t sock_shutdown(socket_t so, int how) 402*aca3beaaSApple OSS Distributions __NKE_API_DEPRECATED; 403*aca3beaaSApple OSS Distributions 404*aca3beaaSApple OSS Distributions /*! 405*aca3beaaSApple OSS Distributions * @function sock_socket 406*aca3beaaSApple OSS Distributions * @discussion Allocate a socket. Allocating a socket in this manner 407*aca3beaaSApple OSS Distributions * creates a socket with no associated file descriptor. For more 408*aca3beaaSApple OSS Distributions * information, see 'man 2 socket'. 409*aca3beaaSApple OSS Distributions * @param domain The socket domain (PF_INET, etc...). 410*aca3beaaSApple OSS Distributions * @param type The socket type (SOCK_STREAM, SOCK_DGRAM, etc...). 411*aca3beaaSApple OSS Distributions * @param protocol The socket protocol. 412*aca3beaaSApple OSS Distributions * @param callback A notifier function to be called when an event 413*aca3beaaSApple OSS Distributions * occurs on the socket. This may be NULL. 414*aca3beaaSApple OSS Distributions * @param cookie A cookie passed directly to the callback. 415*aca3beaaSApple OSS Distributions * @param new_so Upon success, a reference to the new socket. 416*aca3beaaSApple OSS Distributions * @result 0 on success otherwise the errno error. 417*aca3beaaSApple OSS Distributions */ 418*aca3beaaSApple OSS Distributions #ifdef KERNEL_PRIVATE 419*aca3beaaSApple OSS Distributions extern errno_t sock_socket_internal(int domain, int type, int protocol, 420*aca3beaaSApple OSS Distributions sock_upcall callback, void *cookie, socket_t *new_so); 421*aca3beaaSApple OSS Distributions 422*aca3beaaSApple OSS Distributions #define sock_socket(domain, type, protocol, callback, cookie, new_so) \ 423*aca3beaaSApple OSS Distributions sock_socket_internal((domain), (type), (protocol), \ 424*aca3beaaSApple OSS Distributions (callback), (cookie), (new_so)) 425*aca3beaaSApple OSS Distributions #else 426*aca3beaaSApple OSS Distributions extern errno_t sock_socket(int domain, int type, int protocol, 427*aca3beaaSApple OSS Distributions sock_upcall callback, void *cookie, socket_t *new_so) 428*aca3beaaSApple OSS Distributions __NKE_API_DEPRECATED; 429*aca3beaaSApple OSS Distributions #endif /* KERNEL_PRIVATE */ 430*aca3beaaSApple OSS Distributions 431*aca3beaaSApple OSS Distributions /*! 432*aca3beaaSApple OSS Distributions * @function sock_close 433*aca3beaaSApple OSS Distributions * @discussion Close the socket. 434*aca3beaaSApple OSS Distributions * @param so The socket to close. This should only ever be a socket 435*aca3beaaSApple OSS Distributions * created with sock_socket. Closing a socket created in user space 436*aca3beaaSApple OSS Distributions * using sock_close may leave a file descriptor pointing to the 437*aca3beaaSApple OSS Distributions * closed socket, resulting in undefined behavior. 438*aca3beaaSApple OSS Distributions */ 439*aca3beaaSApple OSS Distributions extern void sock_close(socket_t so) 440*aca3beaaSApple OSS Distributions __NKE_API_DEPRECATED; 441*aca3beaaSApple OSS Distributions 442*aca3beaaSApple OSS Distributions /* 443*aca3beaaSApple OSS Distributions * @function sock_retain 444*aca3beaaSApple OSS Distributions * @discussion Prevents the socket from closing 445*aca3beaaSApple OSS Distributions * @param so The socket to close. Increment a retain count on the 446*aca3beaaSApple OSS Distributions * socket, preventing it from being closed when sock_close is 447*aca3beaaSApple OSS Distributions * called. This is used when a File Descriptor is passed (and 448*aca3beaaSApple OSS Distributions * closed) from userland and the kext wants to keep ownership of 449*aca3beaaSApple OSS Distributions * that socket. It is used in conjunction with 450*aca3beaaSApple OSS Distributions * sock_release(socket_t so). 451*aca3beaaSApple OSS Distributions */ 452*aca3beaaSApple OSS Distributions extern void sock_retain(socket_t so) 453*aca3beaaSApple OSS Distributions __NKE_API_DEPRECATED; 454*aca3beaaSApple OSS Distributions 455*aca3beaaSApple OSS Distributions /* 456*aca3beaaSApple OSS Distributions * @function sock_release 457*aca3beaaSApple OSS Distributions * @discussion Decrement the retain count and close the socket if the 458*aca3beaaSApple OSS Distributions * retain count reaches zero. 459*aca3beaaSApple OSS Distributions * @param so The socket to release. This is used to release ownership 460*aca3beaaSApple OSS Distributions * on a socket acquired with sock_retain. When the last retain 461*aca3beaaSApple OSS Distributions * count is reached, this will call sock_close to close the socket. 462*aca3beaaSApple OSS Distributions */ 463*aca3beaaSApple OSS Distributions extern void sock_release(socket_t so) 464*aca3beaaSApple OSS Distributions __NKE_API_DEPRECATED; 465*aca3beaaSApple OSS Distributions 466*aca3beaaSApple OSS Distributions /*! 467*aca3beaaSApple OSS Distributions * @function sock_setpriv 468*aca3beaaSApple OSS Distributions * @discussion Set the privileged bit in the socket. Allows for 469*aca3beaaSApple OSS Distributions * operations that require root privileges. 470*aca3beaaSApple OSS Distributions * @param so The socket on which to modify the SS_PRIV flag. 471*aca3beaaSApple OSS Distributions * @param on Indicate whether or not the SS_PRIV flag should be set. 472*aca3beaaSApple OSS Distributions * @result 0 on success otherwise the errno error. 473*aca3beaaSApple OSS Distributions */ 474*aca3beaaSApple OSS Distributions extern errno_t sock_setpriv(socket_t so, int on) 475*aca3beaaSApple OSS Distributions __NKE_API_DEPRECATED; 476*aca3beaaSApple OSS Distributions 477*aca3beaaSApple OSS Distributions /*! 478*aca3beaaSApple OSS Distributions * @function sock_isconnected 479*aca3beaaSApple OSS Distributions * @discussion Returns whether or not the socket is connected. 480*aca3beaaSApple OSS Distributions * @param so The socket to check. 481*aca3beaaSApple OSS Distributions * @result 0 - socket is not connected. 1 - socket is connected. 482*aca3beaaSApple OSS Distributions */ 483*aca3beaaSApple OSS Distributions extern int sock_isconnected(socket_t so) 484*aca3beaaSApple OSS Distributions __NKE_API_DEPRECATED; 485*aca3beaaSApple OSS Distributions 486*aca3beaaSApple OSS Distributions /*! 487*aca3beaaSApple OSS Distributions * @function sock_isnonblocking 488*aca3beaaSApple OSS Distributions * @discussion Returns whether or not the socket is non-blocking. In 489*aca3beaaSApple OSS Distributions * the context of this KPI, non-blocking means that functions to 490*aca3beaaSApple OSS Distributions * perform operations on a socket will not wait for completion. 491*aca3beaaSApple OSS Distributions * 492*aca3beaaSApple OSS Distributions * To enable or disable blocking, use the FIONBIO ioctl. The 493*aca3beaaSApple OSS Distributions * parameter is an int. If the int is zero, the socket will block. 494*aca3beaaSApple OSS Distributions * If the parameter is non-zero, the socket will not block. 495*aca3beaaSApple OSS Distributions * @result 0 - socket will block. 1 - socket will not block. 496*aca3beaaSApple OSS Distributions */ 497*aca3beaaSApple OSS Distributions extern int sock_isnonblocking(socket_t so) 498*aca3beaaSApple OSS Distributions __NKE_API_DEPRECATED; 499*aca3beaaSApple OSS Distributions 500*aca3beaaSApple OSS Distributions /*! 501*aca3beaaSApple OSS Distributions * @function sock_gettype 502*aca3beaaSApple OSS Distributions * @discussion Retrieves information about the socket. This is the same 503*aca3beaaSApple OSS Distributions * information that was used to create the socket. If any of the 504*aca3beaaSApple OSS Distributions * parameters following so are NULL, that information is not 505*aca3beaaSApple OSS Distributions * retrieved. 506*aca3beaaSApple OSS Distributions * @param so The socket to check. 507*aca3beaaSApple OSS Distributions * @param domain The domain of the socket (PF_INET, ...). May be NULL. 508*aca3beaaSApple OSS Distributions * @param type The socket type (SOCK_STREAM, SOCK_DGRAM, ...). May be NULL. 509*aca3beaaSApple OSS Distributions * @param protocol The socket protocol. May be NULL. 510*aca3beaaSApple OSS Distributions * @result 0 on success otherwise the errno error. 511*aca3beaaSApple OSS Distributions */ 512*aca3beaaSApple OSS Distributions extern errno_t sock_gettype(socket_t so, int *domain, int *type, int *protocol) 513*aca3beaaSApple OSS Distributions __NKE_API_DEPRECATED; 514*aca3beaaSApple OSS Distributions 515*aca3beaaSApple OSS Distributions #ifdef KERNEL_PRIVATE 516*aca3beaaSApple OSS Distributions /* 517*aca3beaaSApple OSS Distributions * @function sock_nointerrupt 518*aca3beaaSApple OSS Distributions * @discussion Disables interrupt on socket buffers (sets SB_NOINTR on 519*aca3beaaSApple OSS Distributions * send and receive socket buffers). 520*aca3beaaSApple OSS Distributions * @param so The socket to modify. 521*aca3beaaSApple OSS Distributions * @param on Indicate whether or not the SB_NOINTR flag should be set. 522*aca3beaaSApple OSS Distributions * @result 0 on success otherwise the errno error. 523*aca3beaaSApple OSS Distributions */ 524*aca3beaaSApple OSS Distributions extern errno_t sock_nointerrupt(socket_t so, int on); 525*aca3beaaSApple OSS Distributions 526*aca3beaaSApple OSS Distributions /* 527*aca3beaaSApple OSS Distributions * @function sock_getlistener 528*aca3beaaSApple OSS Distributions * @discussion Retrieves the listening socket of a pre-accepted socket, 529*aca3beaaSApple OSS Distributions * i.e. a socket which is still in the incomplete/completed list. 530*aca3beaaSApple OSS Distributions * Once a socket has been accepted, the information pertaining 531*aca3beaaSApple OSS Distributions * to its listener is no longer available. Therefore, modules 532*aca3beaaSApple OSS Distributions * interested in finding out the listening socket should install 533*aca3beaaSApple OSS Distributions * the appropriate socket filter callback (sf_attach) which gets 534*aca3beaaSApple OSS Distributions * invoked prior to the socket being fully accepted, and call 535*aca3beaaSApple OSS Distributions * this routine at such a time to obtain the listener. Callers 536*aca3beaaSApple OSS Distributions * are guaranteed that the listener socket will not go away 537*aca3beaaSApple OSS Distributions * during the sf_attach callback, and therefore the value is 538*aca3beaaSApple OSS Distributions * safe to be used only in that callback context. Callers should 539*aca3beaaSApple OSS Distributions * therefore take note that the listening socket's lock will be 540*aca3beaaSApple OSS Distributions * held throughout the duration of the callback. 541*aca3beaaSApple OSS Distributions * @param so The pre-accepted socket. 542*aca3beaaSApple OSS Distributions * @result Non-NULL value which indicates the listening socket; otherwise, 543*aca3beaaSApple OSS Distributions * NULL if the socket is not in the incomplete/completed list 544*aca3beaaSApple OSS Distributions * of a listener. 545*aca3beaaSApple OSS Distributions */ 546*aca3beaaSApple OSS Distributions extern socket_t sock_getlistener(socket_t so); 547*aca3beaaSApple OSS Distributions 548*aca3beaaSApple OSS Distributions /* 549*aca3beaaSApple OSS Distributions * @function sock_getaddr 550*aca3beaaSApple OSS Distributions * @discussion Retrieves the local or remote address of a socket. 551*aca3beaaSApple OSS Distributions * This is a composite of sock_getpeername and sock_getsockname, 552*aca3beaaSApple OSS Distributions * except that the allocated socket address is returned to the 553*aca3beaaSApple OSS Distributions * caller, and that the caller is reponsible for calling 554*aca3beaaSApple OSS Distributions * sock_freeaddr once finished with it. 555*aca3beaaSApple OSS Distributions * @param so The socket. 556*aca3beaaSApple OSS Distributions * @param psockname Pointer to the storage for the socket name. 557*aca3beaaSApple OSS Distributions * @param peername 0 for local address, and non-zero for peer address. 558*aca3beaaSApple OSS Distributions * @result 0 on success otherwise the errno error. 559*aca3beaaSApple OSS Distributions */ 560*aca3beaaSApple OSS Distributions extern errno_t sock_getaddr(socket_t so, struct sockaddr **psockname, 561*aca3beaaSApple OSS Distributions int peername); 562*aca3beaaSApple OSS Distributions 563*aca3beaaSApple OSS Distributions /* 564*aca3beaaSApple OSS Distributions * @function sock_freeaddr 565*aca3beaaSApple OSS Distributions * @discussion Frees the socket address allocated by sock_getaddr. 566*aca3beaaSApple OSS Distributions * @param sockname The socket name to be freed. 567*aca3beaaSApple OSS Distributions */ 568*aca3beaaSApple OSS Distributions extern void sock_freeaddr(struct sockaddr *sockname); 569*aca3beaaSApple OSS Distributions 570*aca3beaaSApple OSS Distributions /* 571*aca3beaaSApple OSS Distributions * @function sock_setupcall 572*aca3beaaSApple OSS Distributions * @discussion Set the notifier function to be called when an event 573*aca3beaaSApple OSS Distributions * occurs on the socket. This may be set to NULL to disable 574*aca3beaaSApple OSS Distributions * further notifications. Setting the function does not 575*aca3beaaSApple OSS Distributions * affect currently notifications about to be sent or being sent. 576*aca3beaaSApple OSS Distributions * Note: When this function is used on a socket passed from 577*aca3beaaSApple OSS Distributions * userspace it is crucial to call sock_retain() on the socket 578*aca3beaaSApple OSS Distributions * otherwise a callback could be dispatched on a closed socket 579*aca3beaaSApple OSS Distributions * and cause a crash. 580*aca3beaaSApple OSS Distributions * @param sock The socket. 581*aca3beaaSApple OSS Distributions * @param callback The notifier function 582*aca3beaaSApple OSS Distributions * @param context A cookie passed directly to the callback 583*aca3beaaSApple OSS Distributions */ 584*aca3beaaSApple OSS Distributions extern errno_t sock_setupcall(socket_t sock, sock_upcall callback, 585*aca3beaaSApple OSS Distributions void *context); 586*aca3beaaSApple OSS Distributions 587*aca3beaaSApple OSS Distributions /* 588*aca3beaaSApple OSS Distributions * @function sock_setupcalls 589*aca3beaaSApple OSS Distributions * @discussion Set the notifier function to be called when an event 590*aca3beaaSApple OSS Distributions * occurs on the socket. This may be set to NULL to disable 591*aca3beaaSApple OSS Distributions * further notifications. Setting the function does not 592*aca3beaaSApple OSS Distributions * affect currently notifications about to be sent or being sent. 593*aca3beaaSApple OSS Distributions * Note: When this function is used on a socket passed from 594*aca3beaaSApple OSS Distributions * userspace it is crucial to call sock_retain() on the socket 595*aca3beaaSApple OSS Distributions * otherwise a callback could be dispatched on a closed socket 596*aca3beaaSApple OSS Distributions * and cause a crash. 597*aca3beaaSApple OSS Distributions * @param sock The socket. 598*aca3beaaSApple OSS Distributions * @param read_callback The read notifier function 599*aca3beaaSApple OSS Distributions * @param read_context A cookie passed directly to the read callback 600*aca3beaaSApple OSS Distributions * @param write_callback The write notifier function 601*aca3beaaSApple OSS Distributions * @param write_context A cookie passed directly to the write callback 602*aca3beaaSApple OSS Distributions */ 603*aca3beaaSApple OSS Distributions extern errno_t sock_setupcalls(socket_t sock, sock_upcall read_callback, 604*aca3beaaSApple OSS Distributions void *read_context, sock_upcall write_callback, void *write_context); 605*aca3beaaSApple OSS Distributions 606*aca3beaaSApple OSS Distributions /* 607*aca3beaaSApple OSS Distributions * @function sock_setupcalls_locked 608*aca3beaaSApple OSS Distributions * @discussion The locked version of sock_setupcalls 609*aca3beaaSApple OSS Distributions * @param locked: When sets, indicates that the callbacks expect to be 610*aca3beaaSApple OSS Distributions * on a locked socket. Thus, no unlock is done prior to 611*aca3beaaSApple OSS Distributions * calling the callback. 612*aca3beaaSApple OSS Distributions */ 613*aca3beaaSApple OSS Distributions extern void sock_setupcalls_locked(socket_t sock, 614*aca3beaaSApple OSS Distributions sock_upcall rcallback, void *rcontext, 615*aca3beaaSApple OSS Distributions sock_upcall wcallback, void *wcontext, int locked); 616*aca3beaaSApple OSS Distributions 617*aca3beaaSApple OSS Distributions /* 618*aca3beaaSApple OSS Distributions * @function sock_catchevents 619*aca3beaaSApple OSS Distributions * @discussion Set the notifier function to be called when an event 620*aca3beaaSApple OSS Distributions * occurs on the socket. This may be set to NULL to disable 621*aca3beaaSApple OSS Distributions * further notifications. Setting the function does not 622*aca3beaaSApple OSS Distributions * affect currently notifications about to be sent or being sent. 623*aca3beaaSApple OSS Distributions * @param sock The socket. 624*aca3beaaSApple OSS Distributions * @param event_callback The event notifier function 625*aca3beaaSApple OSS Distributions * @param event_context A cookie passed directly to the event callback 626*aca3beaaSApple OSS Distributions * @param event_mask One or more SO_FILT_HINT_* values OR'ed together, 627*aca3beaaSApple OSS Distributions * indicating the registered event(s). 628*aca3beaaSApple OSS Distributions */ 629*aca3beaaSApple OSS Distributions extern errno_t sock_catchevents(socket_t sock, sock_evupcall event_callback, 630*aca3beaaSApple OSS Distributions void *event_context, uint32_t event_mask); 631*aca3beaaSApple OSS Distributions 632*aca3beaaSApple OSS Distributions extern void sock_catchevents_locked(socket_t sock, sock_evupcall ecallback, 633*aca3beaaSApple OSS Distributions void *econtext, uint32_t emask); 634*aca3beaaSApple OSS Distributions 635*aca3beaaSApple OSS Distributions 636*aca3beaaSApple OSS Distributions /* 637*aca3beaaSApple OSS Distributions * @function sock_iskernel 638*aca3beaaSApple OSS Distributions * @discussion Returns true if the socket was created by the kernel or 639*aca3beaaSApple OSS Distributions * is owned by the kernel. 640*aca3beaaSApple OSS Distributions * @param sock The socket. 641*aca3beaaSApple OSS Distributions * @result True if the kernel owns the socket. 642*aca3beaaSApple OSS Distributions */ 643*aca3beaaSApple OSS Distributions extern int sock_iskernel(socket_t); 644*aca3beaaSApple OSS Distributions #endif /* KERNEL_PRIVATE */ 645*aca3beaaSApple OSS Distributions 646*aca3beaaSApple OSS Distributions __END_DECLS 647*aca3beaaSApple OSS Distributions #undef __NKE_API_DEPRECATED 648*aca3beaaSApple OSS Distributions #endif /* __KPI_SOCKET__ */ 649