os161-1.99
 All Data Structures
socket.h
00001 /*
00002  * Copyright (c) 2004, 2008
00003  *      The President and Fellows of Harvard College.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the University nor the names of its contributors
00014  *    may be used to endorse or promote products derived from this software
00015  *    without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00027  * SUCH DAMAGE.
00028  */
00029 
00030 #ifndef _KERN_SOCKET_H_
00031 #define _KERN_SOCKET_H_
00032 
00033 /*
00034  * Socket-related definitions, for <sys/socket.h>.
00035  */
00036 
00037 
00038 /*
00039  * Important
00040  */
00041 
00042 /* Socket types that we (might) support. */
00043 #define SOCK_STREAM     1       /* stream */
00044 #define SOCK_DGRAM      2       /* packet */
00045 #define SOCK_RAW        3       /* raw packet */
00046 
00047 /* Address families that we (might) support. */
00048 #define AF_UNSPEC       0
00049 #define AF_UNIX         1
00050 #define AF_INET         2
00051 #define AF_INET6        3
00052 
00053 /* Protocol families. Pointless layer of indirection in the standard API. */
00054 #define PF_UNSPEC       AF_UNSPEC
00055 #define PF_UNIX         AF_UNIX
00056 #define PF_INET         AF_INET
00057 #define PF_INET6        AF_INET6
00058 
00059 /*
00060  * Socket address structures. Socket addresses are polymorphic, and
00061  * the polymorphism is handled by casting pointers. It's fairly gross,
00062  * but way too deeply standardized to ever change.
00063  *
00064  * Each address family defines a sockaddr type (sockaddr_un,
00065  * sockaddr_in, etc.) struct sockaddr is the common prefix of all
00066  * these, and struct sockaddr_storage is defined to be large enough to
00067  * hold any of them.
00068  *
00069  * The complex padding in sockaddr_storage forces it to be aligned,
00070  * which wouldn't happen if it were just a char array.
00071  */
00072 
00073 struct sockaddr {
00074    __u8 sa_len;
00075    __u8 sa_family;
00076 };
00077 
00078 #define _SS_SIZE        128
00079 struct sockaddr_storage {
00080    __u8 ss_len;
00081    __u8 ss_family;
00082    __u8 __ss_pad1;
00083    __u8 __ss_pad2;
00084    __u32 __ss_pad3;
00085    __u64 __ss_pad4;
00086    char __ss_pad5[_SS_SIZE - sizeof(__u64) - sizeof(__u32) - 4*sizeof(__u8)];
00087 };
00088 
00089 
00090 /*
00091  * Not very important.
00092  */
00093 
00094 /*
00095  * msghdr structures for sendmsg() and recvmsg().
00096  */
00097 
00098 struct msghdr {
00099         void *msg_name;         /* really sockaddr; address, or null */
00100         socklen_t msg_namelen;  /* size of msg_name object, or 0 */
00101         struct iovec *msg_iov;  /* I/O buffers */
00102         int msg_iovlen;         /* number of iovecs */
00103         void *msg_control;      /* auxiliary data area, or null */
00104         socklen_t msg_controllen; /* size of msg_control area */
00105         int msg_flags;          /* flags */
00106 };
00107 
00108 struct cmsghdr {
00109         socklen_t cmsg_len;     /* length of control data, including header */
00110         int cmsg_level;         /* protocol layer item originates from */
00111         int cmsg_type;          /* protocol-specific message type */
00112         /* char cmsg_data[];*/  /* data follows the header */
00113 };
00114 
00115 
00116 #endif /* _KERN_SOCKET_H_ */
 All Data Structures