1 /* sys/socket.h */ 2 3 4 #ifndef _SYS_SOCKET_H 5 #define _SYS_SOCKET_H 6 7 #include <stdint.h> 8 #include <sys/types.h> 9 #include <sys/stat.h> 10 #include <sys/ioctl.h> 11 12 #if __cplusplus 13 extern "C" { 14 #endif /* __cplusplus */ 15 16 typedef uint32_t socklen_t; 17 18 /* These are the address/protocol families we'll be using... */ 19 /* NB these should be added to as required... */ 20 21 /* If we want to have Binary compatability we may need to alter these 22 * to agree with the Be versions... 23 */ 24 #define AF_UNSPEC 0 25 #define AF_INET 1 26 #define AF_LOCAL 2 27 #define AF_UNIX AF_LOCAL /* for compatability */ 28 #define AF_ROUTE 3 29 #define AF_LINK 4 30 #define AF_INET6 5 31 #define AF_IPX 7 32 #define AF_IMPLINK 20 33 34 #define AF_MAX 24 35 36 #define PF_UNSPEC AF_UNSPEC 37 #define PF_INET AF_INET 38 #define PF_ROUTE AF_ROUTE 39 #define PF_LINK AF_LINK 40 #define PF_INET6 AF_INET6 41 #define PF_IPX AF_IPX 42 #define PF_IMPLINK AF_IMPLINK 43 44 /* Types of socket we can create (eventually) */ 45 #ifndef BUILDING_R5_LIBNET 46 #define SOCK_STREAM 1 47 #define SOCK_DGRAM 2 48 #define SOCK_RAW 3 49 #define SOCK_MISC 255 50 #else /* BUILDING_R5_LIBNET */ 51 /* XXX: HACK: we use socket emulation for libnet.so */ 52 #define SOCK_DGRAM 10 53 #define SOCK_STREAM 11 54 #define SOCK_RAW 12 55 #define SOCK_MISC 255 56 #define SOCK_NATIVE_STREAM 1 57 #define SOCK_NATIVE_DGRAM 2 58 #define SOCK_NATIVE_RAW 3 59 #define SOCK_NATIVE_MISC 255 60 #endif /* BUILDING_R5_LIBNET */ 61 62 /* 63 * Option flags per-socket. 64 */ 65 #define SOL_SOCKET 0xffffffff 66 67 #define SO_ACCEPTCONN 0x00000001 /* socket has had listen() */ 68 #define SO_BROADCAST 0x00000002 /* permit sending of broadcast msgs */ 69 #define SO_DEBUG 0x00000004 /* turn on debugging info recording */ 70 #define SO_DONTROUTE 0x00000008 /* just use interface addresses */ 71 #define SO_KEEPALIVE 0x00000010 /* keep connections alive */ 72 #define SO_OOBINLINE 0x00000020 /* leave received OOB data in line */ 73 #define SO_REUSEADDR 0x00000040 /* allow local address reuse */ 74 #define SO_REUSEPORT 0x00000080 /* allow local address & port reuse */ 75 #define SO_USELOOPBACK 0x00000100 /* bypass hardware when possible */ 76 #define SO_LINGER 0x00000200 /* linger on close if data present */ 77 78 /* 79 * Additional options, not kept in so_options. 80 */ 81 #define SO_SNDBUF 0x40000001 /* send buffer size */ 82 #define SO_SNDLOWAT 0x40000002 /* send low-water mark */ 83 #define SO_SNDTIMEO 0x40000003 /* send timeout */ 84 #define SO_RCVBUF 0x40000004 /* receive buffer size */ 85 #define SO_RCVLOWAT 0x40000005 /* receive low-water mark */ 86 #define SO_RCVTIMEO 0x40000006 /* receive timeout */ 87 #define SO_ERROR 0x40000007 /* get error status and clear */ 88 #define SO_TYPE 0x40000008 /* get socket type */ 89 90 /* not handled by OpenBeOS */ 91 #define SO_NONBLOCK 0x40000009 92 #define SO_BINDTODEVICE 0x4000000a 93 94 /* only defined in OpenBeOS */ 95 #define SO_NETPROC 0x00001020 /* multiplex; network processing */ 96 97 /* 98 * These are the valid values for the "how" field used by shutdown(2). 99 */ 100 #define SHUT_RD 0 101 #define SHUT_WR 1 102 #define SHUT_RDWR 2 103 /* for BONE compatibility */ 104 #define SHUTDOWN_RECV SHUT_RD 105 #define SHUTDOWN_SEND SHUT_WR 106 #define SHUTDOWN_BOTH SHUT_RDWR 107 108 109 struct linger { 110 int l_onoff; 111 int l_linger; 112 }; 113 114 struct sockaddr { 115 uint8_t sa_len; 116 uint8_t sa_family; 117 uint8_t sa_data[30]; 118 }; 119 120 /* this can hold ANY sockaddr we care to throw at it! */ 121 struct sockaddr_storage { 122 uint8_t ss_len; /* total length */ 123 uint8_t ss_family; /* address family */ 124 uint8_t __ss_pad1[6]; /* align to quad */ 125 uint64_t __ss_pad2; /* force alignment for stupid compilers */ 126 uint8_t __ss_pad3[240]; /* pad to a total of 256 bytes */ 127 }; 128 129 struct sockproto { 130 uint16_t sp_family; 131 uint16_t sp_protocol; 132 }; 133 134 #define CTL_NET 4 135 136 #define CTL_NET_NAMES { \ 137 { 0, 0 }, \ 138 { "unix", CTLTYPE_NODE }, \ 139 { "inet", CTLTYPE_NODE }, \ 140 { "implink", CTLTYPE_NODE }, \ 141 { "pup", CTLTYPE_NODE }, \ 142 { "chaos", CTLTYPE_NODE }, \ 143 { "xerox_ns", CTLTYPE_NODE }, \ 144 { "iso", CTLTYPE_NODE }, \ 145 { "emca", CTLTYPE_NODE }, \ 146 { "datakit", CTLTYPE_NODE }, \ 147 { "ccitt", CTLTYPE_NODE }, \ 148 { "ibm_sna", CTLTYPE_NODE }, \ 149 { "decnet", CTLTYPE_NODE }, \ 150 { "dec_dli", CTLTYPE_NODE }, \ 151 { "lat", CTLTYPE_NODE }, \ 152 { "hylink", CTLTYPE_NODE }, \ 153 { "appletalk", CTLTYPE_NODE }, \ 154 { "route", CTLTYPE_NODE }, \ 155 { "link_layer", CTLTYPE_NODE }, \ 156 { "xtp", CTLTYPE_NODE }, \ 157 { "coip", CTLTYPE_NODE }, \ 158 { "cnt", CTLTYPE_NODE }, \ 159 { "rtip", CTLTYPE_NODE }, \ 160 { "ipx", CTLTYPE_NODE }, \ 161 { "inet6", CTLTYPE_NODE }, \ 162 { "pip", CTLTYPE_NODE }, \ 163 { "isdn", CTLTYPE_NODE }, \ 164 { "natm", CTLTYPE_NODE }, \ 165 { "encap", CTLTYPE_NODE }, \ 166 { "sip", CTLTYPE_NODE }, \ 167 { "key", CTLTYPE_NODE }, \ 168 } 169 170 /* 171 * PF_ROUTE - Routing table 172 * 173 * Three additional levels are defined: 174 * Fourth: address family, 0 is wildcard 175 * Fifth: type of info, defined below 176 * Sixth: flag(s) to mask with for NET_RT_FLAGS 177 */ 178 #define NET_RT_DUMP 1 /* dump; may limit to a.f. */ 179 #define NET_RT_FLAGS 2 /* by flags, e.g. RESOLVING */ 180 #define NET_RT_IFLIST 3 /* survey interface list */ 181 #define NET_RT_MAXID 4 182 183 #define CTL_NET_RT_NAMES { \ 184 { 0, 0 }, \ 185 { "dump", CTLTYPE_STRUCT }, \ 186 { "flags", CTLTYPE_STRUCT }, \ 187 { "iflist", CTLTYPE_STRUCT }, \ 188 } 189 190 /* Max listen queue for a socket */ 191 #define SOMAXCONN 5 /* defined as 128 in OpenBSD */ 192 193 struct msghdr { 194 char * msg_name; /* address we're using (optional) */ 195 uint msg_namelen; /* length of address */ 196 struct iovec *msg_iov; /* scatter/gather array we'll use */ 197 uint msg_iovlen; /* # elements in msg_iov */ 198 char * msg_control; /* extra data */ 199 uint msg_controllen; /* length of extra data */ 200 int msg_flags; /* flags */ 201 }; 202 203 /* Defines used in msghdr structure. */ 204 #define MSG_OOB 0x1 /* process out-of-band data */ 205 #define MSG_PEEK 0x2 /* peek at incoming message */ 206 #define MSG_DONTROUTE 0x4 /* send without using routing tables */ 207 #define MSG_EOR 0x8 /* data completes record */ 208 #define MSG_TRUNC 0x10 /* data discarded before delivery */ 209 #define MSG_CTRUNC 0x20 /* control data lost before delivery */ 210 #define MSG_WAITALL 0x40 /* wait for full request or error */ 211 #define MSG_DONTWAIT 0x80 /* this message should be nonblocking */ 212 #define MSG_BCAST 0x100 /* this message rec'd as broadcast */ 213 #define MSG_MCAST 0x200 /* this message rec'd as multicast */ 214 /* not defind in OpenBeOS */ 215 #define MSG_EOF 0x400 /* data completes connection */ 216 217 218 struct cmsghdr { 219 uint cmsg_len; 220 int cmsg_level; 221 int cmsg_type; 222 /* there now follows uchar[] cmsg_data */ 223 }; 224 225 226 #define SIOCSHIWAT _IOW('s', 0, int) /* set high watermark */ 227 #define SIOCGHIWAT _IOR('s', 1, int) /* get high watermark */ 228 #define SIOCSLOWAT _IOW('s', 2, int) /* set low watermark */ 229 #define SIOCGLOWAT _IOR('s', 3, int) /* get low watermark */ 230 #define SIOCATMARK _IOR('s', 7, int) /* at oob mark? */ 231 232 #define SIOCADDRT _IOW('r', 10, struct ortentry) /* add route */ 233 #define SIOCDELRT _IOW('r', 11, struct ortentry) /* delete route */ 234 235 #define SIOCSIFADDR _IOW('i', 12, struct ifreq) /* set ifnet address */ 236 #define OSIOCGIFADDR _IOWR('i', 13, struct ifreq) /* get ifnet address */ 237 #define SIOCGIFADDR _IOWR('i', 33, struct ifreq) /* get ifnet address */ 238 #define SIOCSIFDSTADDR _IOW('i', 14, struct ifreq) /* set p-p address */ 239 #define OSIOCGIFDSTADDR _IOWR('i', 15, struct ifreq) /* get p-p address */ 240 #define SIOCGIFDSTADDR _IOWR('i', 34, struct ifreq) /* get p-p address */ 241 #define SIOCSIFFLAGS _IOW('i', 16, struct ifreq) /* set ifnet flags */ 242 #define SIOCGIFFLAGS _IOWR('i', 17, struct ifreq) /* get ifnet flags */ 243 #define OSIOCGIFBRDADDR _IOWR('i', 18, struct ifreq) /* get broadcast addr */ 244 #define SIOCGIFBRDADDR _IOWR('i', 35, struct ifreq) /* get broadcast addr */ 245 #define SIOCSIFBRDADDR _IOW('i', 19, struct ifreq) /* set broadcast addr */ 246 #define OSIOCGIFCONF _IOWR('i', 20, struct ifconf) /* get ifnet list */ 247 #define SIOCGIFCONF _IOWR('i', 36, struct ifconf) /* get ifnet list */ 248 #define OSIOCGIFNETMASK _IOWR('i', 21, struct ifreq) /* get net addr mask */ 249 #define SIOCGIFNETMASK _IOWR('i', 37, struct ifreq) /* get net addr mask */ 250 #define SIOCSIFNETMASK _IOW('i', 22, struct ifreq) /* set net addr mask */ 251 #define SIOCGIFMETRIC _IOWR('i', 23, struct ifreq) /* get IF metric */ 252 #define SIOCSIFMETRIC _IOW('i', 24, struct ifreq) /* set IF metric */ 253 #define SIOCDIFADDR _IOW('i', 25, struct ifreq) /* delete IF addr */ 254 #define SIOCAIFADDR _IOW('i', 26, struct ifaliasreq)/* add/chg IF alias */ 255 #define SIOCGIFDATA _IOWR('i', 27, struct ifreq) /* get if_data */ 256 257 #define SIOCGIFMTU _IOWR('i', 126, struct ifreq) /* get ifnet MTU */ 258 #define SIOCSIFMTU _IOW('i', 127, struct ifreq) /* set ifnet MTU */ 259 260 #define SIOCADDMULTI _IOW('i', 49, struct ifreq) /* add m'cast addr */ 261 #define SIOCDELMULTI _IOW('i', 50, struct ifreq) /* del m'cast addr */ 262 263 264 #ifndef _KERNEL_MODE 265 /* Function declarations */ 266 int socket (int, int, int); 267 int bind(int, const struct sockaddr *, int); 268 int connect(int, const struct sockaddr *, int); 269 int listen(int, int); 270 int accept(int, struct sockaddr *, int *); 271 int closesocket(int); 272 int shutdown(int sock, int how); 273 274 ssize_t send(int, const void *, size_t, int); 275 ssize_t recv(int, void *, size_t, int); 276 ssize_t sendto(int, const void *, size_t, int, const struct sockaddr *, size_t); 277 ssize_t recvfrom(int, void *, size_t, int, struct sockaddr *, size_t *); 278 279 int setsockopt(int, int, int, const void *, size_t); 280 int getsockopt(int, int, int, void *, size_t *); 281 int getpeername(int, struct sockaddr *, int *); 282 int getsockname(int, struct sockaddr *, int *); 283 #endif /* _KERNEL_MODE */ 284 285 #if __cplusplus 286 } 287 #endif /* __cplusplus */ 288 289 #endif /* _SYS_SOCKET_H */ 290 291