#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 |
Defines | |
#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 struct afd | afdl [] |
static const char *const | ai_errlist [] |
#define ANY 0 |
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);\ }
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;\ }\ }
Definition at line 167 of file getaddrinfo.c.
Referenced by get_addr(), and get_name().
#define N_INET 0 |
#define NO 0 |
#define PTON_MAX 4 |
#define SUCCESS 0 |
#define YES 1 |
static int str_isnumber __P | ( | (const char *) | ) | [static] |
static int get_addr __P | ( | (const char *, int, struct addrinfo **, struct addrinfo *, int) | ) | [static] |
static int get_name __P | ( | (const char *, const struct afd *, struct addrinfo **, char *, struct addrinfo *, int) | ) | [static] |
void freeaddrinfo | ( | struct addrinfo * | ai | ) |
Definition at line 211 of file getaddrinfo.c.
References addrinfo::ai_canonname, addrinfo::ai_next, free, and NULL.
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] |
Definition at line 572 of file getaddrinfo.c.
References afd::a_af, AF_UNSPEC, afdl, addrinfo::ai_addr, AI_ADDRCONFIG, AI_ALL, addrinfo::ai_next, AI_V4MAPPED, bad, EAI_AGAIN, EAI_FAIL, EAI_NODATA, ERR, GET_AI, GET_CANONNAME, INET6, NULL, top, and u_short.
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.
int getaddrinfo | ( | const char * | hostname, | |
const char * | servname, | |||
const struct addrinfo * | hints, | |||
struct addrinfo ** | res | |||
) |
Definition at line 267 of file getaddrinfo.c.
References afd::a_addrany, afd::a_af, afd::a_loopback, afdl, addrinfo::ai_addr, addrinfo::ai_addrlen, addrinfo::ai_canonname, addrinfo::ai_family, addrinfo::ai_flags, AI_MASK, addrinfo::ai_next, AI_NUMERICSERV, AI_PASSIVE, addrinfo::ai_protocol, addrinfo::ai_socktype, ANY, EAI_BADFLAGS, EAI_BADHINTS, EAI_FAMILY, EAI_NONAME, EAI_PROTOCOL, EAI_SERVICE, EAI_SOCKTYPE, ERR, GET_AI, getenv(), inet_pton(), IPPROTO_TCP, IPPROTO_UDP, NULL, PF_INET, PF_UNSPEC, proto, PTON_MAX, str_isnumber(), top, u_short, and YES.
static int inet_pton | ( | int | af, | |
const char * | hostname, | |||
void * | pton | |||
) | [static] |
static int str_isnumber | ( | const char * | p | ) | [static] |
Referenced by get_addr(), getaddrinfo(), and getnameinfo().
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.