Ruby  1.9.3p448(2013-06-27revision41675)
Data Structures | Macros | Functions | Variables
getaddrinfo.c File Reference
#include "ruby/config.h"
#include <sys/types.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <ctype.h>
#include "addrinfo.h"
#include "sockport.h"
Include dependency graph for getaddrinfo.c:

Go to the source code of this file.

Data Structures

struct  sockinet
 
struct  afd
 

Macros

#define SUCCESS   0
 
#define ANY   0
 
#define YES   1
 
#define NO   0
 
#define N_INET   0
 
#define PTON_MAX   4
 
#define GET_CANONNAME(ai, str)
 
#define GET_AI(ai, afd, addr, port)
 
#define ERR(err)   { error = (err); goto bad; }
 

Functions

static int get_name __P ((const char *, const struct afd *, struct addrinfo **, char *, struct addrinfo *, int))
 
static int get_addr __P ((const char *, int, struct addrinfo **, struct addrinfo *, int))
 
static int str_isnumber __P ((const char *))
 
char * gai_strerror (int ecode)
 
void freeaddrinfo (struct addrinfo *ai)
 
static int str_isnumber (const char *p)
 
static int inet_pton (int af, const char *hostname, void *pton)
 
int getaddrinfo (const char *hostname, const char *servname, const struct addrinfo *hints, struct addrinfo **res)
 
static int get_name (const char *addr, const struct afd *afd, struct addrinfo **res, char *numaddr, struct addrinfo *pai, int port0)
 
static int get_addr (const char *hostname, int af, struct addrinfo **res, struct addrinfo *pai, int port0)
 

Variables

static const char in_addrany [] = { 0, 0, 0, 0 }
 
static const char in6_addrany []
 
static const char in_loopback [] = { 127, 0, 0, 1 }
 
static const char in6_loopback []
 
static const struct afd afdl []
 
static const char *const ai_errlist []
 

Macro Definition Documentation

#define ANY   0

Definition at line 87 of file getaddrinfo.c.

Referenced by getaddrinfo().

#define ERR (   err)    { error = (err); goto bad; }

Definition at line 195 of file getaddrinfo.c.

Referenced by curses_curs_set(), get_addr(), getaddrinfo(), and window_getbkgd().

#define GET_AI (   ai,
  afd,
  addr,
  port 
)
Value:
{\
char *p;\
if (((ai) = (struct addrinfo *)malloc(sizeof(struct addrinfo) +\
((afd)->a_socklen)))\
== NULL) {\
error = EAI_MEMORY;\
goto free;\
}\
memcpy((ai), pai, sizeof(struct addrinfo));\
(ai)->ai_addr = (struct sockaddr *)((ai) + 1);\
memset((ai)->ai_addr, 0, (afd)->a_socklen);\
SET_SA_LEN((ai)->ai_addr, (ai)->ai_addrlen = (afd)->a_socklen);\
(ai)->ai_addr->sa_family = (ai)->ai_family = (afd)->a_af;\
((struct sockinet *)(ai)->ai_addr)->si_port = (port);\
p = (char *)((ai)->ai_addr);\
memcpy(p + (afd)->a_off, (addr), (afd)->a_addrlen);\
}
if(len<=MAX_WORD_LENGTH &&len >=MIN_WORD_LENGTH)
Definition: name2ctype.h:23841
#define SET_SA_LEN(sa, len)
Definition: sockport.h:39
Win32OLEIDispatch * p
Definition: win32ole.c:778
#define EAI_MEMORY
Definition: addrinfo.h:83
#define NULL
void * malloc()
u_short si_port
Definition: getaddrinfo.c:108
free(psz)

Definition at line 177 of file getaddrinfo.c.

Referenced by get_addr(), get_name(), and getaddrinfo().

#define GET_CANONNAME (   ai,
  str 
)
Value:
if (pai->ai_flags & AI_CANONNAME) {\
if (((ai)->ai_canonname = (char *)malloc(strlen(str) + 1)) != NULL) {\
strcpy((ai)->ai_canonname, (str));\
} else {\
error = EAI_MEMORY;\
goto free;\
}\
}
size_t strlen(const char *)
if(len<=MAX_WORD_LENGTH &&len >=MIN_WORD_LENGTH)
Definition: name2ctype.h:23841
#define AI_CANONNAME
Definition: addrinfo.h:97
#define EAI_MEMORY
Definition: addrinfo.h:83
#define NULL
void * malloc()
free(psz)

Definition at line 167 of file getaddrinfo.c.

Referenced by get_addr(), and get_name().

#define N_INET   0

Referenced by get_addr().

#define NO   0

Definition at line 89 of file getaddrinfo.c.

Referenced by str_isnumber().

#define PTON_MAX   4

Definition at line 139 of file getaddrinfo.c.

Referenced by getaddrinfo().

#define SUCCESS   0

Definition at line 86 of file getaddrinfo.c.

Referenced by get_addr(), get_name(), and getaddrinfo().

#define YES   1

Definition at line 88 of file getaddrinfo.c.

Referenced by getaddrinfo(), and str_isnumber().

Function Documentation

static int get_name __P ( (const char *, const struct afd *, struct addrinfo **, char *, struct addrinfo *, int)  )
static
static int get_addr __P ( (const char *, int, struct addrinfo **, struct addrinfo *, int)  )
static
static int str_isnumber __P ( (const char *)  )
static
void freeaddrinfo ( struct addrinfo ai)
char* gai_strerror ( int  ecode)

Definition at line 202 of file getaddrinfo.c.

References EAI_MAX.

Referenced by rsock_raise_socket_error().

static int get_addr ( const char *  hostname,
int  af,
struct addrinfo **  res,
struct addrinfo pai,
int  port0 
)
static
static int get_name ( const char *  addr,
const struct afd afd,
struct addrinfo **  res,
char *  numaddr,
struct addrinfo pai,
int  port0 
)
static

Definition at line 532 of file getaddrinfo.c.

References afd::a_addrlen, afd::a_af, free(), freeaddrinfo(), freehostent, GET_AI, GET_CANONNAME, NULL, SUCCESS, and u_short.

Referenced by getaddrinfo().

int getaddrinfo ( const char *  hostname,
const char *  servname,
const struct addrinfo hints,
struct addrinfo **  res 
)
static int inet_pton ( int  af,
const char *  hostname,
void *  pton 
)
static

Definition at line 239 of file getaddrinfo.c.

References d1.

Referenced by getaddrinfo().

static int str_isnumber ( const char *  p)
static

Definition at line 225 of file getaddrinfo.c.

References NO, and YES.

Referenced by getaddrinfo().

Variable Documentation

const struct afd afdl[]
static
Initial value:
= {
#define N_INET
{PF_INET, sizeof(struct in_addr),
sizeof(struct sockaddr_in),
offsetof(struct sockaddr_in, sin_addr),
{0, 0, 0, 0, NULL, NULL},
}
#define PF_INET
Definition: sockport.h:77
static const char in_addrany[]
Definition: getaddrinfo.c:96
static const char in_loopback[]
Definition: getaddrinfo.c:100
#define offsetof(p_type, field)
Definition: addrinfo.h:186
#define NULL
#define sizeof(x)
Definition: zlib.c:57

Referenced by get_addr(), and getaddrinfo().

const char* const ai_errlist[]
static
Initial value:
= {
"success.",
"address family for hostname not supported.",
"temporary failure in name resolution.",
"invalid value for ai_flags.",
"non-recoverable failure in name resolution.",
"ai_family not supported.",
"memory allocation failure.",
"no address associated with hostname.",
"hostname nor servname provided, or not known.",
"servname not supported for ai_socktype.",
"ai_socktype not supported.",
"system error returned in errno.",
"invalid value for hints.",
"resolved protocol is unknown.",
"unknown error.",
}

Definition at line 149 of file getaddrinfo.c.

const char in6_addrany[]
static
Initial value:
= {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
}

Definition at line 97 of file getaddrinfo.c.

const char in6_loopback[]
static
Initial value:
= {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
}

Definition at line 101 of file getaddrinfo.c.

const char in_addrany[] = { 0, 0, 0, 0 }
static

Definition at line 96 of file getaddrinfo.c.

const char in_loopback[] = { 127, 0, 0, 1 }
static

Definition at line 100 of file getaddrinfo.c.