Ruby  2.1.10p492(2016-04-01revision54464)
Data Structures | Macros | Typedefs | 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"

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; }
 

Typedefs

typedef int socklen_t
 

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

◆ ANY

#define ANY   0

Definition at line 91 of file getaddrinfo.c.

Referenced by getaddrinfo().

◆ ERR

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

Definition at line 199 of file getaddrinfo.c.

Referenced by get_addr(), and getaddrinfo().

◆ GET_AI

#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);\
(ai)->ai_family = (afd)->a_af;\
(ai)->ai_addrlen = (afd)->a_socklen;\
INIT_SOCKADDR((ai)->ai_addr, (afd)->a_af, (afd)->a_socklen);\
((struct sockinet *)(ai)->ai_addr)->si_port = (port);\
p = (char *)((ai)->ai_addr);\
memcpy(p + (afd)->a_off, (addr), (afd)->a_addrlen);\
}
#define EAI_MEMORY
Definition: addrinfo.h:83
#define malloc
Definition: ripper.c:96
u_short si_port
Definition: getaddrinfo.c:112
#define NULL
Definition: _sdbm.c:102
free(psz)

Definition at line 181 of file getaddrinfo.c.

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

◆ GET_CANONNAME

#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 *)
#define AI_CANONNAME
Definition: addrinfo.h:97
#define EAI_MEMORY
Definition: addrinfo.h:83
#define malloc
Definition: ripper.c:96
#define NULL
Definition: _sdbm.c:102
free(psz)

Definition at line 171 of file getaddrinfo.c.

Referenced by get_addr(), and get_name().

◆ N_INET

#define N_INET   0

Referenced by get_addr().

◆ NO

#define NO   0

Definition at line 93 of file getaddrinfo.c.

Referenced by str_isnumber().

◆ PTON_MAX

#define PTON_MAX   4

Definition at line 143 of file getaddrinfo.c.

Referenced by getaddrinfo().

◆ SUCCESS

#define SUCCESS   0

Definition at line 90 of file getaddrinfo.c.

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

◆ YES

#define YES   1

Definition at line 92 of file getaddrinfo.c.

Referenced by getaddrinfo(), and str_isnumber().

Typedef Documentation

◆ socklen_t

typedef int socklen_t

Definition at line 84 of file getaddrinfo.c.

Function Documentation

◆ __P() [1/3]

static int get_name __P ( (const char *, const struct afd *, struct addrinfo **, char *, struct addrinfo *, int)  )
static

◆ __P() [2/3]

static int get_addr __P ( (const char *, int, struct addrinfo **, struct addrinfo *, int)  )
static

◆ __P() [3/3]

static int str_isnumber __P ( (const char *)  )
static

◆ freeaddrinfo()

void freeaddrinfo ( struct addrinfo ai)

Definition at line 215 of file getaddrinfo.c.

References addrinfo::ai_canonname, addrinfo::ai_next, free(), and NULL.

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

◆ gai_strerror()

char* gai_strerror ( int  ecode)

Definition at line 206 of file getaddrinfo.c.

References ai_errlist, and EAI_MAX.

Referenced by rsock_raise_socket_error().

◆ get_addr()

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

◆ get_name()

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 536 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().

◆ getaddrinfo()

int getaddrinfo ( const char *  hostname,
const char *  servname,
const struct addrinfo hints,
struct addrinfo **  res 
)

◆ inet_pton()

static int inet_pton ( int  af,
const char *  hostname,
void *  pton 
)
static

Definition at line 243 of file getaddrinfo.c.

References d1.

Referenced by getaddrinfo(), and numeric_getaddrinfo().

◆ str_isnumber()

static int str_isnumber ( const char *  p)
static

Definition at line 229 of file getaddrinfo.c.

References NO, and YES.

Referenced by getaddrinfo().

Variable Documentation

◆ afdl

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:109
static const char in_addrany[]
Definition: getaddrinfo.c:100
static const char in_loopback[]
Definition: getaddrinfo.c:104
#define offsetof(p_type, field)
Definition: addrinfo.h:186
#define sizeof(x)
Definition: zlib.c:58
#define NULL
Definition: _sdbm.c:102

Referenced by get_addr(), and getaddrinfo().

◆ ai_errlist

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 153 of file getaddrinfo.c.

Referenced by gai_strerror().

◆ in6_addrany

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 101 of file getaddrinfo.c.

◆ in6_loopback

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 105 of file getaddrinfo.c.

◆ in_addrany

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

Definition at line 100 of file getaddrinfo.c.

◆ in_loopback

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

Definition at line 104 of file getaddrinfo.c.