| 1 |
/**************************************************************************/ |
| 2 |
/* */ |
| 3 |
/* This file is part of Frama-C. */ |
| 4 |
/* */ |
| 5 |
/* Copyright (C) 2007-2022 */ |
| 6 |
/* CEA (Commissariat à l'énergie atomique et aux énergies */ |
| 7 |
/* alternatives) */ |
| 8 |
/* */ |
| 9 |
/* you can redistribute it and/or modify it under the terms of the GNU */ |
| 10 |
/* Lesser General Public License as published by the Free Software */ |
| 11 |
/* Foundation, version 2.1. */ |
| 12 |
/* */ |
| 13 |
/* It is distributed in the hope that it will be useful, */ |
| 14 |
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ |
| 15 |
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ |
| 16 |
/* GNU Lesser General Public License for more details. */ |
| 17 |
/* */ |
| 18 |
/* See the GNU Lesser General Public License version 2.1 */ |
| 19 |
/* for more details (enclosed in the file licenses/LGPLv2.1). */ |
| 20 |
/* */ |
| 21 |
/**************************************************************************/ |
| 22 |
|
| 23 |
#ifndef __FC_SOCKET_H__ |
| 24 |
#define __FC_SOCKET_H__ |
| 25 |
#include "../features.h" |
| 26 |
__PUSH_FC_STDLIB |
| 27 |
__BEGIN_DECLS |
| 28 |
#include "../__fc_machdep.h" |
| 29 |
|
| 30 |
#include "../errno.h" |
| 31 |
|
| 32 |
// Note: most constants used here are based on Linux, independently of the |
| 33 |
// chosen machdep. If using other OSs (e.g. MacOS), consider redefining them. |
| 34 |
|
| 35 |
#ifndef __socklen_t_defined |
| 36 |
typedef __UINT_LEAST32_T socklen_t; |
| 37 |
#define __socklen_t_defined |
| 38 |
#endif |
| 39 |
#include "../__fc_define_sa_family_t.h" |
| 40 |
#include "../__fc_define_sockaddr.h" |
| 41 |
/* Not POSIX compliant but seems needed for some functions... */ |
| 42 |
#include "../__fc_define_ssize_t.h" |
| 43 |
#include "../features.h" |
| 44 |
|
| 45 |
struct sockaddr_storage { |
| 46 |
sa_family_t ss_family; |
| 47 |
}; |
| 48 |
|
| 49 |
#include "./uio.h" |
| 50 |
|
| 51 |
struct cmsghdr { |
| 52 |
socklen_t cmsg_len; |
| 53 |
int cmsg_level; |
| 54 |
int cmsg_type; |
| 55 |
}; |
| 56 |
|
| 57 |
#define SCM_RIGHTS 0 |
| 58 |
|
| 59 |
struct msghdr { |
| 60 |
void *msg_name; |
| 61 |
socklen_t msg_namelen; |
| 62 |
struct iovec *msg_iov; |
| 63 |
int msg_iovlen; |
| 64 |
void *msg_control; |
| 65 |
socklen_t msg_controllen; |
| 66 |
int msg_flags; |
| 67 |
}; |
| 68 |
|
| 69 |
// POSIX.1-2008 requires these to be defined as macros, but we have no body |
| 70 |
// for them, so we declare them as prototypes as well. |
| 71 |
#ifndef CMSG_FIRSTHDR |
| 72 |
extern struct cmsghdr *CMSG_FIRSTHDR(struct msghdr *msgh); |
| 73 |
# define CMSG_FIRSTHDR(h) CMSG_FIRSTHDR(h) |
| 74 |
#endif |
| 75 |
#ifndef CMSG_NXTHDR |
| 76 |
extern struct cmsghdr *CMSG_NXTHDR(struct msghdr *msgh, struct cmsghdr *cmsg); |
| 77 |
# define CMSG_NXTHDR(h, c) CMSG_NXTHDR(h, c) |
| 78 |
#endif |
| 79 |
#ifndef CMSG_ALIGN |
| 80 |
extern size_t CMSG_ALIGN(size_t length); |
| 81 |
# define CMSG_ALIGN(l) CMSG_ALIGN(l) |
| 82 |
#endif |
| 83 |
#ifndef CMSG_SPACE |
| 84 |
extern size_t CMSG_SPACE(size_t length); |
| 85 |
# define CMSG_SPACE(l) CMSG_SPACE(l) |
| 86 |
#endif |
| 87 |
#ifndef CMSG_LEN |
| 88 |
extern size_t CMSG_LEN(size_t length); |
| 89 |
# define CMSG_LEN(l) CMSG_LEN(l) |
| 90 |
#endif |
| 91 |
#ifndef CMSG_DATA |
| 92 |
extern unsigned char *CMSG_DATA(struct cmsghdr *cmsg); |
| 93 |
# define CMSG_DATA(c) CMSG_DATA(c) |
| 94 |
#endif |
| 95 |
|
| 96 |
/* Socket types. */ |
| 97 |
#define SOCK_STREAM 1 /* stream (connection) socket */ |
| 98 |
#define SOCK_DGRAM 2 /* datagram (conn.less) socket */ |
| 99 |
#define SOCK_RAW 3 /* raw socket */ |
| 100 |
#define SOCK_RDM 4 /* reliably-delivered message */ |
| 101 |
#define SOCK_SEQPACKET 5 /* sequential packet socket */ |
| 102 |
|
| 103 |
/* Protocol families (not described by POSIX) */ |
| 104 |
#define PF_UNSPEC 0 |
| 105 |
#define PF_LOCAL 1 |
| 106 |
#define PF_UNIX PF_LOCAL |
| 107 |
#define PF_FILE PF_LOCAL |
| 108 |
#define PF_INET 2 |
| 109 |
#define PF_AX25 3 |
| 110 |
#define PF_IPX 4 |
| 111 |
#define PF_APPLETALK 5 |
| 112 |
#define PF_NETROM 6 |
| 113 |
#define PF_BRIDGE 7 |
| 114 |
#define PF_ATMPVC 8 |
| 115 |
#define PF_X25 9 |
| 116 |
#define PF_INET6 10 |
| 117 |
#define PF_ROSE 11 |
| 118 |
#define PF_DECnet 12 |
| 119 |
#define PF_NETBEUI 13 |
| 120 |
#define PF_SECURITY 14 |
| 121 |
#define PF_KEY 15 |
| 122 |
#define PF_NETLINK 16 |
| 123 |
#define PF_ROUTE PF_NETLINK |
| 124 |
#define PF_PACKET 17 |
| 125 |
#define PF_ASH 18 |
| 126 |
#define PF_ECONET 19 |
| 127 |
#define PF_ATMSVC 20 |
| 128 |
#define PF_RDS 21 |
| 129 |
#define PF_SNA 22 |
| 130 |
#define PF_IRDA 23 |
| 131 |
#define PF_PPPOX 24 |
| 132 |
#define PF_WANPIPE 25 |
| 133 |
#define PF_LLC 26 |
| 134 |
#define PF_IB 27 |
| 135 |
#define PF_MPLS 28 |
| 136 |
#define PF_CAN 29 |
| 137 |
#define PF_TIPC 30 |
| 138 |
#define PF_BLUETOOTH 31 |
| 139 |
#define PF_IUCV 32 |
| 140 |
#define PF_RXRPC 33 |
| 141 |
#define PF_ISDN 34 |
| 142 |
#define PF_PHONET 35 |
| 143 |
#define PF_IEEE802154 36 |
| 144 |
#define PF_CAIF 37 |
| 145 |
#define PF_ALG 38 |
| 146 |
#define PF_NFC 39 |
| 147 |
#define PF_VSOCK 40 |
| 148 |
#define PF_KCM 41 |
| 149 |
#define PF_QIPCRTR 42 |
| 150 |
#define PF_MAX 43 |
| 151 |
|
| 152 |
/* Address families (only AF_INET, AF_INET6, AF_UNIX and AF_UNSPEC are |
| 153 |
described in POSIX; AF_INET6 is optional) */ |
| 154 |
#define AF_UNSPEC 0 |
| 155 |
#define AF_LOCAL PF_LOCAL |
| 156 |
#define AF_UNIX PF_UNIX |
| 157 |
#define AF_FILE PF_FILE |
| 158 |
#define AF_INET PF_INET |
| 159 |
#define AF_AX25 PF_AX25 |
| 160 |
#define AF_IPX PF_IPX |
| 161 |
#define AF_APPLETALK PF_APPLETALK |
| 162 |
#define AF_NETROM PF_NETROM |
| 163 |
#define AF_BRIDGE PF_BRIDGE |
| 164 |
#define AF_ATMPVC PF_ATMPVC |
| 165 |
#define AF_X25 PF_X25 |
| 166 |
#define AF_INET6 PF_INET6 |
| 167 |
#define AF_ROSE PF_ROSE |
| 168 |
#define AF_DECnet PF_DECnet |
| 169 |
#define AF_NETBEUI PF_NETBEUI |
| 170 |
#define AF_SECURITY PF_SECURITY |
| 171 |
#define AF_KEY PF_KEY |
| 172 |
#define AF_NETLINK PF_NETLINK |
| 173 |
#define AF_ROUTE PF_ROUTE |
| 174 |
#define AF_PACKET PF_PACKET |
| 175 |
#define AF_ASH PF_ASH |
| 176 |
#define AF_ECONET PF_ECONET |
| 177 |
#define AF_ATMSVC PF_ATMSVC |
| 178 |
#define AF_RDS PF_RDS |
| 179 |
#define AF_SNA PF_SNA |
| 180 |
#define AF_IRDA PF_IRDA |
| 181 |
#define AF_PPPOX PF_PPPOX |
| 182 |
#define AF_WANPIPE PF_WANPIPE |
| 183 |
#define AF_LLC PF_LLC |
| 184 |
#define AF_IB PF_IB |
| 185 |
#define AF_MPLS PF_MPLS |
| 186 |
#define AF_CAN PF_CAN |
| 187 |
#define AF_TIPC PF_TIPC |
| 188 |
#define AF_BLUETOOTH PF_BLUETOOTH |
| 189 |
#define AF_IUCV PF_IUCV |
| 190 |
#define AF_RXRPC PF_RXRPC |
| 191 |
#define AF_ISDN PF_ISDN |
| 192 |
#define AF_PHONET PF_PHONET |
| 193 |
#define AF_IEEE802154 PF_IEEE802154 |
| 194 |
#define AF_CAIF PF_CAIF |
| 195 |
#define AF_ALG PF_ALG |
| 196 |
#define AF_NFC PF_NFC |
| 197 |
#define AF_VSOCK PF_VSOCK |
| 198 |
#define AF_KCM PF_KCM |
| 199 |
#define AF_QIPCRTR PF_QIPCRTR |
| 200 |
#define AF_MAX PF_MAX |
| 201 |
|
| 202 |
#define SOL_SOCKET 1 |
| 203 |
|
| 204 |
#define SO_DEBUG 1 |
| 205 |
#define SO_REUSEADDR 2 |
| 206 |
#define SO_TYPE 3 |
| 207 |
#define SO_ERROR 4 |
| 208 |
#define SO_DONTROUTE 5 |
| 209 |
#define SO_BROADCAST 6 |
| 210 |
#define SO_SNDBUF 7 |
| 211 |
#define SO_RCVBUF 8 |
| 212 |
#define SO_SNDBUFFORCE 32 |
| 213 |
#define SO_RCVBUFFORCE 33 |
| 214 |
#define SO_KEEPALIVE 9 |
| 215 |
#define SO_OOBINLINE 10 |
| 216 |
#define SO_NO_CHECK 11 |
| 217 |
#define SO_PRIORITY 12 |
| 218 |
#define SO_LINGER 13 |
| 219 |
#define SO_BSDCOMPAT 14 |
| 220 |
#define SO_REUSEPORT 15 |
| 221 |
#define SO_PASSCRED 16 |
| 222 |
#define SO_PEERCRED 17 |
| 223 |
#define SO_RCVLOWAT 18 |
| 224 |
#define SO_SNDLOWAT 19 |
| 225 |
#define SO_RCVTIMEO 20 |
| 226 |
#define SO_SNDTIMEO 21 |
| 227 |
#define SO_SECURITY_AUTHENTICATION 22 |
| 228 |
#define SO_SECURITY_ENCRYPTION_TRANSPORT 23 |
| 229 |
#define SO_SECURITY_ENCRYPTION_NETWORK 24 |
| 230 |
#define SO_BINDTODEVICE 25 |
| 231 |
#define SO_ATTACH_FILTER 26 |
| 232 |
#define SO_DETACH_FILTER 27 |
| 233 |
#define SO_GET_FILTER SO_ATTACH_FILTER |
| 234 |
#define SO_PEERNAME 28 |
| 235 |
#define SO_TIMESTAMP 29 |
| 236 |
#define SCM_TIMESTAMP SO_TIMESTAMP |
| 237 |
#define SO_ACCEPTCONN 30 |
| 238 |
#define SO_PEERSEC 31 |
| 239 |
#define SO_PASSSEC 34 |
| 240 |
#define SO_TIMESTAMPNS 35 |
| 241 |
#define SCM_TIMESTAMPNS SO_TIMESTAMPNS |
| 242 |
#define SO_MARK 36 |
| 243 |
#define SO_TIMESTAMPING 37 |
| 244 |
#define SCM_TIMESTAMPING SO_TIMESTAMPING |
| 245 |
#define SO_PROTOCOL 38 |
| 246 |
#define SO_DOMAIN 39 |
| 247 |
#define SO_RXQ_OVFL 40 |
| 248 |
#define SO_WIFI_STATUS 41 |
| 249 |
#define SCM_WIFI_STATUS SO_WIFI_STATUS |
| 250 |
#define SO_PEEK_OFF 42 |
| 251 |
#define SO_NOFCS 43 |
| 252 |
#define SO_LOCK_FILTER 44 |
| 253 |
#define SO_SELECT_ERR_QUEUE 45 |
| 254 |
#define SO_BUSY_POLL 46 |
| 255 |
#define SO_MAX_PACING_RATE 47 |
| 256 |
#define SO_BPF_EXTENSIONS 48 |
| 257 |
#define SO_INCOMING_CPU 49 |
| 258 |
#define SO_ATTACH_BPF 50 |
| 259 |
#define SO_DETACH_BPF SO_DETACH_FILTER |
| 260 |
#define SO_ATTACH_REUSEPORT_CBPF 51 |
| 261 |
#define SO_ATTACH_REUSEPORT_EBPF 52 |
| 262 |
#define SO_CNX_ADVICE 53 |
| 263 |
#define SCM_TIMESTAMPING_OPT_STATS 54 |
| 264 |
#define SO_MEMINFO 55 |
| 265 |
#define SO_INCOMING_NAPI_ID 56 |
| 266 |
#define SO_COOKIE 57 |
| 267 |
#define SCM_TIMESTAMPING_PKTINFO 58 |
| 268 |
#define SO_PEERGROUPS 59 |
| 269 |
|
| 270 |
#define SOMAXCONN 128 |
| 271 |
|
| 272 |
enum __fc_shutdown { |
| 273 |
SHUT_RD, |
| 274 |
SHUT_WR, |
| 275 |
SHUT_RDWR |
| 276 |
}; |
| 277 |
// POSIX requires these SHUT_* constants to be defined as macros |
| 278 |
#define SHUT_RD SHUT_RD |
| 279 |
#define SHUT_WR SHUT_WR |
| 280 |
#define SHUT_RDWR SHUT_RDWR |
| 281 |
|
| 282 |
#ifndef __FC_MAX_OPEN_SOCKETS |
| 283 |
// arbitrary number |
| 284 |
#define __FC_MAX_OPEN_SOCKETS 1024 |
| 285 |
#endif |
| 286 |
|
| 287 |
// Allows different implementations for internal socket structures |
| 288 |
#ifndef __FC_INTERNAL_SOCKFDS_PROVIDED |
| 289 |
struct __fc_sockfds_type { int x; }; |
| 290 |
#endif |
| 291 |
//@ ghost struct __fc_sockfds_type __fc_sockfds[__FC_MAX_OPEN_SOCKETS]; |
| 292 |
|
| 293 |
/* Represents the creation of new file descriptors for sockets. */ |
| 294 |
//@ ghost extern int __fc_socket_counter; |
| 295 |
|
| 296 |
// __fc_sockfds represents the state of open socket descriptors. |
| 297 |
//@ ghost volatile int __fc_open_sock_fds; |
| 298 |
// TODO: Model the state of some functions more precisely. |
| 299 |
|
| 300 |
/*@ |
| 301 |
requires valid_sockfd: 0 <= sockfd < __FC_MAX_OPEN_SOCKETS; |
| 302 |
assigns \result, *(((char *)addr)+(0 .. *addrlen-1)), __fc_sockfds[sockfd] |
| 303 |
\from *addr, *addrlen, __fc_sockfds[sockfd]; |
| 304 |
ensures result_error_or_valid_new_sockfd: |
| 305 |
\result == -1 || 0 <= \result < __FC_MAX_OPEN_SOCKETS; |
| 306 |
behavior addr_null: |
| 307 |
assumes addr_is_null: addr == \null; |
| 308 |
requires addrlen_should_be_null: addrlen == \null; |
| 309 |
assigns \result, __fc_sockfds[sockfd] \from __fc_sockfds[sockfd]; |
| 310 |
behavior addr_not_null: |
| 311 |
assumes addr_is_not_null: addr != \null; |
| 312 |
requires valid_addrlen: \valid(addrlen); |
| 313 |
requires addr_has_room: \valid(((char *)addr)+(0 .. *addrlen-1)); |
| 314 |
ensures initialization:addr: \initialized(((char *)addr)+(0..*addrlen-1)); |
| 315 |
disjoint behaviors; |
| 316 |
// TODO: check what to do when the buffer addr is too small |
| 317 |
*/ |
| 318 |
extern int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen); |
| 319 |
|
| 320 |
/*@ |
| 321 |
requires valid_sockfd: sockfd: 0 <= sockfd < __FC_MAX_OPEN_SOCKETS; |
| 322 |
requires valid_read_addr: \valid_read(((char*)addr)+(0..addrlen-1)); |
| 323 |
assigns __fc_sockfds[sockfd] |
| 324 |
\from sockfd, *addr, addrlen, __fc_sockfds[sockfd]; |
| 325 |
assigns \result \from indirect:sockfd, indirect:*addr, indirect:addrlen, |
| 326 |
indirect:__fc_sockfds[sockfd]; |
| 327 |
ensures result_ok_or_error: \result == 0 || \result == -1; |
| 328 |
*/ |
| 329 |
extern int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen); |
| 330 |
|
| 331 |
/*@ |
| 332 |
// ideally, we should check whether addrlen is compatible with the kind of |
| 333 |
// socket of [sockfd] (created by calling socket()). |
| 334 |
requires valid_sockfd: 0 <= sockfd < __FC_MAX_OPEN_SOCKETS; |
| 335 |
requires valid_read_addr: \valid_read(((char*)addr)+(0 .. addrlen-1)); |
| 336 |
assigns __fc_sockfds[sockfd] |
| 337 |
\from __fc_sockfds[sockfd], indirect:sockfd, indirect:addr, |
| 338 |
indirect:*addr, indirect:addrlen; |
| 339 |
assigns \result |
| 340 |
\from indirect:__fc_sockfds[sockfd], indirect:sockfd, indirect:addr, |
| 341 |
indirect:*addr, indirect:addrlen; |
| 342 |
ensures result_ok_or_error: \result == 0 || \result == -1; |
| 343 |
*/ |
| 344 |
extern int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen); |
| 345 |
|
| 346 |
extern int getpeername(int, struct sockaddr *, socklen_t *); |
| 347 |
|
| 348 |
/*@ |
| 349 |
// missing: may assign to errno: EBADF, ENOTSOCK, EOPNOTSUPP, EINVAL, ENOBUFS |
| 350 |
requires valid_sockfd: 0 <= socket < __FC_MAX_OPEN_SOCKETS; |
| 351 |
requires valid_address_len: \valid(address_len); |
| 352 |
requires initialization:address_len: \initialized(address_len); |
| 353 |
requires valid_address: \valid(((char*)address)+(0 .. *address_len-1)); |
| 354 |
assigns *address_len \from indirect:socket, __fc_sockfds[socket]; |
| 355 |
assigns \result \from indirect:__fc_sockfds[socket], indirect:socket; |
| 356 |
assigns ((char*)address)[0 .. (*address_len)-1] \from |
| 357 |
indirect:__fc_sockfds[socket], indirect:socket; |
| 358 |
ensures new_address_len: *address_len <= \old(*address_len); |
| 359 |
ensures result_ok_or_error: \result == 0 || \result == -1; |
| 360 |
*/ |
| 361 |
extern int getsockname(int socket, struct sockaddr *restrict address, |
| 362 |
socklen_t *restrict address_len); |
| 363 |
|
| 364 |
// getsockopt is incrementally specified: options which are used more often |
| 365 |
// are gradually refined; the rest are handled by behavior "other_options". |
| 366 |
// Note: this specification may be more restrictive than what the manpage says, |
| 367 |
// to allow for a more precise analysis. It should however correspond to |
| 368 |
// expected usage. |
| 369 |
/*@ |
| 370 |
requires valid_sockfd: 0 <= sockfd < __FC_MAX_OPEN_SOCKETS; |
| 371 |
requires valid_optlen: \valid(optlen); |
| 372 |
assigns ((char*)optval)[0..], \result |
| 373 |
\from indirect:sockfd, indirect:level, indirect:optname, |
| 374 |
indirect:*optlen, indirect:optval, |
| 375 |
indirect:__fc_sockfds[sockfd]; |
| 376 |
assigns *optlen |
| 377 |
\from indirect:sockfd, indirect:level, indirect:optname, |
| 378 |
*optlen, indirect:optval, indirect:__fc_sockfds[sockfd]; |
| 379 |
ensures result_ok_or_error: \result == 0 || \result == -1; |
| 380 |
behavior so_error: |
| 381 |
assumes optname_is_error: level == SOL_SOCKET && optname == SO_ERROR; |
| 382 |
requires valid_optlen: \valid(optlen); |
| 383 |
requires optlen_value: *optlen == sizeof(int); |
| 384 |
requires valid_optval: \valid((int*)optval); |
| 385 |
assigns *(int*)optval, \result \from indirect:sockfd, indirect:optlen, |
| 386 |
indirect:__fc_sockfds[sockfd]; |
| 387 |
behavior other_options: |
| 388 |
assumes optname_not_error: !(level == SOL_SOCKET && optname == SO_ERROR); |
| 389 |
requires optval_null_or_valid: |
| 390 |
optval == \null || \valid(((char*)optval)+(0..)); |
| 391 |
assigns ((char*)optval)[0..], \result |
| 392 |
\from indirect:sockfd, indirect:level, indirect:optname, |
| 393 |
indirect:*optlen, indirect:optval, |
| 394 |
indirect:__fc_sockfds[sockfd]; |
| 395 |
assigns *optlen |
| 396 |
\from indirect:sockfd, indirect:level, indirect:optname, |
| 397 |
*optlen, indirect:optval, indirect:__fc_sockfds[sockfd]; |
| 398 |
disjoint behaviors; |
| 399 |
complete behaviors; |
| 400 |
*/ |
| 401 |
extern int getsockopt(int sockfd, int level, int optname, |
| 402 |
void *optval, socklen_t *optlen); |
| 403 |
|
| 404 |
/*@ |
| 405 |
requires valid_sockfd: 0 <= sockfd < __FC_MAX_OPEN_SOCKETS; |
| 406 |
assigns \result \from sockfd, __fc_sockfds[sockfd]; |
| 407 |
assigns __fc_sockfds[sockfd] \from sockfd, backlog, __fc_sockfds[sockfd]; |
| 408 |
ensures result_ok_or_error: \result == 0 || \result == -1; |
| 409 |
*/ |
| 410 |
extern int listen(int sockfd, int backlog); |
| 411 |
|
| 412 |
/* Flags for passing to recv() and others */ |
| 413 |
#define MSG_OOB 0x1 |
| 414 |
#define MSG_PEEK 0x2 |
| 415 |
#define MSG_DONTROUTE 0x4 |
| 416 |
#define MSG_CTRUNC 0x8 |
| 417 |
#define MSG_PROXY 0x10 |
| 418 |
#define MSG_TRUNC 0x20 |
| 419 |
#define MSG_DONTWAIT 0x40 |
| 420 |
#define MSG_EOR 0x80 |
| 421 |
#define MSG_WAITALL 0x100 |
| 422 |
#define MSG_FIN 0x200 |
| 423 |
#define MSG_SYN 0x400 |
| 424 |
#define MSG_CONFIRM 0x800 |
| 425 |
#define MSG_RST 0x1000 |
| 426 |
#define MSG_RSTERRQUEUE 0x2000 |
| 427 |
#define MSG_NOSIGNAL 0x4000 |
| 428 |
#define MSG_MORE 0x8000 |
| 429 |
#define MSG_WAITFORONE 0x10000 |
| 430 |
#define MSG_BATCH 0x40000 |
| 431 |
#define MSG_FASTOPEN 0x20000000 |
| 432 |
#define MSG_CMSG_CLOEXEC 0x40000000 |
| 433 |
|
| 434 |
|
| 435 |
/*@ |
| 436 |
requires valid_sockfd: 0 <= sockfd < __FC_MAX_OPEN_SOCKETS; |
| 437 |
requires valid_buffer_length: \valid((char *)buf+(0 .. len-1)); |
| 438 |
assigns *((char *)buf+(0 .. len-1)), __fc_sockfds[sockfd], \result |
| 439 |
\from sockfd, len, flags, __fc_sockfds[sockfd]; |
| 440 |
ensures result_error_or_received_length: |
| 441 |
\result == -1 || 0 <= \result <= len; |
| 442 |
ensures initialization: \initialized(((char *)buf+(0 .. \result-1))); |
| 443 |
*/ |
| 444 |
extern ssize_t recv(int sockfd, void * buf, size_t len, int flags); |
| 445 |
|
| 446 |
/*@ |
| 447 |
requires valid_sockfd: 0 <= sockfd < __FC_MAX_OPEN_SOCKETS; |
| 448 |
requires valid_buffer_length: \valid((char *)buf+(0 .. len-1)); |
| 449 |
requires valid_addrbuf_or_null:initialization: (\valid(addrbuf_len) && |
| 450 |
\initialized(addrbuf_len) && |
| 451 |
\valid((char *)addrbuf+(0 .. *addrbuf_len-1))) |
| 452 |
|| (addrbuf == \null && addrbuf_len == \null); |
| 453 |
assigns *((char *)buf+(0 .. len-1)), __fc_sockfds[sockfd], \result |
| 454 |
\from sockfd, len, flags, __fc_sockfds[sockfd]; |
| 455 |
assigns *addrbuf_len \from indirect:sockfd, indirect: len, |
| 456 |
indirect:flags, __fc_sockfds[sockfd]; |
| 457 |
assigns *((char *)addrbuf+(0 .. \old(*addrbuf_len)-1)) |
| 458 |
\from indirect:sockfd, indirect: len, |
| 459 |
indirect:flags, __fc_sockfds[sockfd]; |
| 460 |
ensures result_error_or_received_length: \result == -1 || 0 <= \result <= len; |
| 461 |
ensures initialization:buf: \initialized(((char *)buf+(0 .. \result-1))); |
| 462 |
ensures initialization:addrbuf: |
| 463 |
addrbuf != \null ==> |
| 464 |
\initialized(((char *)addrbuf+(0 .. \old(*addrbuf_len)-1))); |
| 465 |
*/ |
| 466 |
extern ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags, |
| 467 |
struct sockaddr *addrbuf, socklen_t *addrbuf_len); |
| 468 |
|
| 469 |
/*@ requires valid_sockfd: 0 <= sockfd < __FC_MAX_OPEN_SOCKETS; |
| 470 |
@ requires msg_control_has_room: |
| 471 |
@ \valid(&((char *)hdr->msg_control)[0..hdr->msg_controllen-1]); |
| 472 |
@ requires msg_iov_has_room: \valid(&(hdr->msg_iov[0..hdr->msg_iovlen-1])); |
| 473 |
@ requires msg_name_null_or_has_room: hdr->msg_name == \null |
| 474 |
@ || \valid(&((char *)hdr->msg_name)[0..hdr->msg_namelen-1]); |
| 475 |
@ assigns ((char *)hdr->msg_name)[0..hdr->msg_namelen-1] |
| 476 |
@ \from __fc_sockfds[sockfd]; |
| 477 |
@ assigns hdr->msg_namelen \from __fc_sockfds[sockfd]; |
| 478 |
@ assigns ((char *)hdr->msg_iov[0..hdr->msg_iovlen-1].iov_base)[0..] |
| 479 |
@ \from __fc_sockfds[sockfd]; |
| 480 |
@ assigns ((char *)hdr->msg_control)[0..hdr->msg_controllen-1] |
| 481 |
@ \from __fc_sockfds[sockfd]; |
| 482 |
@ assigns \result \from __fc_sockfds[sockfd]; |
| 483 |
@ assigns hdr->msg_controllen \from __fc_sockfds[sockfd]; |
| 484 |
@ assigns hdr->msg_flags \from __fc_sockfds[sockfd]; |
| 485 |
@ assigns __fc_sockfds[sockfd] \from __fc_sockfds[sockfd]; |
| 486 |
@ ensures result_error_or_received_length: |
| 487 |
@ \result == -1 || 0 <= \result <= hdr->msg_iovlen; |
| 488 |
*/ |
| 489 |
extern ssize_t recvmsg(int sockfd, struct msghdr *hdr, int flags); |
| 490 |
|
| 491 |
/*@ |
| 492 |
requires available_sockfd: 0 <= sockfd < __FC_MAX_OPEN_SOCKETS; |
| 493 |
requires buf_len_ok: \valid_read(((char*)buf)+(0 .. len - 1)); |
| 494 |
assigns errno |
| 495 |
\from indirect:sockfd, indirect:__fc_sockfds[sockfd], |
| 496 |
indirect:((char *)buf)[0..len], flags; |
| 497 |
assigns __fc_sockfds[sockfd] |
| 498 |
\from __fc_sockfds[sockfd], ((char *)buf)[0..len], flags; |
| 499 |
assigns \result |
| 500 |
\from indirect:sockfd, indirect:__fc_sockfds[sockfd], |
| 501 |
indirect:((char*)buf)[0..len], indirect:flags; |
| 502 |
ensures error_or_chars_sent: \result == -1 || 0 <= \result <= len; |
| 503 |
*/ |
| 504 |
extern ssize_t send(int sockfd, const void *buf, size_t len, int flags); |
| 505 |
|
| 506 |
/*@ |
| 507 |
requires available_sockfd: 0 <= sockfd < __FC_MAX_OPEN_SOCKETS; |
| 508 |
requires valid_message: \valid_read(message); |
| 509 |
requires valid_msg_iov: |
| 510 |
\valid_read(message->msg_iov+(0 .. message->msg_iovlen - 1)); |
| 511 |
assigns __fc_sockfds[sockfd] |
| 512 |
\from __fc_sockfds[sockfd], |
| 513 |
indirect:*message, |
| 514 |
indirect:message->msg_iov[0 .. message->msg_iovlen - 1], |
| 515 |
indirect:flags; |
| 516 |
assigns \result \from indirect:sockfd, indirect:__fc_sockfds[sockfd], |
| 517 |
indirect:*message, |
| 518 |
indirect:message->msg_iov[0 .. message->msg_iovlen - 1]; |
| 519 |
ensures error_or_chars_sent: \result == -1 || 0 <= \result; |
| 520 |
*/ |
| 521 |
extern ssize_t sendmsg(int sockfd, const struct msghdr *message, int flags); |
| 522 |
|
| 523 |
/*@ |
| 524 |
requires available_sockfd: 0 <= sockfd < __FC_MAX_OPEN_SOCKETS; |
| 525 |
requires buf_len_ok: \valid_read(((char*)buf)+(0 .. len - 1)); |
| 526 |
assigns errno |
| 527 |
\from indirect:sockfd, indirect:__fc_sockfds[sockfd], |
| 528 |
indirect:((char *)buf)[0..len], flags; |
| 529 |
assigns __fc_sockfds[sockfd] |
| 530 |
\from __fc_sockfds[sockfd], ((char *)buf)[0..len], flags; |
| 531 |
assigns \result |
| 532 |
\from indirect:sockfd, indirect:__fc_sockfds[sockfd], |
| 533 |
indirect:((char*)buf)[0..len], indirect:flags; |
| 534 |
ensures error_or_chars_sent: \result == -1 || 0 <= \result <= len; |
| 535 |
*/ |
| 536 |
extern ssize_t sendto(int sockfd, const void *buf, size_t len, int flags, |
| 537 |
const struct sockaddr *address, socklen_t address_len); |
| 538 |
|
| 539 |
/*@ |
| 540 |
requires valid_sockfd: 0 <= sockfd < __FC_MAX_OPEN_SOCKETS; |
| 541 |
requires optval_null_or_has_room: |
| 542 |
optval == \null || \valid_read(((char *)optval)+(0..optlen-1)); |
| 543 |
assigns \result, __fc_sockfds[sockfd] |
| 544 |
\from __fc_sockfds[sockfd], level, optname, |
| 545 |
((char *)optval)[0..optlen-1], optlen; |
| 546 |
ensures result_error_or_ok: \result == 0 || \result == -1; |
| 547 |
*/ |
| 548 |
extern int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen); |
| 549 |
|
| 550 |
/*@ |
| 551 |
requires valid_sockfd: 0 <= sockfd < __FC_MAX_OPEN_SOCKETS; |
| 552 |
assigns \result, __fc_sockfds[sockfd] \from how, __fc_sockfds[sockfd]; |
| 553 |
ensures result_error_or_ok: \result == 0 || \result == -1; |
| 554 |
*/ |
| 555 |
extern int shutdown(int sockfd, int how); |
| 556 |
|
| 557 |
extern int sockatmark(int); |
| 558 |
|
| 559 |
/*@ |
| 560 |
assigns \result \from indirect:domain, indirect:type, indirect:protocol, |
| 561 |
indirect:__fc_socket_counter; |
| 562 |
assigns __fc_socket_counter \from indirect:domain, indirect:type, |
| 563 |
indirect:protocol, __fc_socket_counter; |
| 564 |
ensures result_error_or_valid_new_sockfd: |
| 565 |
0 <= \result < __FC_MAX_OPEN_SOCKETS || \result == -1; |
| 566 |
*/ |
| 567 |
extern int socket(int domain, int type, int protocol); |
| 568 |
|
| 569 |
extern int sockatmark(int); |
| 570 |
|
| 571 |
/*@ requires valid_socket_sector: \valid(&sv[0..1]); |
| 572 |
@ assigns \result, __fc_socket_counter, sv[0..1] \from |
| 573 |
@ __fc_socket_counter; |
| 574 |
@ ensures result_error_or_ok: \result == 0 || \result == -1; |
| 575 |
@ ensures initialization:sv: \initialized(&sv[0..1]); |
| 576 |
@ ensures valid_new_sockfd:sv0: 0 <= sv[0] < __FC_MAX_OPEN_SOCKETS; |
| 577 |
@ ensures valid_new_sockfd:sv1: 0 <= sv[1] < __FC_MAX_OPEN_SOCKETS; |
| 578 |
@*/ |
| 579 |
extern int socketpair(int domain, int type, int protocol, int sv[2]); |
| 580 |
|
| 581 |
__END_DECLS |
| 582 |
__POP_FC_STDLIB |
| 583 |
#endif |