2 Copyright (C) 2008 Mathias Gottschlag
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in the
6 Software without restriction, including without limitation the rights to use,
7 copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
8 Software, and to permit persons to whom the Software is furnished to do so,
9 subject to the following conditions:
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16 PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
19 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 #include <arpa/inet.h>
24 #include <sys/socket.h>
35 void endprotoent(void)
41 struct hostent
*gethostbyaddr(const void *addr
, size_t len
, int type
)
45 struct hostent
*gethostbyname(const char *name
)
49 struct hostent
*gethostent(void)
53 struct netent
*getnetbyaddr(uint32_t net
, int type
)
57 struct netent
*getnetbyname(const char *name
)
61 struct netent
*getnetent(void)
65 struct protoent
*getprotobyname(const char *name
)
69 struct protoent
*getprotobynumber(int proto
)
73 struct protoent
*getprotoent(void)
77 struct servent
*getservbyname(const char *name
, const char *proto
)
81 struct servent
*getservbyport(int port
, const char *proto
)
85 struct servent
*getservent(void)
90 void sethostent(int stayopen
)
93 void setnetent(int stayopen
)
96 void setprotoent(int stayopen
)
99 void setservent(int stayopen
)
102 void freeaddrinfo(struct addrinfo
*info
)
104 if (info
->ai_canonname
)
105 free(info
->ai_canonname
);
108 int getaddrinfo(const char *nodename
, const char *servname
, const struct addrinfo
* hints
, struct addrinfo
** res
)
111 struct sockaddr_in addr
;
112 addr
.sin_family
= AF_INET
;
113 if ((nodename
== 0) || !strcmp(nodename
, "") || !strcmp(nodename
, "localhost"))
115 ((char*)&addr
.sin_addr
)[0] = 0;
116 ((char*)&addr
.sin_addr
)[1] = 0;
117 ((char*)&addr
.sin_addr
)[2] = 0;
118 ((char*)&addr
.sin_addr
)[3] = 0;
122 struct hostent
*host
= gethostbyname(nodename
);
127 memcpy(&addr
.sin_addr
, host
->h_addr_list
[0], 4);
131 if ((servname
== 0) || !strcmp(servname
, ""))
135 if (isdigit(servname
[0]))
137 addr
.sin_port
= atoi(servname
);
144 struct addrinfo
*addrinfo
= malloc(sizeof(struct addrinfo
));
145 memcpy(addrinfo
, hints
, sizeof(struct addrinfo
));
146 addrinfo
->ai_family
= addr
.sin_family
;
147 addrinfo
->ai_addrlen
= sizeof(struct sockaddr_in
);
148 addrinfo
->ai_addr
= malloc(sizeof(struct sockaddr_in
));
149 memcpy(addrinfo
->ai_addr
, &addr
, sizeof(addr
));
151 addrinfo
->ai_canonname
= strdup(nodename
);
153 addrinfo
->ai_canonname
= 0;
154 addrinfo
->ai_next
= 0;
159 const char *gai_strerror(int error
)