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 #ifndef BUILDING_R5_LIBNET 101 #define SHUTDOWN_RECV 0 102 #define SHUTDOWN_SEND 1 103 #define SHUTDOWN_BOTH 2 104 #else // BUILDING_R5_LIBNET 105 #define SHUT_RD 1 106 #define SHUT_WR 2 107 #define SHUT_RDWR 3 108 #endif // BUILDING_R5_LIBNET 109 110 111 struct linger { 112 int l_onoff; 113 int l_linger; 114 }; 115 116 struct sockaddr { 117 uint8_t sa_len; 118 uint8_t sa_family; 119 uint8_t sa_data[30]; 120 }; 121 122 /* this can hold ANY sockaddr we care to throw at it! */ 123 struct sockaddr_storage { 124 uint8_t ss_len; /* total length */ 125 uint8_t ss_family; /* address family */ 126 uint8_t __ss_pad1[6]; /* align to quad */ 127 uint64_t __ss_pad2; /* force alignment for stupid compilers */ 128 uint8_t __ss_pad3[240]; /* pad to a total of 256 bytes */ 129 }; 130 131 struct sockproto { 132 uint16_t sp_family; 133 uint16_t sp_protocol; 134 }; 135 136 #define CTL_NET 4 137 138 #define CTL_NET_NAMES { \ 139 { 0, 0 }, \ 140 { "unix", CTLTYPE_NODE }, \ 141 { "inet", CTLTYPE_NODE }, \ 142 { "implink", CTLTYPE_NODE }, \ 143 { "pup", CTLTYPE_NODE }, \ 144 { "chaos", CTLTYPE_NODE }, \ 145 { "xerox_ns", CTLTYPE_NODE }, \ 146 { "iso", CTLTYPE_NODE }, \ 147 { "emca", CTLTYPE_NODE }, \ 148 { "datakit", CTLTYPE_NODE }, \ 149 { "ccitt", CTLTYPE_NODE }, \ 150 { "ibm_sna", CTLTYPE_NODE }, \ 151 { "decnet", CTLTYPE_NODE }, \ 152 { "dec_dli", CTLTYPE_NODE }, \ 153 { "lat", CTLTYPE_NODE }, \ 154 { "hylink", CTLTYPE_NODE }, \ 155 { "appletalk", CTLTYPE_NODE }, \ 156 { "route", CTLTYPE_NODE }, \ 157 { "link_layer", CTLTYPE_NODE }, \ 158 { "xtp", CTLTYPE_NODE }, \ 159 { "coip", CTLTYPE_NODE }, \ 160 { "cnt", CTLTYPE_NODE }, \ 161 { "rtip", CTLTYPE_NODE }, \ 162 { "ipx", CTLTYPE_NODE }, \ 163 { "inet6", CTLTYPE_NODE }, \ 164 { "pip", CTLTYPE_NODE }, \ 165 { "isdn", CTLTYPE_NODE }, \ 166 { "natm", CTLTYPE_NODE }, \ 167 { "encap", CTLTYPE_NODE }, \ 168 { "sip", CTLTYPE_NODE }, \ 169 { "key", CTLTYPE_NODE }, \ 170 } 171 172 /* 173 * PF_ROUTE - Routing table 174 * 175 * Three additional levels are defined: 176 * Fourth: address family, 0 is wildcard 177 * Fifth: type of info, defined below 178 * Sixth: flag(s) to mask with for NET_RT_FLAGS 179 */ 180 #define NET_RT_DUMP 1 /* dump; may limit to a.f. */ 181 #define NET_RT_FLAGS 2 /* by flags, e.g. RESOLVING */ 182 #define NET_RT_IFLIST 3 /* survey interface list */ 183 #define NET_RT_MAXID 4 184 185 #define CTL_NET_RT_NAMES { \ 186 { 0, 0 }, \ 187 { "dump", CTLTYPE_STRUCT }, \ 188 { "flags", CTLTYPE_STRUCT }, \ 189 { "iflist", CTLTYPE_STRUCT }, \ 190 } 191 192 /* Max listen queue for a socket */ 193 #define SOMAXCONN 5 /* defined as 128 in OpenBSD */ 194 195 struct msghdr { 196 char * msg_name; /* address we're using (optional) */ 197 uint msg_namelen; /* length of address */ 198 struct iovec *msg_iov; /* scatter/gather array we'll use */ 199 uint msg_iovlen; /* # elements in msg_iov */ 200 char * msg_control; /* extra data */ 201 uint msg_controllen; /* length of extra data */ 202 int msg_flags; /* flags */ 203 }; 204 205 /* Defines used in msghdr structure. */ 206 #define MSG_OOB 0x1 /* process out-of-band data */ 207 #define MSG_PEEK 0x2 /* peek at incoming message */ 208 #define MSG_DONTROUTE 0x4 /* send without using routing tables */ 209 #define MSG_EOR 0x8 /* data completes record */ 210 #define MSG_TRUNC 0x10 /* data discarded before delivery */ 211 #define MSG_CTRUNC 0x20 /* control data lost before delivery */ 212 #define MSG_WAITALL 0x40 /* wait for full request or error */ 213 #define MSG_DONTWAIT 0x80 /* this message should be nonblocking */ 214 #define MSG_BCAST 0x100 /* this message rec'd as broadcast */ 215 #define MSG_MCAST 0x200 /* this message rec'd as multicast */ 216 /* not defind in OpenBeOS */ 217 #define MSG_EOF 0x400 /* data completes connection */ 218 219 220 struct cmsghdr { 221 uint cmsg_len; 222 int cmsg_level; 223 int cmsg_type; 224 /* there now follows uchar[] cmsg_data */ 225 }; 226 227 228 #define SIOCSHIWAT _IOW('s', 0, int) /* set high watermark */ 229 #define SIOCGHIWAT _IOR('s', 1, int) /* get high watermark */ 230 #define SIOCSLOWAT _IOW('s', 2, int) /* set low watermark */ 231 #define SIOCGLOWAT _IOR('s', 3, int) /* get low watermark */ 232 #define SIOCATMARK _IOR('s', 7, int) /* at oob mark? */ 233 234 #define SIOCADDRT _IOW('r', 10, struct ortentry) /* add route */ 235 #define SIOCDELRT _IOW('r', 11, struct ortentry) /* delete route */ 236 237 #define SIOCSIFADDR _IOW('i', 12, struct ifreq) /* set ifnet address */ 238 #define OSIOCGIFADDR _IOWR('i', 13, struct ifreq) /* get ifnet address */ 239 #define SIOCGIFADDR _IOWR('i', 33, struct ifreq) /* get ifnet address */ 240 #define SIOCSIFDSTADDR _IOW('i', 14, struct ifreq) /* set p-p address */ 241 #define OSIOCGIFDSTADDR _IOWR('i', 15, struct ifreq) /* get p-p address */ 242 #define SIOCGIFDSTADDR _IOWR('i', 34, struct ifreq) /* get p-p address */ 243 #define SIOCSIFFLAGS _IOW('i', 16, struct ifreq) /* set ifnet flags */ 244 #define SIOCGIFFLAGS _IOWR('i', 17, struct ifreq) /* get ifnet flags */ 245 #define OSIOCGIFBRDADDR _IOWR('i', 18, struct ifreq) /* get broadcast addr */ 246 #define SIOCGIFBRDADDR _IOWR('i', 35, struct ifreq) /* get broadcast addr */ 247 #define SIOCSIFBRDADDR _IOW('i', 19, struct ifreq) /* set broadcast addr */ 248 #define OSIOCGIFCONF _IOWR('i', 20, struct ifconf) /* get ifnet list */ 249 #define SIOCGIFCONF _IOWR('i', 36, struct ifconf) /* get ifnet list */ 250 #define OSIOCGIFNETMASK _IOWR('i', 21, struct ifreq) /* get net addr mask */ 251 #define SIOCGIFNETMASK _IOWR('i', 37, struct ifreq) /* get net addr mask */ 252 #define SIOCSIFNETMASK _IOW('i', 22, struct ifreq) /* set net addr mask */ 253 #define SIOCGIFMETRIC _IOWR('i', 23, struct ifreq) /* get IF metric */ 254 #define SIOCSIFMETRIC _IOW('i', 24, struct ifreq) /* set IF metric */ 255 #define SIOCDIFADDR _IOW('i', 25, struct ifreq) /* delete IF addr */ 256 #define SIOCAIFADDR _IOW('i', 26, struct ifaliasreq)/* add/chg IF alias */ 257 #define SIOCGIFDATA _IOWR('i', 27, struct ifreq) /* get if_data */ 258 259 #define SIOCGIFMTU _IOWR('i', 126, struct ifreq) /* get ifnet MTU */ 260 #define SIOCSIFMTU _IOW('i', 127, struct ifreq) /* set ifnet MTU */ 261 262 #define SIOCADDMULTI _IOW('i', 49, struct ifreq) /* add m'cast addr */ 263 #define SIOCDELMULTI _IOW('i', 50, struct ifreq) /* del m'cast addr */ 264 265 266 #ifndef _KERNEL_MODE 267 /* Function declarations */ 268 int socket (int, int, int); 269 int bind(int, const struct sockaddr *, int); 270 int connect(int, const struct sockaddr *, int); 271 int listen(int, int); 272 int accept(int, struct sockaddr *, int *); 273 int closesocket(int); 274 int shutdown(int sock, int how); 275 276 ssize_t send(int, const void *, size_t, int); 277 ssize_t recv(int, void *, size_t, int); 278 ssize_t sendto(int, const void *, size_t, int, const struct sockaddr *, size_t); 279 ssize_t recvfrom(int, void *, size_t, int, struct sockaddr *, size_t *); 280 281 int setsockopt(int, int, int, const void *, size_t); 282 int getsockopt(int, int, int, void *, size_t *); 283 int getpeername(int, struct sockaddr *, int *); 284 int getsockname(int, struct sockaddr *, int *); 285 #endif /* _KERNEL_MODE */ 286 287 #if __cplusplus 288 } 289 #endif /* __cplusplus */ 290 291 #endif /* _SYS_SOCKET_H */ 292 293