socket.h revision e11c3f44f531fdff80941ce57c065d2ae861cefc
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* University Copyright- Copyright (c) 1982, 1986, 1988
* The Regents of the University of California
* All Rights Reserved
*
* University Acknowledgment- Portions of this document are derived from
* software developed by the University of California, Berkeley, and its
* contributors.
*/
#ifndef _SYS_SOCKET_H
#define _SYS_SOCKET_H
#include <sys/feature_tests.h>
#include <sys/socket_impl.h>
#if !defined(_XPG4_2) || defined(__EXTENSIONS__)
#ifndef _KERNEL
#include <sys/netconfig.h>
#endif /* !_KERNEL */
#endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
#ifdef __cplusplus
extern "C" {
#endif
#ifndef _SOCKLEN_T
#define _SOCKLEN_T
/*
* applications and is not required by austin.
*/
#else
#endif /* defined(_XPG4_2) && !defined(_XPG5) && !defined(_LP64) */
#else
typedef void *_RESTRICT_KYWD Psocklen_t;
#endif /* defined(_XPG4_2) || defined(_BOOT) */
#endif /* _SOCKLEN_T */
/*
* Definitions related to sockets: types, address families, options.
*/
#if !defined(_XPG4_2) || defined(__EXTENSIONS__)
#ifndef NC_TPI_CLTS
#endif /* !NC_TPI_CLTS */
#endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
/*
* Types
*/
#if !defined(_XPG4_2) || defined(__EXTENSIONS__)
#else
#endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
/*
* Option flags per-socket.
*/
#ifdef _KERNEL
/* when doing zero-copy */
struct so_snd_bufinfo {
};
#endif /* _KERNEL */
/*
* N.B.: The following definition is present only for compatibility
* with release 3.0. It will disappear in later releases.
*/
/*
* Additional options, not kept in so_options.
*/
/* "Socket"-level control message types: */
#ifdef _KERNEL
#endif /* _KERNEL */
#ifdef _KERNEL
/*
* new socket open flags to identify socket and acceptor streams
*/
/*
* Flags for socket_create() and socket_newconn()
*/
#define SOCKET_SLEEP KM_SLEEP
#define SOCKET_NOSLEEP KM_NOSLEEP
/*
* flags used by sockfs when falling back to tpi socket
*/
#define SO_FB_START 0x1
#define SO_FB_FINISH 0x2
#endif /* _KERNEL */
/*
* Structure used for manipulating linger option.
*/
struct linger {
int l_linger; /* linger time */
};
/*
*/
#if !defined(_XPG4_2) || defined(__EXTENSIONS__)
#endif
/*
* Address families.
*
* Some of these constant names are copied for the DTrace IP provider in
* in sync.
*/
#define AF_UNSPEC 0 /* unspecified */
#define AF_MAX 30
/*
* Protocol families, same as address families for now.
*/
#define PF_IMPLINK AF_IMPLINK
#define PF_DATAKIT AF_DATAKIT
#define PF_APPLETALK AF_APPLETALK
/*
* Maximum queue length specifiable by listen.
*/
#define SOMAXCONN 128
/*
* Message header for recvmsg and sendmsg calls.
*/
struct msghdr {
void *msg_name; /* optional address */
int msg_iovlen; /* # elements in msg_iov */
void *msg_control; /* ancillary data */
int msg_flags; /* flags on received message */
#else
int msg_accrightslen;
#endif /* defined(_XPG4_2) || defined(_KERNEL) */
};
#if defined(_KERNEL)
/*
* N.B.: we assume that omsghdr and nmsghdr are isomorphic, with
* the sole exception that nmsghdr has the additional msg_flags
* field at the end.
*/
struct omsghdr {
void *msg_name; /* optional address */
int msg_iovlen; /* # elements in msg_iov */
int msg_accrightslen;
};
#if defined(_SYSCALL32)
struct omsghdr32 {
};
struct msghdr32 {
};
#endif /* _SYSCALL32 */
#endif /* _KERNEL */
/* Added for XPGv2 compliance */
/* with left over data */
/* End of XPGv2 compliance */
#define MSG_MAXIOVLEN 16
#ifdef _KERNEL
/*
* for kernel socket only
*/
/* in timely manner */
#endif /* _KERNEL */
/* Added for XPGv2 compliance */
#define SHUT_RD 0
#define SHUT_WR 1
#define SHUT_RDWR 2
struct cmsghdr {
int cmsg_level; /* originating protocol */
int cmsg_type; /* protocol-specific type */
};
#if defined(__sparc)
/* To maintain backward compatibility, alignment needs to be 8 on sparc. */
#define _CMSG_HDR_ALIGNMENT 8
#else
/* for __i386 (and other future architectures) */
#define _CMSG_HDR_ALIGNMENT 4
#endif /* defined(__sparc) */
#endif /* defined(_XPG4_2) || defined(_KERNEL) */
#if defined(_XPG4_2)
/*
* The cmsg headers (and macros dealing with them) were made available as
* part of UNIX95 and hence need to be protected with a _XPG4_2 define.
*/
#define _CMSG_DATA_ALIGNMENT (sizeof (int))
~(_CMSG_HDR_ALIGNMENT - 1))
~(_CMSG_DATA_ALIGNMENT - 1))
#define CMSG_DATA(c) \
#define CMSG_FIRSTHDR(m) \
(((m)->msg_controllen < sizeof (struct cmsghdr)) ? \
#define CMSG_NXTHDR(m, c) \
(((c) == 0) ? CMSG_FIRSTHDR(m) : \
((((uintptr_t)_CMSG_HDR_ALIGN((char *)(c) + \
((struct cmsghdr *)0) : \
((struct cmsghdr *)_CMSG_HDR_ALIGN((char *)(c) + \
/* Amount of space + padding needed for a message of length l */
#define CMSG_SPACE(l) \
((unsigned int)_CMSG_HDR_ALIGN(sizeof (struct cmsghdr) + (l)))
/* Value to be used in cmsg_len, does not include trailing padding */
#define CMSG_LEN(l) \
((unsigned int)_CMSG_DATA_ALIGN(sizeof (struct cmsghdr)) + (l))
#endif /* _XPG4_2 */
#ifdef _XPG4_2
#ifdef __PRAGMA_REDEFINE_EXTNAME
#else /* __PRAGMA_REDEFINE_EXTNAME */
#define bind __xnet_bind
#define connect __xnet_connect
#define recvmsg __xnet_recvmsg
#define sendmsg __xnet_sendmsg
#define sendto __xnet_sendto
#define socket __xnet_socket
#define socketpair __xnet_socketpair
#define getsockopt __xnet_getsockopt
#endif /* __PRAGMA_REDEFINE_EXTNAME */
#endif /* _XPG4_2 */
#ifdef __PRAGMA_REDEFINE_EXTNAME
#else /* __PRAGMA_REDEFINE_EXTNAME */
#define listen __xnet_listen
#endif /* __PRAGMA_REDEFINE_EXTNAME */
#endif /* (_XPG4_2) && !defined(_XPG5) */
#ifdef __STDC__
extern int listen(int, int); /* XXX - fixme??? where do I go */
extern int socketpair(int, int, int, int *);
extern int setsockopt(int, int, int, const void *, socklen_t);
extern int shutdown(int, int);
extern int socket(int, int, int);
extern int sockatmark(int);
#endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */
#else /* __STDC__ */
extern int accept();
extern int bind();
extern int connect();
extern int getpeername();
extern int getsockname();
extern int getsockopt();
extern int listen();
extern int recv();
extern int recvfrom();
extern int send();
extern int sendto();
extern int setsockopt();
extern int sockatmark();
extern int socket();
extern int recvmsg();
extern int sendmsg();
extern int shutdown();
extern int socketpair();
#endif /* __STDC__ */
#endif /* !defined(_KERNEL) || defined(_BOOT) */
#ifdef __cplusplus
}
#endif
#endif /* _SYS_SOCKET_H */