| 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 |
// This file regroups all definitions from these two files: |
| 24 |
// |
| 25 |
// - <arpa/inet.h> |
| 26 |
// |
| 27 |
// - <netinet/in.h> |
| 28 |
// |
| 29 |
// POSIX.1-2008 states that each of them may make the symbols of the other |
| 30 |
// visible, so we define them all here. |
| 31 |
|
| 32 |
#ifndef __FC_INET |
| 33 |
#define __FC_INET |
| 34 |
#include "features.h" |
| 35 |
__PUSH_FC_STDLIB |
| 36 |
#include "__fc_machdep.h" |
| 37 |
__BEGIN_DECLS |
| 38 |
|
| 39 |
#include "__fc_string_axiomatic.h" |
| 40 |
#include "__fc_define_pthread_types.h" |
| 41 |
#include "inttypes.h" |
| 42 |
#include "signal.h" |
| 43 |
#include "sys/socket.h" |
| 44 |
|
| 45 |
////////// DEFINITIONS BELOW WERE ORIGINALLY IN <netinet/in.h> |
| 46 |
|
| 47 |
typedef uint16_t in_port_t; |
| 48 |
typedef uint32_t in_addr_t; |
| 49 |
|
| 50 |
struct in_addr { |
| 51 |
in_addr_t s_addr; |
| 52 |
}; |
| 53 |
|
| 54 |
struct sockaddr_in { |
| 55 |
sa_family_t sin_family; |
| 56 |
in_port_t sin_port; |
| 57 |
struct in_addr sin_addr; |
| 58 |
}; |
| 59 |
|
| 60 |
struct in6_addr { |
| 61 |
uint8_t s6_addr[16]; |
| 62 |
}; |
| 63 |
|
| 64 |
struct sockaddr_in6 { |
| 65 |
sa_family_t sin6_family; |
| 66 |
in_port_t sin6_port; |
| 67 |
uint32_t sin6_flowinfo; |
| 68 |
struct in6_addr sin6_addr; |
| 69 |
uint32_t sin6_scope_id; |
| 70 |
}; |
| 71 |
|
| 72 |
#define INADDR_ANY 0 |
| 73 |
#define INADDR_BROADCAST 0XFFFFFFFFUL |
| 74 |
#define INET_ADDRSTRLEN 16 |
| 75 |
|
| 76 |
// Non-POSIX |
| 77 |
#define INADDR_NONE ((in_addr_t) 0xffffffff) |
| 78 |
|
| 79 |
#define IN6ADDR_ANY_INIT {{0}} |
| 80 |
#define IN6ADDR_LOOPBACK_INIT {{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }} |
| 81 |
#define INET6_ADDRSTRLEN 46 |
| 82 |
|
| 83 |
// Not required by POSIX |
| 84 |
#define INADDR_LOOPBACK (uint32_t)0x7F000001 |
| 85 |
|
| 86 |
extern const struct in6_addr in6addr_any; |
| 87 |
extern const struct in6_addr in6addr_loopback; |
| 88 |
|
| 89 |
struct ipv6_mreq { |
| 90 |
struct in6_addr ipv6mr_multiaddr; |
| 91 |
unsigned ipv6mr_interface; |
| 92 |
}; |
| 93 |
|
| 94 |
|
| 95 |
struct in6_pktinfo |
| 96 |
{ |
| 97 |
struct in6_addr ipi6_addr; |
| 98 |
int ipi6_ifindex; |
| 99 |
}; |
| 100 |
|
| 101 |
|
| 102 |
/* Standard well-defined IP protocols. */ |
| 103 |
enum __fc_ipproto |
| 104 |
{ |
| 105 |
IPPROTO_IP = 0, /* Dummy protocol for TCP. */ |
| 106 |
#define IPPROTO_IP IPPROTO_IP |
| 107 |
IPPROTO_HOPOPTS = 0, /* IPv6 Hop-by-Hop options. */ |
| 108 |
#define IPPROTO_HOPOPTS IPPROTO_HOPOPTS |
| 109 |
IPPROTO_ICMP = 1, /* Internet Control Message Protocol. */ |
| 110 |
#define IPPROTO_ICMP IPPROTO_ICMP |
| 111 |
IPPROTO_IGMP = 2, /* Internet Group Management Protocol. */ |
| 112 |
#define IPPROTO_IGMP IPPROTO_IGMP |
| 113 |
IPPROTO_IPIP = 4, /* IPIP tunnels (older KA9Q tunnels use 94). */ |
| 114 |
#define IPPROTO_IPIP IPPROTO_IPIP |
| 115 |
IPPROTO_TCP = 6, /* Transmission Control Protocol. */ |
| 116 |
#define IPPROTO_TCP IPPROTO_TCP |
| 117 |
IPPROTO_EGP = 8, /* Exterior Gateway Protocol. */ |
| 118 |
#define IPPROTO_EGP IPPROTO_EGP |
| 119 |
IPPROTO_PUP = 12, /* PUP protocol. */ |
| 120 |
#define IPPROTO_PUP IPPROTO_PUP |
| 121 |
IPPROTO_UDP = 17, /* User Datagram Protocol. */ |
| 122 |
#define IPPROTO_UDP IPPROTO_UDP |
| 123 |
IPPROTO_IDP = 22, /* XNS IDP protocol. */ |
| 124 |
#define IPPROTO_IDP IPPROTO_IDP |
| 125 |
IPPROTO_TP = 29, /* SO Transport Protocol Class 4. */ |
| 126 |
#define IPPROTO_TP IPPROTO_TP |
| 127 |
IPPROTO_DCCP = 33, /* Datagram Congestion Control Protocol. */ |
| 128 |
#define IPPROTO_DCCP IPPROTO_DCCP |
| 129 |
IPPROTO_IPV6 = 41, /* IPv6 header. */ |
| 130 |
#define IPPROTO_IPV6 IPPROTO_IPV6 |
| 131 |
IPPROTO_ROUTING = 43, /* IPv6 routing header. */ |
| 132 |
#define IPPROTO_ROUTING IPPROTO_ROUTING |
| 133 |
IPPROTO_FRAGMENT = 44, /* IPv6 fragmentation header. */ |
| 134 |
#define IPPROTO_FRAGMENT IPPROTO_FRAGMENT |
| 135 |
IPPROTO_RSVP = 46, /* Reservation Protocol. */ |
| 136 |
#define IPPROTO_RSVP IPPROTO_RSVP |
| 137 |
IPPROTO_GRE = 47, /* General Routing Encapsulation. */ |
| 138 |
#define IPPROTO_GRE IPPROTO_GRE |
| 139 |
IPPROTO_ESP = 50, /* encapsulating security payload. */ |
| 140 |
#define IPPROTO_ESP IPPROTO_ESP |
| 141 |
IPPROTO_AH = 51, /* authentication header. */ |
| 142 |
#define IPPROTO_AH IPPROTO_AH |
| 143 |
IPPROTO_ICMPV6 = 58, /* ICMPv6. */ |
| 144 |
#define IPPROTO_ICMPV6 IPPROTO_ICMPV6 |
| 145 |
IPPROTO_NONE = 59, /* IPv6 no next header. */ |
| 146 |
#define IPPROTO_NONE IPPROTO_NONE |
| 147 |
IPPROTO_DSTOPTS = 60, /* IPv6 destination options. */ |
| 148 |
#define IPPROTO_DSTOPTS IPPROTO_DSTOPTS |
| 149 |
IPPROTO_MTP = 92, /* Multicast Transport Protocol. */ |
| 150 |
#define IPPROTO_MTP IPPROTO_MTP |
| 151 |
IPPROTO_ENCAP = 98, /* Encapsulation Header. */ |
| 152 |
#define IPPROTO_ENCAP IPPROTO_ENCAP |
| 153 |
IPPROTO_PIM = 103, /* Protocol Independent Multicast. */ |
| 154 |
#define IPPROTO_PIM IPPROTO_PIM |
| 155 |
IPPROTO_COMP = 108, /* Compression Header Protocol. */ |
| 156 |
#define IPPROTO_COMP IPPROTO_COMP |
| 157 |
IPPROTO_SCTP = 132, /* Stream Control Transmission Protocol. */ |
| 158 |
#define IPPROTO_SCTP IPPROTO_SCTP |
| 159 |
IPPROTO_UDPLITE = 136, /* UDP-Lite protocol. */ |
| 160 |
#define IPPROTO_UDPLITE IPPROTO_UDPLITE |
| 161 |
IPPROTO_RAW = 255, /* Raw IP packets. */ |
| 162 |
#define IPPROTO_RAW IPPROTO_RAW |
| 163 |
IPPROTO_MAX |
| 164 |
}; |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
/*** originally from bits/in.h ***/ |
| 169 |
|
| 170 |
/* Options for use with `getsockopt' and `setsockopt' at the IP level. |
| 171 |
The first word in the comment at the right is the data type used; |
| 172 |
"bool" means a boolean value stored in an `int'. */ |
| 173 |
#define IP_OPTIONS 4 /* ip_opts; IP per-packet options. */ |
| 174 |
#define IP_HDRINCL 3 /* int; Header is included with data. */ |
| 175 |
#define IP_TOS 1 /* int; IP type of service and precedence. */ |
| 176 |
#define IP_TTL 2 /* int; IP time to live. */ |
| 177 |
#define IP_RECVOPTS 6 /* bool; Receive all IP options w/datagram. */ |
| 178 |
/* For BSD compatibility. */ |
| 179 |
#define IP_RECVRETOPTS IP_RETOPTS /* bool; Receive IP options for response. */ |
| 180 |
#define IP_RETOPTS 7 /* ip_opts; Set/get IP per-packet options. */ |
| 181 |
#define IP_MULTICAST_IF 32 /* in_addr; set/get IP multicast i/f */ |
| 182 |
#define IP_MULTICAST_TTL 33 /* u_char; set/get IP multicast ttl */ |
| 183 |
#define IP_MULTICAST_LOOP 34 /* i_char; set/get IP multicast loopback */ |
| 184 |
#define IP_ADD_MEMBERSHIP 35 /* ip_mreq; add an IP group membership */ |
| 185 |
#define IP_DROP_MEMBERSHIP 36 /* ip_mreq; drop an IP group membership */ |
| 186 |
#define IP_UNBLOCK_SOURCE 37 /* ip_mreq_source: unblock data from source */ |
| 187 |
#define IP_BLOCK_SOURCE 38 /* ip_mreq_source: block data from source */ |
| 188 |
#define IP_ADD_SOURCE_MEMBERSHIP 39 /* ip_mreq_source: join source group */ |
| 189 |
#define IP_DROP_SOURCE_MEMBERSHIP 40 /* ip_mreq_source: leave source group */ |
| 190 |
#define IP_MSFILTER 41 |
| 191 |
#if defined __USE_MISC || defined __USE_GNU |
| 192 |
# define MCAST_JOIN_GROUP 42 /* group_req: join any-source group */ |
| 193 |
# define MCAST_BLOCK_SOURCE 43 /* group_source_req: block from given group */ |
| 194 |
# define MCAST_UNBLOCK_SOURCE 44 /* group_source_req: unblock from given group*/ |
| 195 |
# define MCAST_LEAVE_GROUP 45 /* group_req: leave any-source group */ |
| 196 |
# define MCAST_JOIN_SOURCE_GROUP 46 /* group_source_req: join source-spec gr */ |
| 197 |
# define MCAST_LEAVE_SOURCE_GROUP 47 /* group_source_req: leave source-spec gr*/ |
| 198 |
# define MCAST_MSFILTER 48 |
| 199 |
|
| 200 |
# define MCAST_EXCLUDE 0 |
| 201 |
# define MCAST_INCLUDE 1 |
| 202 |
#endif |
| 203 |
|
| 204 |
|
| 205 |
#define IP_ROUTER_ALERT 5 /* bool */ |
| 206 |
#define IP_PKTINFO 8 /* bool */ |
| 207 |
#define IP_PKTOPTIONS 9 |
| 208 |
#define IP_PMTUDISC 10 /* obsolete name? */ |
| 209 |
#define IP_MTU_DISCOVER 10 /* int; see below */ |
| 210 |
#define IP_RECVERR 11 /* bool */ |
| 211 |
#define IP_RECVTTL 12 /* bool */ |
| 212 |
#define IP_RECVTOS 13 /* bool */ |
| 213 |
#define IP_MTU 14 /* int */ |
| 214 |
#define IP_FREEBIND 15 |
| 215 |
#define IP_IPSEC_POLICY 16 |
| 216 |
#define IP_XFRM_POLICY 17 |
| 217 |
#define IP_PASSSEC 18 |
| 218 |
#define IP_TRANSPARENT 19 |
| 219 |
|
| 220 |
|
| 221 |
/* TProxy original addresses */ |
| 222 |
#define IP_ORIGDSTADDR 20 |
| 223 |
#define IP_RECVORIGDSTADDR IP_ORIGDSTADDR |
| 224 |
|
| 225 |
#define IP_MINTTL 21 |
| 226 |
|
| 227 |
|
| 228 |
/* IP_MTU_DISCOVER arguments. */ |
| 229 |
#define IP_PMTUDISC_DONT 0 /* Never send DF frames. */ |
| 230 |
#define IP_PMTUDISC_WANT 1 /* Use per route hints. */ |
| 231 |
#define IP_PMTUDISC_DO 2 /* Always DF. */ |
| 232 |
#define IP_PMTUDISC_PROBE 3 /* Ignore dst pmtu. */ |
| 233 |
|
| 234 |
/* To select the IP level. */ |
| 235 |
#define SOL_IP 0 |
| 236 |
|
| 237 |
#define IP_DEFAULT_MULTICAST_TTL 1 |
| 238 |
#define IP_DEFAULT_MULTICAST_LOOP 1 |
| 239 |
#define IP_MAX_MEMBERSHIPS 20 |
| 240 |
|
| 241 |
|
| 242 |
#if defined __USE_MISC || defined __USE_GNU |
| 243 |
/* Structure used to describe IP options for IP_OPTIONS and IP_RETOPTS. |
| 244 |
The `ip_dst' field is used for the first-hop gateway when using a |
| 245 |
source route (this gets put into the header proper). */ |
| 246 |
struct ip_opts |
| 247 |
{ |
| 248 |
struct in_addr ip_dst; /* First hop; zero without source route. */ |
| 249 |
char ip_opts[40]; /* Actually variable in size. */ |
| 250 |
}; |
| 251 |
|
| 252 |
/* Like `struct ip_mreq' but including interface specification by index. */ |
| 253 |
struct ip_mreqn |
| 254 |
{ |
| 255 |
struct in_addr imr_multiaddr; /* IP multicast address of group */ |
| 256 |
struct in_addr imr_address; /* local IP address of interface */ |
| 257 |
int imr_ifindex; /* Interface index */ |
| 258 |
}; |
| 259 |
|
| 260 |
/* Structure used for IP_PKTINFO. */ |
| 261 |
struct in_pktinfo |
| 262 |
{ |
| 263 |
int ipi_ifindex; /* Interface index */ |
| 264 |
struct in_addr ipi_spec_dst; /* Routing destination address */ |
| 265 |
struct in_addr ipi_addr; /* Header destination address */ |
| 266 |
}; |
| 267 |
#endif |
| 268 |
|
| 269 |
/* Options for use with `getsockopt' and `setsockopt' at the IPv6 level. |
| 270 |
The first word in the comment at the right is the data type used; |
| 271 |
"bool" means a boolean value stored in an `int'. */ |
| 272 |
#define IPV6_ADDRFORM 1 |
| 273 |
#define IPV6_2292PKTINFO 2 |
| 274 |
#define IPV6_2292HOPOPTS 3 |
| 275 |
#define IPV6_2292DSTOPTS 4 |
| 276 |
#define IPV6_2292RTHDR 5 |
| 277 |
#define IPV6_2292PKTOPTIONS 6 |
| 278 |
#define IPV6_CHECKSUM 7 |
| 279 |
#define IPV6_2292HOPLIMIT 8 |
| 280 |
|
| 281 |
#define SCM_SRCRT IPV6_RXSRCRT |
| 282 |
|
| 283 |
#define IPV6_NEXTHOP 9 |
| 284 |
#define IPV6_AUTHHDR 10 |
| 285 |
#define IPV6_UNICAST_HOPS 16 |
| 286 |
#define IPV6_MULTICAST_IF 17 |
| 287 |
#define IPV6_MULTICAST_HOPS 18 |
| 288 |
#define IPV6_MULTICAST_LOOP 19 |
| 289 |
#define IPV6_JOIN_GROUP 20 |
| 290 |
#define IPV6_LEAVE_GROUP 21 |
| 291 |
#define IPV6_ROUTER_ALERT 22 |
| 292 |
#define IPV6_MTU_DISCOVER 23 |
| 293 |
#define IPV6_MTU 24 |
| 294 |
#define IPV6_RECVERR 25 |
| 295 |
#define IPV6_V6ONLY 26 |
| 296 |
#define IPV6_JOIN_ANYCAST 27 |
| 297 |
#define IPV6_LEAVE_ANYCAST 28 |
| 298 |
#define IPV6_IPSEC_POLICY 34 |
| 299 |
#define IPV6_XFRM_POLICY 35 |
| 300 |
|
| 301 |
#define IPV6_RECVPKTINFO 49 |
| 302 |
#define IPV6_PKTINFO 50 |
| 303 |
#define IPV6_RECVHOPLIMIT 51 |
| 304 |
#define IPV6_HOPLIMIT 52 |
| 305 |
#define IPV6_RECVHOPOPTS 53 |
| 306 |
#define IPV6_HOPOPTS 54 |
| 307 |
#define IPV6_RTHDRDSTOPTS 55 |
| 308 |
#define IPV6_RECVRTHDR 56 |
| 309 |
#define IPV6_RTHDR 57 |
| 310 |
#define IPV6_RECVDSTOPTS 58 |
| 311 |
#define IPV6_DSTOPTS 59 |
| 312 |
|
| 313 |
#define IPV6_RECVTCLASS 66 |
| 314 |
#define IPV6_TCLASS 67 |
| 315 |
|
| 316 |
/* Obsolete synonyms for the above. */ |
| 317 |
#define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP |
| 318 |
#define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP |
| 319 |
#define IPV6_RXHOPOPTS IPV6_HOPOPTS |
| 320 |
#define IPV6_RXDSTOPTS IPV6_DSTOPTS |
| 321 |
|
| 322 |
/* IPV6_MTU_DISCOVER values. */ |
| 323 |
#define IPV6_PMTUDISC_DONT 0 /* Never send DF frames. */ |
| 324 |
#define IPV6_PMTUDISC_WANT 1 /* Use per route hints. */ |
| 325 |
#define IPV6_PMTUDISC_DO 2 /* Always DF. */ |
| 326 |
#define IPV6_PMTUDISC_PROBE 3 /* Ignore dst pmtu. */ |
| 327 |
|
| 328 |
/* Socket level values for IPv6. */ |
| 329 |
#define SOL_IPV6 41 |
| 330 |
#define SOL_ICMPV6 58 |
| 331 |
|
| 332 |
/* Routing header options for IPv6. */ |
| 333 |
#define IPV6_RTHDR_LOOSE 0 /* Hop doesn't need to be neighbour. */ |
| 334 |
#define IPV6_RTHDR_STRICT 1 /* Hop must be a neighbour. */ |
| 335 |
|
| 336 |
#define IPV6_RTHDR_TYPE_0 0 /* IPv6 Routing header type 0. */ |
| 337 |
|
| 338 |
// END OF DEFINITIONS FROM <netinet/in.h> |
| 339 |
|
| 340 |
// THE DEFINITIONS BELOW WERE ORIGINALLY IN <arpa/inet.h> |
| 341 |
|
| 342 |
/*@ assigns \result \from arg ; */ |
| 343 |
extern uint32_t htonl(uint32_t arg); |
| 344 |
|
| 345 |
/*@ assigns \result \from arg ; */ |
| 346 |
extern uint16_t htons(uint16_t arg); |
| 347 |
|
| 348 |
/*@ assigns \result \from arg ; */ |
| 349 |
extern uint32_t ntohl(uint32_t arg); |
| 350 |
|
| 351 |
/*@ assigns \result \from arg ; */ |
| 352 |
extern uint16_t ntohs(uint16_t arg); |
| 353 |
|
| 354 |
/*@ |
| 355 |
requires valid_arg: valid_read_string(arg); |
| 356 |
assigns \result \from indirect:arg[0..]; */ |
| 357 |
extern in_addr_t inet_addr(const char *arg); |
| 358 |
|
| 359 |
volatile char __fc_inet_ntoa_array[16]; |
| 360 |
char *__fc_inet_ntoa = (char*)__fc_inet_ntoa_array; |
| 361 |
|
| 362 |
/*@ |
| 363 |
assigns \result \from indirect:arg, __fc_inet_ntoa; |
| 364 |
assigns __fc_inet_ntoa[0..] \from indirect:arg; |
| 365 |
ensures result_static_string: \result == __fc_inet_ntoa; |
| 366 |
ensures result_null_terminated: \result[15] == 0; // always null-terminated |
| 367 |
ensures result_valid_string: valid_read_string(\result); |
| 368 |
*/ |
| 369 |
extern char *inet_ntoa(struct in_addr arg); |
| 370 |
|
| 371 |
/*@ |
| 372 |
assigns \result \from dst,af,((char*)src)[0..]; |
| 373 |
assigns dst[0..size-1] \from af,((char*)src)[0..] ; */ |
| 374 |
extern const char *inet_ntop(int af, const void *src, char *dst, |
| 375 |
socklen_t size); |
| 376 |
|
| 377 |
/*@ |
| 378 |
assigns \result \from af,src[..]; |
| 379 |
assigns ((char*)dst)[0..] \from af,src[0..] ; */ |
| 380 |
extern int inet_pton(int af, const char *src, void *dst); |
| 381 |
|
| 382 |
////////// END OF DEFINITIONS FROM <arpa/inet.h> |
| 383 |
|
| 384 |
__END_DECLS |
| 385 |
__POP_FC_STDLIB |
| 386 |
#endif |