The OpenD Programming Language

1 /**
2  * D header file for POSIX.
3  *
4  * Copyright: Copyright David Nadlinger 2011.
5  * License:   $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
6  * Authors:   David Nadlinger, Sean Kelly, Alex Rønne Petersen
7  * Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
8  */
9 
10 /*          Copyright David Nadlinger 2011.
11  * Distributed under the Boost Software License, Version 1.0.
12  *    (See accompanying file LICENSE or copy at
13  *          http://www.boost.org/LICENSE_1_0.txt)
14  */
15 module core.sys.posix.netdb;
16 
17 import core.sys.posix.config;
18 public import core.stdc.inttypes;         // for uint32_t
19 public import core.sys.posix.netinet.in_; // for in_port_t, in_addr_t
20 public import core.sys.posix.sys.types;   // for ino_t
21 public import core.sys.posix.sys.socket;  // for socklen_t
22 
23 version (OSX)
24     version = Darwin;
25 else version (iOS)
26     version = Darwin;
27 else version (TVOS)
28     version = Darwin;
29 else version (WatchOS)
30     version = Darwin;
31 
32 version (Posix):
33 extern (C):
34 nothrow:
35 @nogc:
36 
37 //
38 // Required
39 //
40 /*
41 struct hostent
42 {
43     char*   h_name;
44     char**  h_aliases;
45     int     h_addrtype;
46     int     h_length;
47     char**  h_addr_list;
48 }
49 
50 struct netent
51 {
52     char*   n_name;
53     char**  n_aliase;
54     int     n_addrtype;
55     uint32_t n_net;
56 }
57 
58 struct protoent
59 {
60     char*   p_name;
61     char**  p_aliases;
62     int     p_proto;
63 }
64 
65 struct servent
66 {
67     char*   s_name;
68     char**  s_aliases;
69     int     s_port;
70     char*   s_proto;
71 }
72 
73 IPPORT_RESERVED
74 
75 h_errno
76 
77 HOST_NOT_FOUND
78 NO_DATA
79 NO_RECOVERY
80 TRY_AGAIN
81 
82 struct addrinfo
83 {
84     int         ai_flags;
85     int         ai_family;
86     int         ai_socktype;
87     int         ai_protocol;
88     socklen_t   ai_addrlen;
89     sockaddr*   ai_addr;
90     char*       ai_canonname;
91     addrinfo*   ai_next;
92 }
93 
94 AI_PASSIVE
95 AI_CANONNAME
96 AI_NUMERICHOST
97 AI_NUMERICSERV
98 AI_V4MAPPED
99 AI_ALL
100 AI_ADDRCONFIG
101 
102 NI_NOFQDN
103 NI_NUMERICHOST
104 NI_NAMEREQD
105 NI_NUMERICSERV
106 NI_NUMERICSCOPE
107 NI_DGRAM
108 
109 EAI_AGAIN
110 EAI_BADFLAGS
111 EAI_FAIL
112 EAI_FAMILY
113 EAI_MEMORY
114 EAI_NONAME
115 
116 EAI_SERVICE
117 EAI_SOCKTYPE
118 EAI_SYSTEM
119 EAI_OVERFLOW
120 
121 void         endhostent();
122 void         endnetent();
123 void         endprotoent();
124 void         endservent();
125 void         freeaddrinfo(addrinfo*);
126 const(char)* gai_strerror(int);
127 int          getaddrinfo(const(char)*, const(char)*, const(addrinfo)*, addrinfo**);
128 hostent*     gethostbyaddr(const(void)*, socklen_t, int);
129 hostent*     gethostbyname(const(char)*);
130 hostent*     gethostent();
131 int          getnameinfo(const(sockaddr)*, socklen_t, char*, socklen_t, char*, socklen_t, int);
132 netent*      getnetbyaddr(uint32_t, int);
133 netent*      getnetbyname(const(char)*);
134 netent*      getnetent();
135 protoent*    getprotobyname(const(char)*);
136 protoent*    getprotobynumber(int);
137 protoent*    getprotoent();
138 servent*     getservbyname(const(char)*, const(char)*);
139 servent*     getservbyport(int, const(char)*);
140 servent*     getservent();
141 void         sethostent(int);
142 void         setnetent(int);
143 void         setprotoent(int);
144 void         setservent(int);
145 */
146 
147 version (CRuntime_Glibc)
148 {
149     struct hostent
150     {
151         char*   h_name;
152         char**  h_aliases;
153         int     h_addrtype;
154         int     h_length;
155         char**  h_addr_list;
156         char*   h_addr() @property { return h_addr_list[0]; } // non-standard
157     }
158 
159     struct netent
160     {
161         char*   n_name;
162         char**  n_aliases;
163         int     n_addrtype;
164         uint32_t n_net;
165     }
166 
167     struct protoent
168     {
169         char*   p_name;
170         char**  p_aliases;
171         int     p_proto;
172     }
173 
174     struct servent
175     {
176         char*   s_name;
177         char**  s_aliases;
178         int     s_port;
179         char*   s_proto;
180     }
181 
182     enum IPPORT_RESERVED = 1024;
183 
184     //h_errno
185 
186     enum HOST_NOT_FOUND = 1;
187     enum NO_DATA        = 4;
188     enum NO_RECOVERY    = 3;
189     enum TRY_AGAIN      = 2;
190 
191     struct addrinfo
192     {
193         int         ai_flags;
194         int         ai_family;
195         int         ai_socktype;
196         int         ai_protocol;
197         socklen_t   ai_addrlen;
198         sockaddr*   ai_addr;
199         char*       ai_canonname;
200         addrinfo*   ai_next;
201     }
202 
203     enum AI_PASSIVE         = 0x1;
204     enum AI_CANONNAME       = 0x2;
205     enum AI_NUMERICHOST     = 0x4;
206     enum AI_NUMERICSERV     = 0x400;
207     enum AI_V4MAPPED        = 0x8;
208     enum AI_ALL             = 0x10;
209     enum AI_ADDRCONFIG      = 0x20;
210 
211     enum NI_NOFQDN          = 4;
212     enum NI_NUMERICHOST     = 1;
213     enum NI_NAMEREQD        = 8;
214     enum NI_NUMERICSERV     = 2;
215     //enum NI_NUMERICSCOPE    = ?;
216     enum NI_DGRAM           = 16;
217     enum NI_MAXHOST         = 1025; // non-standard
218     enum NI_MAXSERV         = 32;   // non-standard
219 
220     enum EAI_AGAIN          = -3;
221     enum EAI_BADFLAGS       = -1;
222     enum EAI_FAIL           = -4;
223     enum EAI_FAMILY         = -6;
224     enum EAI_MEMORY         = -10;
225     enum EAI_NONAME         = -2;
226     enum EAI_SERVICE        = -8;
227     enum EAI_SOCKTYPE       = -7;
228     enum EAI_SYSTEM         = -11;
229     enum EAI_OVERFLOW       = -12;
230 }
231 else version (Darwin)
232 {
233     struct hostent
234     {
235         char*   h_name;
236         char**  h_aliases;
237         int     h_addrtype;
238         int     h_length;
239         char**  h_addr_list;
240         char*   h_addr() @property { return h_addr_list[0]; } // non-standard
241     }
242 
243     struct netent
244     {
245         char*   n_name;
246         char**  n_aliases;
247         int     n_addrtype;
248         uint32_t n_net;
249     }
250 
251     struct protoent
252     {
253         char*   p_name;
254         char**  p_aliases;
255         int     p_proto;
256     }
257 
258     struct servent
259     {
260         char*   s_name;
261         char**  s_aliases;
262         int     s_port;
263         char*   s_proto;
264     }
265 
266     enum IPPORT_RESERVED = 1024;
267 
268     //h_errno
269 
270     enum HOST_NOT_FOUND = 1;
271     enum NO_DATA        = 4;
272     enum NO_RECOVERY    = 3;
273     enum TRY_AGAIN      = 2;
274 
275     struct addrinfo
276     {
277         int         ai_flags;
278         int         ai_family;
279         int         ai_socktype;
280         int         ai_protocol;
281         socklen_t   ai_addrlen;
282         char*       ai_canonname;
283         sockaddr*   ai_addr;
284         addrinfo*   ai_next;
285     }
286 
287     enum AI_PASSIVE         = 0x1;
288     enum AI_CANONNAME       = 0x2;
289     enum AI_NUMERICHOST     = 0x4;
290     enum AI_NUMERICSERV     = 0x1000;
291     enum AI_V4MAPPED        = 0x800;
292     enum AI_ALL             = 0x100;
293     enum AI_ADDRCONFIG      = 0x400;
294 
295     enum NI_NOFQDN          = 0x1;
296     enum NI_NUMERICHOST     = 0x2;
297     enum NI_NAMEREQD        = 0x4;
298     enum NI_NUMERICSERV     = 0x8;
299     //enum NI_NUMERICSCOPE    = ?;
300     enum NI_DGRAM           = 0x10;
301     enum NI_MAXHOST         = 1025; // non-standard
302     enum NI_MAXSERV         = 32;   // non-standard
303 
304     enum EAI_AGAIN          = 2;
305     enum EAI_BADFLAGS       = 3;
306     enum EAI_FAIL           = 4;
307     enum EAI_FAMILY         = 5;
308     enum EAI_MEMORY         = 6;
309     enum EAI_NONAME         = 8;
310     enum EAI_SERVICE        = 9;
311     enum EAI_SOCKTYPE       = 10;
312     enum EAI_SYSTEM         = 11;
313     enum EAI_OVERFLOW       = 14;
314 }
315 else version (FreeBSD)
316 {
317     struct hostent
318     {
319         char*   h_name;
320         char**  h_aliases;
321         int     h_addrtype;
322         int     h_length;
323         char**  h_addr_list;
324         extern (D) char* h_addr() @property { return h_addr_list[0]; } // non-standard
325     }
326 
327     struct netent
328     {
329         char*   n_name;
330         char**  n_aliases;
331         int     n_addrtype;
332         uint32_t n_net;
333     }
334 
335     struct protoent
336     {
337         char*   p_name;
338         char**  p_aliases;
339         int     p_proto;
340     }
341 
342     struct servent
343     {
344         char*   s_name;
345         char**  s_aliases;
346         int     s_port;
347         char*   s_proto;
348     }
349 
350     enum IPPORT_RESERVED = 1024;
351 
352     //h_errno
353 
354     enum HOST_NOT_FOUND = 1;
355     enum NO_DATA        = 4;
356     enum NO_RECOVERY    = 3;
357     enum TRY_AGAIN      = 2;
358 
359     struct addrinfo
360     {
361         int         ai_flags;
362         int         ai_family;
363         int         ai_socktype;
364         int         ai_protocol;
365         socklen_t   ai_addrlen;
366         char*       ai_canonname;
367         sockaddr*   ai_addr;
368         addrinfo*   ai_next;
369     }
370 
371     enum AI_PASSIVE         = 0x1;
372     enum AI_CANONNAME       = 0x2;
373     enum AI_NUMERICHOST     = 0x4;
374     enum AI_NUMERICSERV     = 0x8;
375     enum AI_V4MAPPED        = 0x800;
376     enum AI_ALL             = 0x100;
377     enum AI_ADDRCONFIG      = 0x400;
378 
379     enum NI_NOFQDN          = 0x1;
380     enum NI_NUMERICHOST     = 0x2;
381     enum NI_NAMEREQD        = 0x4;
382     enum NI_NUMERICSERV     = 0x8;
383     //enum NI_NUMERICSCOPE    = ?;
384     enum NI_DGRAM           = 0x10;
385     enum NI_MAXHOST         = 1025; // non-standard
386     enum NI_MAXSERV         = 32;   // non-standard
387 
388     enum EAI_AGAIN          = 2;
389     enum EAI_BADFLAGS       = 3;
390     enum EAI_FAIL           = 4;
391     enum EAI_FAMILY         = 5;
392     enum EAI_MEMORY         = 6;
393     enum EAI_NONAME         = 8;
394     enum EAI_SERVICE        = 9;
395     enum EAI_SOCKTYPE       = 10;
396     enum EAI_SYSTEM         = 11;
397     enum EAI_OVERFLOW       = 14;
398 }
399 else version (NetBSD)
400 {
401     struct hostent
402     {
403         char*   h_name;
404         char**  h_aliases;
405         int     h_addrtype;
406         int     h_length;
407         char**  h_addr_list;
408         extern (D) char* h_addr() @property { return h_addr_list[0]; } // non-standard
409     }
410 
411     struct netent
412     {
413         char*   n_name;
414         char**  n_aliases;
415         int     n_addrtype;
416         uint32_t n_net;
417 /+ todo
418 #if (defined(__sparc__) && defined(_LP64)) || \
419     (defined(__sh__) && defined(_LP64) && (_BYTE_ORDER == _BIG_ENDIAN))
420         int             __n_pad0;       /* ABI compatibility */
421 #endif
422         uint32_t        n_net;          /*%< network # */
423 #if defined(__alpha__) || (defined(__i386__) && defined(_LP64)) || \
424     (defined(__sh__) && defined(_LP64) && (_BYTE_ORDER == _LITTLE_ENDIAN))
425         int             __n_pad0;       /* ABI compatibility */
426 #endif
427 
428 +/
429     }
430 
431     struct protoent
432     {
433         char*   p_name;
434         char**  p_aliases;
435         int     p_proto;
436     }
437 
438     struct servent
439     {
440         char*   s_name;
441         char**  s_aliases;
442         int     s_port;
443         char*   s_proto;
444     }
445 
446     enum IPPORT_RESERVED = 1024;
447 
448     //h_errno
449 
450     enum HOST_NOT_FOUND = 1;
451     enum NO_DATA        = 4;
452     enum NO_RECOVERY    = 3;
453     enum TRY_AGAIN      = 2;
454 
455     struct addrinfo
456     {
457         int         ai_flags;
458         int         ai_family;
459         int         ai_socktype;
460         int         ai_protocol;
461 /+todo
462 #if defined(__sparc__) && defined(_LP64)
463         int             __ai_pad0;      /* ABI compatibility */
464 #endif
465 +/
466         socklen_t   ai_addrlen;
467 /+todo
468 #if defined(__alpha__) || (defined(__i386__) && defined(_LP64))
469         int             __ai_pad0;      /* ABI compatibility */
470 #endif
471 +/
472         char*       ai_canonname;
473         sockaddr*   ai_addr;
474         addrinfo*   ai_next;
475     }
476 
477     enum AI_PASSIVE         = 0x1;
478     enum AI_CANONNAME       = 0x2;
479     enum AI_NUMERICHOST     = 0x4;
480     enum AI_NUMERICSERV     = 0x8;
481     enum AI_V4MAPPED        = 0x800;
482     enum AI_ALL             = 0x100;
483     enum AI_ADDRCONFIG      = 0x400;
484 
485     enum NI_NOFQDN          = 0x1;
486     enum NI_NUMERICHOST     = 0x2;
487     enum NI_NAMEREQD        = 0x4;
488     enum NI_NUMERICSERV     = 0x8;
489     enum NI_DGRAM           = 0x10;
490     enum NI_WITHSCOPEID     = 0x00000020;
491     enum NI_NUMERICSCOPE    = 0x00000040;
492     enum NI_MAXHOST         = 1025; // non-standard
493     enum NI_MAXSERV         = 32;   // non-standard
494 
495     enum EAI_AGAIN          = 2;
496     enum EAI_BADFLAGS       = 3;
497     enum EAI_FAIL           = 4;
498     enum EAI_FAMILY         = 5;
499     enum EAI_MEMORY         = 6;
500     enum EAI_NONAME         = 8;
501     enum EAI_SERVICE        = 9;
502     enum EAI_SOCKTYPE       = 10;
503     enum EAI_SYSTEM         = 11;
504     enum EAI_OVERFLOW       = 14;
505 }
506 else version (OpenBSD)
507 {
508     struct hostent
509     {
510         char*     h_name;
511         char**    h_aliases;
512         int       h_addrtype;
513         int       h_length;
514         char**    h_addr_list;
515         extern (D) char* h_addr() @property { return h_addr_list[0]; } // non-standard
516     }
517 
518     struct netent
519     {
520         char*     n_name;
521         char**    n_aliases;
522         int       n_addrtype;
523         in_addr_t n_net;
524     }
525 
526     struct protoent
527     {
528         char*     p_name;
529         char**    p_aliases;
530         int       p_proto;
531     }
532 
533     struct servent
534     {
535         char*     s_name;
536         char**    s_aliases;
537         int       s_port;
538         char*     s_proto;
539     }
540 
541     enum IPPORT_RESERVED = 1024;
542 
543     //h_errno
544 
545     enum NETDB_INTERNAL = -1;
546     enum NETDB_SUCCESS  = 0;
547     enum HOST_NOT_FOUND = 1;
548     enum NO_DATA        = 4;
549     enum NO_RECOVERY    = 3;
550     enum TRY_AGAIN      = 2;
551 
552     struct addrinfo
553     {
554         int         ai_flags;
555         int         ai_family;
556         int         ai_socktype;
557         int         ai_protocol;
558         socklen_t   ai_addrlen;
559         char*       ai_canonname;
560         sockaddr*   ai_addr;
561         addrinfo*   ai_next;
562     }
563 
564     enum AI_PASSIVE         = 0x1;
565     enum AI_CANONNAME       = 0x2;
566     enum AI_NUMERICHOST     = 0x4;
567     enum AI_EXT             = 0x8;
568     enum AI_NUMERICSERV     = 0x10;
569     enum AI_V4MAPPED        = 0; // Not supported
570     enum AI_FQDN            = 0x20;
571     enum AI_ADDRCONFIG      = 0x40;
572     enum AI_MASK            = AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV | AI_FQDN | AI_ADDRCONFIG;
573 
574     enum NI_NUMERICHOST     = 1;
575     enum NI_NUMERICSERV     = 2;
576     enum NI_NOFQDN          = 4;
577     enum NI_NAMEREQD        = 8;
578     enum NI_DGRAM           = 16;
579     //enum NI_NUMERICSCOPE    = 32;
580     enum NI_MAXHOST         = 256; // non-standard
581     enum NI_MAXSERV         = 32;  // non-standard
582 
583     enum EAI_NONAME         = -1;
584     enum EAI_BADFLAGS       = -2;
585     enum EAI_AGAIN          = -3;
586     enum EAI_FAIL           = -4;
587     enum EAI_NODATA         = -5;
588     enum EAI_FAMILY         = -6;
589     enum EAI_SOCKTYPE       = -7;
590     enum EAI_SERVICE        = -8;
591     enum EAI_ADDRFAMILY     = -9;
592     enum EAI_MEMORY         = -10;
593     enum EAI_SYSTEM         = -11;
594     enum EAI_BADHINTS       = -12;
595     enum EAI_PROTOCOL       = -13;
596     enum EAI_OVERFLOW       = -14;
597 }
598 else version (DragonFlyBSD)
599 {
600     /*
601      * Error return codes from gethostbyname() and gethostbyaddr()
602      * (left in h_errno).
603      */
604     struct hostent
605     {
606         char*   h_name;
607         char**  h_aliases;
608         int     h_addrtype;
609         int     h_length;
610         char**  h_addr_list;
611         extern (D) char* h_addr() @property { return h_addr_list[0]; } // non-standard
612     }
613 
614     struct netent
615     {
616         char*   n_name;
617         char**  n_aliases;
618         int     n_addrtype;
619         uint32_t n_net;
620     }
621 
622     struct protoent
623     {
624         char*   p_name;
625         char**  p_aliases;
626         int     p_proto;
627     }
628 
629     struct servent
630     {
631         char*   s_name;
632         char**  s_aliases;
633         int     s_port;
634         char*   s_proto;
635     }
636 
637     struct addrinfo
638     {
639         int         ai_flags;
640         int         ai_family;
641         int         ai_socktype = SOCK_STREAM;           /* socktype default value required to be able to perform getAddrInfo on DragonFlyBSD
642                                                           * without socktype set, you get 'servname not supported for ai_socktype'
643                                                           */
644         int         ai_protocol;
645         socklen_t   ai_addrlen;
646         char*       ai_canonname;
647         sockaddr*   ai_addr;
648         addrinfo*   ai_next;
649     }
650 
651     enum IPPORT_RESERVED = 1024;
652 
653     enum NETDB_INTERNAL = -1;
654     enum NETDB_SUCCESS  = 0;
655     enum HOST_NOT_FOUND = 1;
656     enum TRY_AGAIN      = 2;
657     enum NO_RECOVERY    = 3;
658     enum NO_DATA        = 4;
659     enum NO_ADDRESS     = NO_DATA;
660 
661     //enum EAI_ADDRFAMILY     = 1; // deprecated
662     enum EAI_AGAIN          = 2;
663     enum EAI_BADFLAGS       = 3;
664     enum EAI_FAIL           = 4;
665     enum EAI_FAMILY         = 5;
666     enum EAI_MEMORY         = 6;
667     //enum EAI_NODATA         = 7; // deprecated
668     enum EAI_NONAME         = 8;
669     enum EAI_SERVICE        = 9;
670     enum EAI_SOCKTYPE       = 10;
671     enum EAI_SYSTEM         = 11;
672     enum EAI_BADHINTS       = 12;
673     enum EAI_PROTOCOL       = 13;
674     enum EAI_OVERFLOW       = 14;
675 
676     enum AI_PASSIVE         = 0x001;
677     enum AI_CANONNAME       = 0x002;
678     enum AI_NUMERICHOST     = 0x004;
679     enum AI_NUMERICSERV     = 0x008;
680     enum AI_MASK            = (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV | AI_ADDRCONFIG);   // valid flags for addrinfo (not a standard def, apps should not use it)
681     enum AI_ALL             = 0x100;
682     enum AI_V4MAPPED_CFG    = 0x200;
683     enum AI_ADDRCONFIG      = 0x400;
684     enum AI_V4MAPPED        = 0x800;
685     enum AI_DEFAULT         = (AI_V4MAPPED_CFG | AI_ADDRCONFIG);
686 
687     enum NI_MAXHOST         = 1025; // non-standard
688     enum NI_MAXSERV         = 32;   // non-standard
689 
690     enum NI_NOFQDN          = 0x01;
691     enum NI_NUMERICHOST     = 0x02;
692     enum NI_NAMEREQD        = 0x04;
693     enum NI_NUMERICSERV     = 0x08;
694     enum NI_DGRAM           = 0x10;
695     //enum NI_WITHSCOPEID     = 0x20; // deprecated
696     enum NI_NUMERICSCOPE    = 0x40;
697 
698 }
699 else version (Solaris)
700 {
701     struct hostent
702     {
703         char* h_name;
704         char** h_aliases;
705         int h_addrtype;
706         int h_length;
707         char** h_addr_list;
708 
709         extern (D) char* h_addr() @property { return h_addr_list[0]; } // non-standard
710     }
711 
712     struct netent
713     {
714         char* n_name;
715         char** n_aliases;
716         int n_addrtype;
717         uint32_t n_net;
718     }
719 
720     struct protoent
721     {
722         char* p_name;
723         char** p_aliases;
724         int p_proto;
725     }
726 
727     struct servent
728     {
729         char* s_name;
730         char** s_aliases;
731         int s_port;
732         char* s_proto;
733     }
734 
735     enum HOST_NOT_FOUND = 1;
736     enum TRY_AGAIN = 2;
737     enum NO_RECOVERY = 3;
738     enum NO_DATA = 4;
739 
740     struct addrinfo
741     {
742         int ai_flags;
743         int ai_family;
744         int ai_socktype;
745         int ai_protocol;
746 
747         version (SPARC64)
748             int _ai_pad;
749 
750         socklen_t ai_addrlen;
751         char* ai_canonname;
752         sockaddr* ai_addr;
753         addrinfo* ai_next;
754     }
755 
756     enum AI_PASSIVE = 0x0008;
757     enum AI_CANONNAME = 0x0010;
758     enum AI_NUMERICHOST = 0x0020;
759     enum AI_NUMERICSERV = 0x0040;
760     enum AI_V4MAPPED = 0x0001;
761     enum AI_ALL = 0x0002;
762     enum AI_ADDRCONFIG = 0x0004;
763 
764     enum NI_NOFQDN = 0x0001;
765     enum NI_NUMERICHOST = 0x0002;
766     enum NI_NAMEREQD = 0x0004;
767     enum NI_NUMERICSERV = 0x0008;
768     enum NI_DGRAM = 0x0010;
769     enum NI_WITHSCOPEID = 0x0020;
770     enum NI_NUMERICSCOPE = 0x0040;
771     enum NI_MAXHOST = 1025;
772     enum NI_MAXSERV = 32;
773 
774     enum EAI_AGAIN = 2;
775     enum EAI_BADFLAGS = 3;
776     enum EAI_FAIL = 4;
777     enum EAI_FAMILY = 5;
778     enum EAI_MEMORY = 6;
779     enum EAI_NONAME = 8;
780     enum EAI_SERVICE = 9;
781     enum EAI_SOCKTYPE = 10;
782     enum EAI_SYSTEM = 11;
783     enum EAI_OVERFLOW = 14;
784     enum EAI_PROTOCOL = 13;
785     enum EAI_MAX = 14;
786 }
787 else version (CRuntime_Bionic)
788 {
789     struct hostent
790     {
791         char*   h_name;
792         char**  h_aliases;
793         int     h_addrtype;
794         int     h_length;
795         char**  h_addr_list;
796         extern (D) char* h_addr() @property { return h_addr_list[0]; } // non-standard
797     }
798 
799     struct netent
800     {
801         char*   n_name;
802         char**  n_aliases;
803         int     n_addrtype;
804         uint32_t n_net;
805     }
806 
807     struct protoent
808     {
809         char*   p_name;
810         char**  p_aliases;
811         int     p_proto;
812     }
813 
814     struct servent
815     {
816         char*   s_name;
817         char**  s_aliases;
818         int     s_port;
819         char*   s_proto;
820     }
821 
822     enum IPPORT_RESERVED = 1024;
823 
824     enum HOST_NOT_FOUND = 1;
825     enum NO_DATA        = 4;
826     enum NO_RECOVERY    = 3;
827     enum TRY_AGAIN      = 2;
828 
829     struct addrinfo
830     {
831         int         ai_flags;
832         int         ai_family;
833         int         ai_socktype;
834         int         ai_protocol;
835         socklen_t   ai_addrlen;
836         char*       ai_canonname;
837         sockaddr*   ai_addr;
838         addrinfo*   ai_next;
839     }
840 
841     enum AI_PASSIVE         = 0x1;
842     enum AI_CANONNAME       = 0x2;
843     enum AI_NUMERICHOST     = 0x4;
844     enum AI_NUMERICSERV     = 0x8;
845     enum AI_V4MAPPED        = 0x800;
846     enum AI_ALL             = 0x100;
847     enum AI_ADDRCONFIG      = 0x400;
848 
849     enum NI_NOFQDN          = 0x1;
850     enum NI_NUMERICHOST     = 0x2;
851     enum NI_NAMEREQD        = 0x4;
852     enum NI_NUMERICSERV     = 0x8;
853     enum NI_DGRAM           = 0x10;
854     enum NI_MAXHOST         = 1025; // non-standard
855     enum NI_MAXSERV         = 32;   // non-standard
856 
857     enum EAI_AGAIN          = 2;
858     enum EAI_BADFLAGS       = 3;
859     enum EAI_FAIL           = 4;
860     enum EAI_FAMILY         = 5;
861     enum EAI_MEMORY         = 6;
862     enum EAI_NONAME         = 8;
863     enum EAI_SERVICE        = 9;
864     enum EAI_SOCKTYPE       = 10;
865     enum EAI_SYSTEM         = 11;
866     enum EAI_OVERFLOW       = 14;
867 }
868 else version (CRuntime_Musl)
869 {
870     struct hostent
871     {
872         char*   h_name;
873         char**  h_aliases;
874         int     h_addrtype;
875         int     h_length;
876         char**  h_addr_list;
877         char*   h_addr() @property { return h_addr_list[0]; } // non-standard
878     }
879 
880     struct netent
881     {
882         char*     n_name;
883         char**    n_aliases;
884         int       n_addrtype;
885         uint32_t n_net;
886     }
887 
888     struct protoent
889     {
890         char*   p_name;
891         char**  p_aliases;
892         int     p_proto;
893     }
894 
895     struct servent
896     {
897         char*     s_name;
898         char**    s_aliases;
899         int       s_port;
900         char*     s_proto;
901     }
902 
903     struct addrinfo
904     {
905         int         ai_flags;
906         int         ai_family;
907         int         ai_socktype;
908         int         ai_protocol;
909         socklen_t   ai_addrlen;
910         sockaddr*   ai_addr;
911         char*       ai_canonname;
912         addrinfo*   ai_next;
913     }
914 
915     enum {
916         AI_PASSIVE         = 0x1,
917         AI_CANONNAME       = 0x2,
918         AI_NUMERICHOST     = 0x4,
919         AI_NUMERICSERV     = 0x400,
920         AI_V4MAPPED        = 0x8,
921         AI_ALL             = 0x10,
922         AI_ADDRCONFIG      = 0x20,
923     }
924     enum {
925         NI_NUMERICHOST     = 1,
926         NI_NUMERICSERV     = 2,
927         NI_NOFQDN          = 4,
928         NI_NAMEREQD        = 8,
929         NI_DGRAM           = 16,
930         NI_MAXSERV         = 32,
931         NI_MAXHOST         = 255,
932     }
933     enum {
934         EAI_BADFLAGS       = -1,
935         EAI_NONAME         = -2,
936         EAI_AGAIN          = -3,
937         EAI_FAIL           = -4,
938         EAI_FAMILY         = -6,
939         EAI_SOCKTYPE       = -7,
940         EAI_SERVICE        = -8,
941         EAI_MEMORY         = -10,
942         EAI_SYSTEM         = -11,
943         EAI_OVERFLOW       = -12,
944     }
945 }
946 else version (CRuntime_UClibc)
947 {
948     struct hostent
949     {
950         char*   h_name;
951         char**  h_aliases;
952         int     h_addrtype;
953         int     h_length;
954         char**  h_addr_list;
955         extern (D) char* h_addr() @property { return h_addr_list[0]; } // non-standard
956     }
957 
958     struct netent
959     {
960         char*   n_name;
961         char**  n_aliases;
962         int     n_addrtype;
963         uint32_t n_net;
964     }
965 
966     struct protoent
967     {
968         char*   p_name;
969         char**  p_aliases;
970         int     p_proto;
971     }
972 
973     struct servent
974     {
975         char*   s_name;
976         char**  s_aliases;
977         int     s_port;
978         char*   s_proto;
979     }
980 
981     enum IPPORT_RESERVED = 1024;
982 
983     enum HOST_NOT_FOUND = 1;
984     enum NO_DATA        = 4;
985     enum NO_RECOVERY    = 3;
986     enum TRY_AGAIN      = 2;
987 
988     struct addrinfo
989     {
990         int         ai_flags;
991         int         ai_family;
992         int         ai_socktype;
993         int         ai_protocol;
994         socklen_t   ai_addrlen;
995         sockaddr*   ai_addr;
996         char*       ai_canonname;
997         addrinfo*   ai_next;
998     }
999 
1000     enum AI_PASSIVE         = 0x1;
1001     enum AI_CANONNAME       = 0x2;
1002     enum AI_NUMERICHOST     = 0x4;
1003     enum AI_NUMERICSERV     = 0x400;
1004     enum AI_V4MAPPED        = 0x8;
1005     enum AI_ALL             = 0x10;
1006     enum AI_ADDRCONFIG      = 0x20;
1007 
1008     enum NI_NOFQDN          = 4;
1009     enum NI_NUMERICHOST     = 1;
1010     enum NI_NAMEREQD        = 8;
1011     enum NI_NUMERICSERV     = 2;
1012     enum NI_DGRAM           = 16;
1013     enum NI_MAXHOST         = 1025; // non-standard
1014     enum NI_MAXSERV         = 32;   // non-standard
1015 
1016     enum EAI_AGAIN          = -3;
1017     enum EAI_BADFLAGS       = -1;
1018     enum EAI_FAIL           = -4;
1019     enum EAI_FAMILY         = -6;
1020     enum EAI_MEMORY         = -10;
1021     enum EAI_NONAME         = -2;
1022     enum EAI_SERVICE        = -8;
1023     enum EAI_SOCKTYPE       = -7;
1024     enum EAI_SYSTEM         = -11;
1025     enum EAI_OVERFLOW       = -12;
1026 
1027     enum EAI_NODATA         = -5;
1028     enum EAI_ADDRFAMILY     = -9;
1029     enum EAI_INPROGRESS     = -100;
1030     enum EAI_CANCELED       = -101;
1031     enum EAI_NOTCANCELED    = -102;
1032     enum EAI_ALLDONE        = -103;
1033     enum EAI_INTR           = -104;
1034     enum EAI_IDN_ENCODE     = -105;
1035 }
1036 else
1037 {
1038     static assert(false, "Unsupported platform");
1039 }
1040 
1041 void         endhostent();
1042 void         endnetent();
1043 void         endprotoent();
1044 void         endservent();
1045 void         freeaddrinfo(addrinfo*);
1046 const(char)* gai_strerror(int);
1047 int          getaddrinfo(const(char)*, const(char)*, const(addrinfo)*, addrinfo**);
1048 hostent*     gethostbyaddr(const(void)*, socklen_t, int);
1049 hostent*     gethostbyname(const(char)*);
1050 hostent*     gethostent();
1051 int          getnameinfo(const(sockaddr)*, socklen_t, char*, socklen_t, char*, socklen_t, int);
1052 netent*      getnetbyaddr(uint32_t, int);
1053 netent*      getnetbyname(const(char)*);
1054 netent*      getnetent();
1055 protoent*    getprotobyname(const(char)*);
1056 protoent*    getprotobynumber(int);
1057 protoent*    getprotoent();
1058 servent*     getservbyname(const(char)*, const(char)*);
1059 servent*     getservbyport(int, const(char)*);
1060 servent*     getservent();
1061 void         sethostent(int);
1062 void         setnetent(int);
1063 void         setprotoent(int);
1064 void         setservent(int);