1 /* 2 * Copyright (c) 1982, 1985, 1986 Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that this notice is preserved and that due credit is given 7 * to the University of California at Berkeley. The name of the University 8 * may not be used to endorse or promote products derived from this 9 * software without specific prior written permission. This software 10 * is provided ``as is'' without express or implied warranty. 11 * 12 * @(#)socket.h 7.2 (Berkeley) 12/30/87 13 */ 14 15 /* 16 * Definitions related to sockets: types, address families, options. 17 */ 18 19 /* 20 * Types 21 */ 22 #define SOCK_STREAM 1 /* stream socket */ 23 #define SOCK_DGRAM 2 /* datagram socket */ 24 #define SOCK_RAW 3 /* raw-protocol interface */ 25 #define SOCK_RDM 4 /* reliably-delivered message */ 26 #define SOCK_SEQPACKET 5 /* sequenced packet stream */ 27 28 /* 29 * Option flags per-socket. 30 */ 31 #define SO_DEBUG 0x0001 /* turn on debugging info recording */ 32 #define SO_ACCEPTCONN 0x0002 /* socket has had listen() */ 33 #define SO_REUSEADDR 0x0004 /* allow local address reuse */ 34 #define SO_KEEPALIVE 0x0008 /* keep connections alive */ 35 #define SO_DONTROUTE 0x0010 /* just use interface addresses */ 36 #define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */ 37 #define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */ 38 #define SO_LINGER 0x0080 /* linger on close if data present */ 39 #define SO_OOBINLINE 0x0100 /* leave received OOB data in line */ 40 41 /* 42 * Additional options, not kept in so_options. 43 */ 44 #define SO_SNDBUF 0x1001 /* send buffer size */ 45 #define SO_RCVBUF 0x1002 /* receive buffer size */ 46 #define SO_SNDLOWAT 0x1003 /* send low-water mark */ 47 #define SO_RCVLOWAT 0x1004 /* receive low-water mark */ 48 #define SO_SNDTIMEO 0x1005 /* send timeout */ 49 #define SO_RCVTIMEO 0x1006 /* receive timeout */ 50 #define SO_ERROR 0x1007 /* get error status and clear */ 51 #define SO_TYPE 0x1008 /* get socket type */ 52 53 /* 54 * Structure used for manipulating linger option. 55 */ 56 struct linger { 57 int l_onoff; /* option on/off */ 58 int l_linger; /* linger time */ 59 }; 60 61 /* 62 * Level number for (get/set)sockopt() to apply to socket itself. 63 */ 64 #define SOL_SOCKET 0xffff /* options for socket level */ 65 66 /* 67 * Address families. 68 */ 69 #define AF_UNSPEC 0 /* unspecified */ 70 #define AF_UNIX 1 /* local to host (pipes, portals) */ 71 #define AF_INET 2 /* internetwork: UDP, TCP, etc. */ 72 #define AF_IMPLINK 3 /* arpanet imp addresses */ 73 #define AF_PUP 4 /* pup protocols: e.g. BSP */ 74 #define AF_CHAOS 5 /* mit CHAOS protocols */ 75 #define AF_NS 6 /* XEROX NS protocols */ 76 #define AF_NBS 7 /* nbs protocols */ 77 #define AF_ECMA 8 /* european computer manufacturers */ 78 #define AF_DATAKIT 9 /* datakit protocols */ 79 #define AF_CCITT 10 /* CCITT protocols, X.25 etc */ 80 #define AF_SNA 11 /* IBM SNA */ 81 #define AF_DECnet 12 /* DECnet */ 82 #define AF_DLI 13 /* Direct data link interface */ 83 #define AF_LAT 14 /* LAT */ 84 #define AF_HYLINK 15 /* NSC Hyperchannel */ 85 #define AF_APPLETALK 16 /* Apple Talk */ 86 87 #define AF_MAX 17 88 89 /* 90 * Structure used by kernel to store most 91 * addresses. 92 */ 93 struct sockaddr { 94 u_short sa_family; /* address family */ 95 char sa_data[14]; /* up to 14 bytes of direct address */ 96 }; 97 98 /* 99 * Structure used by kernel to pass protocol 100 * information in raw sockets. 101 */ 102 struct sockproto { 103 u_short sp_family; /* address family */ 104 u_short sp_protocol; /* protocol */ 105 }; 106 107 /* 108 * Protocol families, same as address families for now. 109 */ 110 #define PF_UNSPEC AF_UNSPEC 111 #define PF_UNIX AF_UNIX 112 #define PF_INET AF_INET 113 #define PF_IMPLINK AF_IMPLINK 114 #define PF_PUP AF_PUP 115 #define PF_CHAOS AF_CHAOS 116 #define PF_NS AF_NS 117 #define PF_NBS AF_NBS 118 #define PF_ECMA AF_ECMA 119 #define PF_DATAKIT AF_DATAKIT 120 #define PF_CCITT AF_CCITT 121 #define PF_SNA AF_SNA 122 #define PF_DECnet AF_DECnet 123 #define PF_DLI AF_DLI 124 #define PF_LAT AF_LAT 125 #define PF_HYLINK AF_HYLINK 126 #define PF_APPLETALK AF_APPLETALK 127 128 #define PF_MAX AF_MAX 129 130 /* 131 * Maximum queue length specifiable by listen. 132 */ 133 #define SOMAXCONN 5 134 135 /* 136 * Message header for recvmsg and sendmsg calls. 137 */ 138 struct msghdr { 139 caddr_t msg_name; /* optional address */ 140 int msg_namelen; /* size of address */ 141 struct iovec *msg_iov; /* scatter/gather array */ 142 int msg_iovlen; /* # elements in msg_iov */ 143 caddr_t msg_accrights; /* access rights sent/received */ 144 int msg_accrightslen; 145 }; 146 147 #define MSG_OOB 0x1 /* process out-of-band data */ 148 #define MSG_PEEK 0x2 /* peek at incoming message */ 149 #define MSG_DONTROUTE 0x4 /* send without using routing tables */ 150 151 #define MSG_MAXIOVLEN 16 152