Debian Codegraph @

share/libc/netdb.h

raw
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_NETDB
24 #define __FC_NETDB
25 #include "features.h"
26 __PUSH_FC_STDLIB
27
28 #include "netinet/in.h"
29 #include "sys/socket.h"
30 #include "inttypes.h"
31 #include "__fc_string_axiomatic.h"
32
33 __BEGIN_DECLS
34
35 struct hostent
36 {
37 char *h_name; /* Official name of host. */
38 char **h_aliases; /* Alias list. */
39 int h_addrtype; /* Host address type. */
40 int h_length; /* Length of address. */
41 char **h_addr_list; /* List of addresses from name server. */
42 };
43 #define h_addr h_addr_list[0] /* for backward compatibility */
44
45 struct netent
46 {
47 char *n_name; /* Official name of network. */
48 char **n_aliases; /* Alias list. */
49 int n_addrtype; /* Net address type. */
50 uint32_t n_net; /* Network number. */
51 };
52 struct protoent
53 {
54 char *p_name; /* Official protocol name. */
55 char **p_aliases; /* Alias list. */
56 int p_proto; /* Protocol number. */
57 };
58 struct servent
59 {
60 char *s_name; /* Official service name. */
61 char **s_aliases; /* Alias list. */
62 int s_port; /* Port number. */
63 char *s_proto; /* Protocol to use. */
64 };
65
66 #define IPPORT_RESERVED 1024
67
68 int h_errno;
69
70 # define HOST_NOT_FOUND 1
71 # define TRY_AGAIN 2
72 # define NO_RECOVERY 3
73 # define NO_DATA 4
74
75 struct addrinfo
76 {
77 int ai_flags; /* Input flags. */
78 int ai_family; /* Protocol family for socket. */
79 int ai_socktype; /* Socket type. */
80 int ai_protocol; /* Protocol for socket. */
81 socklen_t ai_addrlen; /* Length of socket address. */
82 struct sockaddr *ai_addr; /* Socket address for socket. */
83 char *ai_canonname; /* Canonical name for service location. */
84 struct addrinfo *ai_next; /* Pointer to next in list. */
85 };
86
87 # define AI_PASSIVE 0x0001 /* Socket address is intended for `bind'. */
88 # define AI_CANONNAME 0x0002 /* Request for canonical name. */
89 # define AI_NUMERICHOST 0x0004 /* Don't use name resolution. */
90 # define AI_NUMERICSERV 0x0400 /* Don't use name resolution. */
91 # define AI_V4MAPPED 0x0008 /* IPv4 mapped addresses are acceptable. */
92 # define AI_ALL 0x0010 /* Return IPv4 mapped and IPv6 addresses. */
93 # define AI_ADDRCONFIG 0x0020 /* Use configuration of this host to choose
94 returned address type.. */
95 # define NI_NUMERICHOST 1 /* Don't try to look up hostname. */
96 # define NI_NUMERICSERV 2 /* Don't convert port number to name. */
97 # define NI_NOFQDN 4 /* Only return nodename portion. */
98 # define NI_NAMEREQD 8 /* Don't return numeric addresses. */
99 # define NI_DGRAM 16 /* Look up UDP service rather than TCP. */
100 # define NI_NUMERICSCOPE 32
101
102 // Non-POSIX
103 #ifndef NI_MAXHOST
104 # define NI_MAXHOST 1025
105 #endif
106 #ifndef NI_MAXSERV
107 # define NI_MAXSERV 32
108 #endif
109
110 # define EAI_BADFLAGS -1 /* Invalid value for `ai_flags' field. */
111 # define EAI_NONAME -2 /* NAME or SERVICE is unknown. */
112 # define EAI_AGAIN -3 /* Temporary failure in name resolution. */
113 # define EAI_FAIL -4 /* Non-recoverable failure in name res. */
114 # define EAI_FAMILY -6 /* `ai_family' not supported. */
115 # define EAI_SOCKTYPE -7 /* `ai_socktype' not supported. */
116 # define EAI_SERVICE -8 /* SERVICE not supported for `ai_socktype'. */
117 # define EAI_MEMORY -10 /* Memory allocation failure. */
118 # define EAI_SYSTEM -11 /* System error returned in `errno'. */
119 # define EAI_OVERFLOW -12 /* Argument buffer overflow. */
120
121 extern void endhostent(void);
122 extern void endnetent(void);
123 extern void endprotoent(void);
124 extern void endservent(void);
125 /*@ requires addrinfo_valid: \valid(addrinfo);
126 assigns \nothing;
127 frees addrinfo;
128 ensures allocation: \allocable(addrinfo);
129 */
130 extern void freeaddrinfo(struct addrinfo * addrinfo);
131
132 const char *__fc_gai_strerror = "<error message reported by gai_strerror>";
133
134 /*@
135 assigns \result \from indirect:errcode, __fc_gai_strerror;
136 ensures result_string: \result == __fc_gai_strerror;
137 ensures result_valid_string: valid_read_string(\result);
138 */
139 extern const char *gai_strerror(int errcode);
140
141 /*@ requires nodename_string: nodename == \null || valid_read_string(nodename);
142 requires servname_string: servname == \null || valid_read_string(servname);
143 requires hints_option: hints == \null || \valid_read(hints);
144 requires valid_res: \valid(res);
145
146 assigns *res \from indirect:nodename, indirect:servname, indirect:hints;
147 assigns \result \from indirect:nodename, indirect:servname,indirect:hints;
148 assigns errno \from indirect:nodename, indirect:servname, indirect:hints;
149
150 allocates *res;
151
152 behavior empty_request:
153 assumes empty: nodename == \null && servname == \null;
154 assigns \result \from indirect:nodename, indirect:servname;
155 ensures no_name: \result == EAI_NONAME;
156
157 behavior normal_request:
158 assumes has_name: nodename != \null || servname != \null;
159 ensures initialization:allocation:success_or_error:
160 (\result == 0 && \fresh(*res,sizeof(*res))
161 && \initialized(*res))
162 || \result == EAI_AGAIN
163 || \result == EAI_BADFLAGS
164 || \result == EAI_FAIL
165 || \result == EAI_FAMILY
166 || \result == EAI_MEMORY
167 || \result == EAI_SERVICE
168 || \result == EAI_SOCKTYPE
169 || \result == EAI_SYSTEM;
170
171 complete behaviors;
172 disjoint behaviors;
173 */
174 extern int getaddrinfo(
175 const char *restrict nodename,
176 const char *restrict servname,
177 const struct addrinfo *restrict hints,
178 struct addrinfo **restrict res);
179
180 extern struct hostent *gethostbyaddr(const void *, socklen_t, int);
181 extern struct hostent *gethostbyname(const char *);
182 extern struct hostent *gethostent(void);
183 extern int getnameinfo(const struct sockaddr *restrict, socklen_t,
184 char *restrict, socklen_t, char *restrict,
185 socklen_t, int);
186 extern struct netent *getnetbyaddr(uint32_t, int);
187 extern struct netent *getnetbyname(const char *);
188 extern struct netent *getnetent(void);
189 extern struct protoent *getprotobyname(const char *);
190 extern struct protoent *getprotobynumber(int);
191 extern struct protoent *getprotoent(void);
192 extern struct servent *getservbyname(const char *, const char *);
193 extern struct servent *getservbyport(int, const char *);
194 extern struct servent *getservent(void);
195 extern void sethostent(int);
196 extern void setnetent(int);
197 extern void setprotoent(int);
198 extern void setservent(int);
199
200 __END_DECLS
201
202 __POP_FC_STDLIB
203 #endif
204