Mercurial > dovecot > core-2.2
annotate src/lib/network.c @ 388:792fc5b3daa4 HEAD
Send error message if close() fails in net_disconnect().
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Wed, 09 Oct 2002 02:22:06 +0300 |
parents | fd32faeb7ba5 |
children | f25e575bf1ca |
rev | line source |
---|---|
0 | 1 /* |
2 network.c : Network stuff with IPv6 support | |
3 | |
4 Copyright (c) 1999-2002 Timo Sirainen | |
5 | |
6 Permission is hereby granted, free of charge, to any person obtaining | |
7 a copy of this software and associated documentation files (the | |
8 "Software"), to deal in the Software without restriction, including | |
9 without limitation the rights to use, copy, modify, merge, publish, | |
10 distribute, sublicense, and/or sell copies of the Software, and to | |
11 permit persons to whom the Software is furnished to do so, subject to | |
12 the following conditions: | |
13 | |
14 The above copyright notice and this permission notice shall be | |
15 included in all copies or substantial portions of the Software. | |
16 | |
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
18 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
20 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | |
21 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | |
22 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | |
23 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
24 */ | |
25 | |
26 #include "lib.h" | |
27 #include "network.h" | |
28 | |
29 #include <unistd.h> | |
30 #include <fcntl.h> | |
31 #include <ctype.h> | |
32 #include <sys/un.h> | |
33 #include <netinet/tcp.h> | |
34 | |
35 #define LISTEN_BACKLOG 8 | |
36 | |
37 union sockaddr_union { | |
38 struct sockaddr sa; | |
39 struct sockaddr_in sin; | |
40 #ifdef HAVE_IPV6 | |
41 struct sockaddr_in6 sin6; | |
42 #endif | |
43 }; | |
44 | |
45 #ifdef HAVE_IPV6 | |
46 # define SIZEOF_SOCKADDR(so) ((so).sa.sa_family == AF_INET6 ? \ | |
47 sizeof(so.sin6) : sizeof(so.sin)) | |
48 #else | |
49 # define SIZEOF_SOCKADDR(so) (sizeof(so.sin)) | |
50 #endif | |
51 | |
52 int net_ip_compare(IPADDR *ip1, IPADDR *ip2) | |
53 { | |
54 if (ip1->family != ip2->family) | |
55 return 0; | |
56 | |
57 #ifdef HAVE_IPV6 | |
58 if (ip1->family == AF_INET6) | |
59 return memcmp(&ip1->ip, &ip2->ip, sizeof(ip1->ip)) == 0; | |
60 #endif | |
61 | |
62 return memcmp(&ip1->ip, &ip2->ip, 4) == 0; | |
63 } | |
64 | |
65 | |
66 /* copy IP to sockaddr */ | |
67 static inline void sin_set_ip(union sockaddr_union *so, const IPADDR *ip) | |
68 { | |
69 if (ip == NULL) { | |
70 #ifdef HAVE_IPV6 | |
71 so->sin6.sin6_family = AF_INET6; | |
72 so->sin6.sin6_addr = in6addr_any; | |
73 #else | |
74 so->sin.sin_family = AF_INET; | |
75 so->sin.sin_addr.s_addr = INADDR_ANY; | |
76 #endif | |
77 return; | |
78 } | |
79 | |
80 so->sin.sin_family = ip->family; | |
81 #ifdef HAVE_IPV6 | |
82 if (ip->family == AF_INET6) | |
83 memcpy(&so->sin6.sin6_addr, &ip->ip, sizeof(ip->ip)); | |
84 else | |
85 #endif | |
86 memcpy(&so->sin.sin_addr, &ip->ip, 4); | |
87 } | |
88 | |
89 static inline void sin_get_ip(const union sockaddr_union *so, IPADDR *ip) | |
90 { | |
91 ip->family = so->sin.sin_family; | |
92 | |
93 #ifdef HAVE_IPV6 | |
94 if (ip->family == AF_INET6) | |
95 memcpy(&ip->ip, &so->sin6.sin6_addr, sizeof(ip->ip)); | |
96 else | |
97 #endif | |
98 memcpy(&ip->ip, &so->sin.sin_addr, 4); | |
99 } | |
100 | |
349 | 101 static inline void sin_set_port(union sockaddr_union *so, unsigned int port) |
0 | 102 { |
103 #ifdef HAVE_IPV6 | |
104 if (so->sin.sin_family == AF_INET6) | |
105 so->sin6.sin6_port = htons((unsigned short) port); | |
106 else | |
107 #endif | |
108 so->sin.sin_port = htons((unsigned short) port); | |
109 } | |
110 | |
349 | 111 static inline unsigned int sin_get_port(union sockaddr_union *so) |
0 | 112 { |
113 #ifdef HAVE_IPV6 | |
114 if (so->sin.sin_family == AF_INET6) | |
115 return ntohs(so->sin6.sin6_port); | |
116 #endif | |
117 return ntohs(so->sin.sin_port); | |
118 } | |
119 | |
120 static inline void close_save_errno(int fd) | |
121 { | |
122 int old_errno = errno; | |
123 close(fd); | |
124 errno = old_errno; | |
125 } | |
126 | |
127 /* Connect to socket with ip address */ | |
349 | 128 int net_connect_ip(IPADDR *ip, unsigned int port, IPADDR *my_ip) |
0 | 129 { |
130 union sockaddr_union so; | |
131 int fd, ret, opt = 1; | |
132 | |
133 if (my_ip != NULL && ip->family != my_ip->family) { | |
134 i_warning("net_connect_ip(): ip->family != my_ip->family"); | |
135 my_ip = NULL; | |
136 } | |
137 | |
138 /* create the socket */ | |
139 memset(&so, 0, sizeof(so)); | |
140 so.sin.sin_family = ip->family; | |
141 fd = socket(ip->family, SOCK_STREAM, 0); | |
142 | |
143 if (fd == -1) | |
144 return -1; | |
145 | |
146 /* set socket options */ | |
147 net_set_nonblock(fd, TRUE); | |
148 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); | |
149 setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &opt, sizeof(opt)); | |
150 | |
151 /* set our own address */ | |
152 if (my_ip != NULL) { | |
153 sin_set_ip(&so, my_ip); | |
154 if (bind(fd, &so.sa, SIZEOF_SOCKADDR(so)) == -1) { | |
155 /* failed, set it back to INADDR_ANY */ | |
156 sin_set_ip(&so, NULL); | |
157 bind(fd, &so.sa, SIZEOF_SOCKADDR(so)); | |
158 } | |
159 } | |
160 | |
161 /* connect */ | |
162 sin_set_ip(&so, ip); | |
163 sin_set_port(&so, port); | |
164 ret = connect(fd, &so.sa, SIZEOF_SOCKADDR(so)); | |
165 | |
166 #ifndef WIN32 | |
167 if (ret < 0 && errno != EINPROGRESS) | |
168 #else | |
169 if (ret < 0 && WSAGetLastError() != WSAEWOULDBLOCK) | |
170 #endif | |
171 { | |
172 close_save_errno(fd); | |
173 return -1; | |
174 } | |
175 | |
176 return fd; | |
177 } | |
178 | |
179 int net_connect_unix(const char *path) | |
180 { | |
181 struct sockaddr_un sa; | |
182 int fd, ret; | |
183 | |
184 if (strlen(path) > sizeof(sa.sun_path)-1) { | |
185 /* too long path */ | |
186 errno = EINVAL; | |
187 return -1; | |
188 } | |
189 | |
190 /* create the socket */ | |
191 fd = socket(PF_UNIX, SOCK_STREAM, 0); | |
192 if (fd == -1) | |
193 return -1; | |
194 | |
195 /* set socket options */ | |
196 net_set_nonblock(fd, TRUE); | |
197 | |
198 /* connect */ | |
199 memset(&sa, 0, sizeof(sa)); | |
200 sa.sun_family = AF_UNIX; | |
201 strcpy(sa.sun_path, path); | |
202 | |
203 ret = connect(fd, (struct sockaddr *) &sa, sizeof(sa)); | |
204 if (ret < 0 && errno != EINPROGRESS) { | |
205 close_save_errno(fd); | |
206 return -1; | |
207 } | |
208 | |
209 return fd; | |
210 } | |
211 | |
212 /* Disconnect socket */ | |
213 void net_disconnect(int fd) | |
214 { | |
388
792fc5b3daa4
Send error message if close() fails in net_disconnect().
Timo Sirainen <tss@iki.fi>
parents:
349
diff
changeset
|
215 if (close(fd) < 0) |
792fc5b3daa4
Send error message if close() fails in net_disconnect().
Timo Sirainen <tss@iki.fi>
parents:
349
diff
changeset
|
216 i_error("net_disconnect() failed: %m"); |
0 | 217 } |
218 | |
219 /* Set socket blocking/nonblocking */ | |
34
a3d77e73f99b
fixed compile warnings with some systems
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
220 void net_set_nonblock(int fd __attr_unused__, int nonblock __attr_unused__) |
0 | 221 { |
222 #ifdef HAVE_FCNTL | |
223 if (fcntl(fd, F_SETFL, nonblock ? O_NONBLOCK : 0) < 0) | |
224 i_fatal("net_send_nonblock() failed: %m"); | |
225 #endif | |
226 } | |
227 | |
34
a3d77e73f99b
fixed compile warnings with some systems
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
228 void net_set_cork(int fd __attr_unused__, int cork __attr_unused__) |
0 | 229 { |
230 #ifdef TCP_CORK | |
231 setsockopt(fd, SOL_TCP, TCP_CORK, &cork, sizeof(cork)); | |
232 #endif | |
233 } | |
234 | |
235 /* Listen for connections on a socket. if `my_ip' is NULL, listen in any | |
236 address. */ | |
349 | 237 int net_listen(IPADDR *my_ip, unsigned int *port) |
0 | 238 { |
239 union sockaddr_union so; | |
240 int ret, fd, opt = 1; | |
241 socklen_t len; | |
242 | |
243 i_assert(port != NULL); | |
244 | |
245 memset(&so, 0, sizeof(so)); | |
246 sin_set_port(&so, *port); | |
247 sin_set_ip(&so, my_ip); | |
248 | |
249 /* create the socket */ | |
250 fd = socket(so.sin.sin_family, SOCK_STREAM, 0); | |
251 #ifdef HAVE_IPV6 | |
252 if (fd == -1 && (errno == EINVAL || errno == EAFNOSUPPORT)) { | |
253 /* IPv6 is not supported by OS */ | |
254 so.sin.sin_family = AF_INET; | |
255 so.sin.sin_addr.s_addr = INADDR_ANY; | |
256 | |
257 fd = socket(AF_INET, SOCK_STREAM, 0); | |
258 } | |
259 #endif | |
260 if (fd == -1) | |
261 return -1; | |
262 | |
263 /* set socket options */ | |
264 net_set_nonblock(fd, TRUE); | |
265 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); | |
266 setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &opt, sizeof(opt)); | |
267 | |
268 /* specify the address/port we want to listen in */ | |
269 ret = bind(fd, &so.sa, SIZEOF_SOCKADDR(so)); | |
270 if (ret >= 0) { | |
271 /* get the actual port we started listen */ | |
272 len = SIZEOF_SOCKADDR(so); | |
273 ret = getsockname(fd, &so.sa, &len); | |
274 if (ret >= 0) { | |
275 *port = sin_get_port(&so); | |
276 | |
277 /* start listening */ | |
278 if (listen(fd, LISTEN_BACKLOG) >= 0) | |
279 return fd; | |
280 } | |
281 | |
282 } | |
283 | |
284 /* error */ | |
285 close_save_errno(fd); | |
286 return -1; | |
287 } | |
288 | |
289 int net_listen_unix(const char *path) | |
290 { | |
291 struct sockaddr_un sa; | |
292 int fd; | |
293 | |
294 if (strlen(path) > sizeof(sa.sun_path)-1) { | |
295 /* too long path */ | |
296 errno = EINVAL; | |
297 return -1; | |
298 } | |
299 | |
300 /* create the socket */ | |
301 fd = socket(PF_UNIX, SOCK_STREAM, 0); | |
302 if (fd == -1) | |
303 return -1; | |
304 | |
305 /* set socket options */ | |
306 net_set_nonblock(fd, TRUE); | |
307 | |
308 /* bind */ | |
309 memset(&sa, 0, sizeof(sa)); | |
310 sa.sun_family = AF_UNIX; | |
311 strcpy(sa.sun_path, path); | |
312 | |
313 if (bind(fd, (struct sockaddr *) &sa, sizeof(sa)) == 0) { | |
314 /* start listening */ | |
315 if (listen(fd, LISTEN_BACKLOG) == 0) | |
316 return fd; | |
317 } | |
318 | |
319 close_save_errno(fd); | |
320 return -1; | |
321 } | |
322 | |
323 /* Accept a connection on a socket */ | |
349 | 324 int net_accept(int fd, IPADDR *addr, unsigned int *port) |
0 | 325 { |
326 union sockaddr_union so; | |
327 int ret; | |
328 socklen_t addrlen; | |
329 | |
330 i_assert(fd >= 0); | |
331 | |
332 addrlen = sizeof(so); | |
333 ret = accept(fd, &so.sa, &addrlen); | |
334 | |
335 if (ret < 0) | |
336 return -1; | |
337 | |
338 if (addr != NULL) sin_get_ip(&so, addr); | |
339 if (port != NULL) *port = sin_get_port(&so); | |
340 | |
159
e0193106a95d
net_accept() set listening socket nonblocking, not the new socket. thanks to
Timo Sirainen <tss@iki.fi>
parents:
64
diff
changeset
|
341 net_set_nonblock(ret, TRUE); |
0 | 342 return ret; |
343 } | |
344 | |
345 /* Read data from socket, return number of bytes read, -1 = error */ | |
183
4a7ab9e94f25
size_t fixes for lib/. Changed OFF_T_FORMAT to PRIuOFF_T which is more
Timo Sirainen <tss@iki.fi>
parents:
159
diff
changeset
|
346 ssize_t net_receive(int fd, void *buf, size_t len) |
0 | 347 { |
183
4a7ab9e94f25
size_t fixes for lib/. Changed OFF_T_FORMAT to PRIuOFF_T which is more
Timo Sirainen <tss@iki.fi>
parents:
159
diff
changeset
|
348 ssize_t ret; |
0 | 349 |
350 i_assert(fd >= 0); | |
351 i_assert(buf != NULL); | |
183
4a7ab9e94f25
size_t fixes for lib/. Changed OFF_T_FORMAT to PRIuOFF_T which is more
Timo Sirainen <tss@iki.fi>
parents:
159
diff
changeset
|
352 i_assert(len <= SSIZE_T_MAX); |
0 | 353 |
354 ret = recv(fd, buf, len, 0); | |
355 if (ret == 0) | |
356 return -1; /* disconnected */ | |
357 | |
358 if (ret < 0 && (errno == EINTR || errno == EAGAIN)) | |
359 return 0; | |
360 | |
361 return ret; | |
362 } | |
363 | |
364 /* Transmit data, return number of bytes sent, -1 = error */ | |
183
4a7ab9e94f25
size_t fixes for lib/. Changed OFF_T_FORMAT to PRIuOFF_T which is more
Timo Sirainen <tss@iki.fi>
parents:
159
diff
changeset
|
365 ssize_t net_transmit(int fd, const void *data, size_t len) |
0 | 366 { |
183
4a7ab9e94f25
size_t fixes for lib/. Changed OFF_T_FORMAT to PRIuOFF_T which is more
Timo Sirainen <tss@iki.fi>
parents:
159
diff
changeset
|
367 ssize_t ret; |
0 | 368 |
369 i_assert(fd >= 0); | |
370 i_assert(data != NULL); | |
183
4a7ab9e94f25
size_t fixes for lib/. Changed OFF_T_FORMAT to PRIuOFF_T which is more
Timo Sirainen <tss@iki.fi>
parents:
159
diff
changeset
|
371 i_assert(len <= SSIZE_T_MAX); |
0 | 372 |
64
83ae914a583a
added t_strdup_noconst() which can be used instead of (char *) t_strdup().
Timo Sirainen <tss@iki.fi>
parents:
34
diff
changeset
|
373 ret = send(fd, data, len, 0); |
0 | 374 if (ret == -1 && (errno == EINTR || errno == EPIPE || errno == EAGAIN)) |
375 return 0; | |
376 | |
377 return ret; | |
378 } | |
379 | |
380 /* Get IP addresses for host. ips contains ips_count of IPs, they don't need | |
381 to be free'd. Returns 0 = ok, others = error code for net_gethosterror() */ | |
382 int net_gethostbyname(const char *addr, IPADDR **ips, int *ips_count) | |
383 { | |
384 #ifdef HAVE_IPV6 | |
385 union sockaddr_union *so; | |
386 struct addrinfo hints, *ai, *origai; | |
387 char hbuf[NI_MAXHOST]; | |
388 int host_error; | |
389 #else | |
390 struct hostent *hp; | |
391 #endif | |
392 int count; | |
393 | |
394 i_assert(addr != NULL); | |
395 i_assert(ips != NULL); | |
396 i_assert(ips_count != NULL); | |
397 | |
398 *ips = NULL; | |
399 *ips_count = 0; | |
400 | |
401 #ifdef HAVE_IPV6 | |
402 memset(&hints, 0, sizeof(struct addrinfo)); | |
403 hints.ai_socktype = SOCK_STREAM; | |
404 | |
405 /* save error to host_error for later use */ | |
406 host_error = getaddrinfo(addr, NULL, &hints, &ai); | |
407 if (host_error != 0) | |
408 return host_error; | |
409 | |
410 if (getnameinfo(ai->ai_addr, ai->ai_addrlen, hbuf, | |
411 sizeof(hbuf), NULL, 0, NI_NUMERICHOST) != 0) | |
412 return 1; | |
413 | |
414 | |
415 /* get number of IPs */ | |
416 origai = ai; | |
417 for (count = 0; ai != NULL; ai = ai->ai_next) | |
418 count++; | |
419 | |
420 *ips_count = count; | |
421 *ips = t_malloc(sizeof(IPADDR) * count); | |
422 | |
423 count = 0; | |
424 for (ai = origai; ai != NULL; ai = ai->ai_next, count++) { | |
425 so = (union sockaddr_union *) ai->ai_addr; | |
426 | |
427 sin_get_ip(so, ips[count]); | |
428 } | |
429 freeaddrinfo(origai); | |
430 #else | |
431 hp = gethostbyname(addr); | |
432 if (hp == NULL) | |
433 return h_errno; | |
434 | |
435 /* get number of IPs */ | |
436 count = 0; | |
437 while (hp->h_addr_list[count] != NULL) | |
438 count++; | |
439 | |
440 *ips_count = count; | |
441 *ips = t_malloc(sizeof(IPADDR) * count); | |
442 | |
443 while (count > 0) { | |
444 count--; | |
445 | |
446 (*ips)[count].family = AF_INET; | |
447 memcpy(&(*ips)[count].ip, hp->h_addr_list[count], 4); | |
448 } | |
449 #endif | |
450 | |
451 return 0; | |
452 } | |
453 | |
454 /* Get socket address/port */ | |
349 | 455 int net_getsockname(int fd, IPADDR *addr, unsigned int *port) |
0 | 456 { |
457 union sockaddr_union so; | |
458 socklen_t addrlen; | |
459 | |
460 i_assert(fd >= 0); | |
461 | |
462 addrlen = sizeof(so); | |
463 if (getsockname(fd, (struct sockaddr *) &so, &addrlen) == -1) | |
464 return -1; | |
465 | |
466 if (addr != NULL) sin_get_ip(&so, addr); | |
467 if (port != NULL) *port = sin_get_port(&so); | |
468 | |
469 return 0; | |
470 } | |
471 | |
472 int net_ip2host(IPADDR *ip, char *host) | |
473 { | |
474 #ifdef HAVE_IPV6 | |
475 if (!inet_ntop(ip->family, &ip->ip, host, MAX_IP_LEN)) | |
476 return -1; | |
477 #else | |
478 unsigned long ip4; | |
479 | |
480 if (ip->family != AF_INET) { | |
481 strcpy(host, "0.0.0.0"); | |
482 return -1; | |
483 } | |
484 | |
485 ip4 = ntohl(ip->ip.s_addr); | |
486 i_snprintf(host, MAX_IP_LEN, "%lu.%lu.%lu.%lu", | |
487 (ip4 & 0xff000000UL) >> 24, | |
488 (ip4 & 0x00ff0000) >> 16, | |
489 (ip4 & 0x0000ff00) >> 8, | |
490 (ip4 & 0x000000ff)); | |
491 #endif | |
492 return 0; | |
493 } | |
494 | |
495 int net_host2ip(const char *host, IPADDR *ip) | |
496 { | |
497 if (strchr(host, ':') != NULL) { | |
498 /* IPv6 */ | |
499 ip->family = AF_INET6; | |
500 #ifdef HAVE_IPV6 | |
501 if (inet_pton(AF_INET6, host, &ip->ip) == 0) | |
502 return -1; | |
503 #else | |
504 ip->ip.s_addr = 0; | |
505 #endif | |
506 } else { | |
507 /* IPv4 */ | |
508 ip->family = AF_INET; | |
509 if (inet_aton(host, (struct in_addr *) &ip->ip) == 0) | |
510 return -1; | |
511 } | |
512 | |
513 return 0; | |
514 } | |
515 | |
516 /* Get socket error */ | |
517 int net_geterror(int fd) | |
518 { | |
519 int data; | |
520 socklen_t len = sizeof(data); | |
521 | |
522 if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &data, &len) == -1) | |
523 return -1; | |
524 | |
525 return data; | |
526 } | |
527 | |
528 /* get error of net_gethostname() */ | |
529 const char *net_gethosterror(int error) | |
530 { | |
531 #ifdef HAVE_IPV6 | |
532 i_assert(error != 0); | |
533 | |
534 if (error == 1) { | |
535 /* getnameinfo() failed */ | |
536 return strerror(errno); | |
537 } | |
538 | |
539 return gai_strerror(error); | |
540 #else | |
541 switch (error) { | |
542 case HOST_NOT_FOUND: | |
543 return "Host not found"; | |
544 case NO_ADDRESS: | |
545 return "No IP address found for name"; | |
546 case NO_RECOVERY: | |
547 return "A non-recovable name server error occurred"; | |
548 case TRY_AGAIN: | |
549 return "A temporary error on an authoritative name server"; | |
550 } | |
551 | |
552 /* unknown error */ | |
553 return NULL; | |
554 #endif | |
555 } | |
556 | |
557 /* return TRUE if host lookup failed because it didn't exist (ie. not | |
558 some error with name server) */ | |
559 int net_hosterror_notfound(int error) | |
560 { | |
561 #ifdef HAVE_IPV6 | |
562 return error != 1 && (error == EAI_NONAME || error == EAI_NODATA); | |
563 #else | |
564 return error == HOST_NOT_FOUND || error == NO_ADDRESS; | |
565 #endif | |
566 } | |
567 | |
568 /* Get name of TCP service */ | |
349 | 569 char *net_getservbyport(unsigned short port) |
0 | 570 { |
571 struct servent *entry; | |
572 | |
349 | 573 entry = getservbyport(htons(port), "tcp"); |
0 | 574 return entry == NULL ? NULL : entry->s_name; |
575 } | |
576 | |
577 int is_ipv4_address(const char *host) | |
578 { | |
579 while (*host != '\0') { | |
580 if (*host != '.' && !i_isdigit(*host)) | |
581 return 0; | |
582 host++; | |
583 } | |
584 | |
585 return 1; | |
586 } | |
587 | |
588 int is_ipv6_address(const char *host) | |
589 { | |
590 while (*host != '\0') { | |
591 if (*host != ':' && !i_isxdigit(*host)) | |
592 return 0; | |
593 host++; | |
594 } | |
595 | |
596 return 1; | |
597 } |