37 #include "ruby/config.h" 39 #include RUBY_EXTCONF_H 42 #include <sys/types.h> 44 #include <sys/socket.h> 45 #include <netinet/in.h> 46 #if defined(HAVE_ARPA_INET_H) 47 #include <arpa/inet.h> 49 #if defined(HAVE_ARPA_NAMESER_H) 50 #include <arpa/nameser.h> 53 #if defined(HAVE_RESOLV_H) 58 #if defined(_MSC_VER) && _MSC_VER <= 1200 63 #define snprintf _snprintf 73 #ifndef HAVE_TYPE_SOCKLEN_T 100 {PF_INET6,
sizeof(
struct in6_addr),
101 sizeof(struct sockaddr_in6),
102 offsetof(struct sockaddr_in6, sin6_addr)},
107 {
PF_INET,
sizeof(
struct in_addr),
108 sizeof(struct sockaddr_in),
109 offsetof(struct sockaddr_in, sin_addr)},
113 #define ENI_NOSOCKET 0 114 #define ENI_NOSERVNAME 1 115 #define ENI_NOHOSTNAME 2 143 family = sa->sa_family;
144 for (i = 0; afdl[i].a_af; i++)
145 if (afdl[i].a_af == family) {
152 if (len != afd->a_socklen)
return ENI_SALEN;
154 port = ((
struct sockinet *)sa)->si_port;
155 addr = (
char *)sa + afd->a_off;
157 if (serv ==
NULL || servlen == 0) {
160 snprintf(numserv,
sizeof(numserv),
"%d", ntohs(port));
161 if (
strlen(numserv) + 1 > servlen)
163 strcpy(serv, numserv);
165 #if defined(HAVE_GETSERVBYPORT) 166 struct servent *sp = getservbyport(port, (flags &
NI_DGRAM) ?
"udp" :
"tcp");
168 if (
strlen(sp->s_name) + 1 > servlen)
170 strcpy(serv, sp->s_name);
178 switch (sa->sa_family) {
180 v4a = ntohl(((
struct sockaddr_in *)sa)->sin_addr.s_addr);
190 pfx = ((
struct sockaddr_in6 *)sa)->sin6_addr.s6_addr8[0];
192 pfx = ((
struct sockaddr_in6 *)sa)->sin6_addr.s6_addr[0];
194 if (pfx == 0 || pfx == 0xfe || pfx == 0xff)
199 if (host ==
NULL || hostlen == 0) {
202 if (
inet_ntop(afd->a_af, addr, numaddr,
sizeof(numaddr))
205 if (
strlen(numaddr) > hostlen)
207 strcpy(host, numaddr);
210 hp = getipnodebyaddr(addr, afd->a_addrlen, afd->a_af, &h_error);
212 hp = gethostbyaddr(addr, afd->a_addrlen, afd->a_af);
218 p =
strchr(hp->h_name,
'.');
221 if (
strlen(hp->h_name) + 1 > hostlen) {
227 strcpy(host, hp->h_name);
234 if (
inet_ntop(afd->a_af, addr, numaddr,
sizeof(numaddr))
237 if (
strlen(numaddr) > hostlen)
239 strcpy(host, numaddr);
#define VALIDATE_SOCKLEN(addr, len)
size_t strlen(const char *)
if(len<=MAX_WORD_LENGTH &&len >=MIN_WORD_LENGTH)
const char * inet_ntop(int af, const void *addr, char *numaddr, size_t numaddr_len)
char * strchr(char *, char)
register unsigned int len
#define IN_EXPERIMENTAL(i)
int getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, socklen_t hostlen, char *serv, socklen_t servlen, int flags)