37 #include "ruby/config.h" 39 #include RUBY_EXTCONF_H 42 #include <sys/types.h> 44 #if defined(__BEOS__) && !defined(__HAIKU__) && !defined(BONE) 45 # include <net/socket.h> 47 # include <sys/socket.h> 49 #include <netinet/in.h> 50 #if defined(HAVE_ARPA_INET_H) 51 #include <arpa/inet.h> 53 #if defined(HAVE_ARPA_NAMESER_H) 54 #include <arpa/nameser.h> 57 #if defined(HAVE_RESOLV_H) 64 #define snprintf _snprintf 74 #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 121 #ifndef HAVE_INET_NTOP 123 inet_ntop(
int af,
const void *addr,
char *numaddr,
size_t numaddr_len)
125 #ifdef HAVE_INET_NTOA 127 memcpy(&in.s_addr, addr,
sizeof(in.s_addr));
128 snprintf(numaddr, numaddr_len,
"%s", inet_ntoa(in));
130 unsigned long x = ntohl(*(
unsigned long*)addr);
131 snprintf(numaddr, numaddr_len,
"%d.%d.%d.%d",
132 (
int) (x>>24) & 0xff, (
int) (x>>16) & 0xff,
133 (
int) (x>> 8) & 0xff, (
int) (x>> 0) & 0xff);
161 family = sa->sa_family;
163 if (
afdl[i].a_af == family) {
172 port = ((
struct sockinet *)sa)->si_port;
175 if (serv ==
NULL || servlen == 0) {
178 snprintf(numserv,
sizeof(numserv),
"%d", ntohs(port));
179 if (
strlen(numserv) + 1 > servlen)
181 strcpy(serv, numserv);
183 #if defined(HAVE_GETSERVBYPORT) 184 struct servent *sp = getservbyport(port, (flags &
NI_DGRAM) ?
"udp" :
"tcp");
186 if (
strlen(sp->s_name) + 1 > servlen)
188 strcpy(serv, sp->s_name);
196 switch (sa->sa_family) {
198 v4a = ntohl(((
struct sockaddr_in *)sa)->sin_addr.s_addr);
208 pfx = ((
struct sockaddr_in6 *)sa)->sin6_addr.s6_addr8[0];
210 pfx = ((
struct sockaddr_in6 *)sa)->sin6_addr.s6_addr[0];
212 if (pfx == 0 || pfx == 0xfe || pfx == 0xff)
217 if (host ==
NULL || hostlen == 0) {
223 if (
strlen(numaddr) > hostlen)
225 strcpy(host, numaddr);
236 p =
strchr(hp->h_name,
'.');
239 if (
strlen(hp->h_name) + 1 > hostlen) {
245 strcpy(host, hp->h_name);
255 if (
strlen(numaddr) > hostlen)
257 strcpy(host, numaddr);
#define VALIDATE_SOCKLEN(addr, len)
size_t strlen(const char *)
if((ID)(DISPID) nameid !=nameid)
#define offsetof(p_type, field)
static const char * inet_ntop(int af, const void *addr, char *numaddr, size_t numaddr_len)
char * strchr(char *, char)
#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)