Ruby: ext/socket/getaddrinfo.c File Reference

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

Data Structures | Macros | Typedefs | Functions
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
char * | gai_strerror (int ecode)
void | freeaddrinfo (struct addrinfo *ai)
int | getaddrinfo (const char *hostname, const char *servname, const struct addrinfo *hints, struct addrinfo **res)

## Macro Definition Documentation

## ◆ ANY

#define ANY 0

Definition at line 90 of file getaddrinfo.c.

## ◆ ERR

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

Definition at line 200 of file getaddrinfo.c.

## ◆ 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);\
}
EAI_MEMORY
#define EAI_MEMORY
Definition: addrinfo.h:83
free
#define free(x)
Definition: dln.c:52
NULL
#define NULL
Definition: regenc.h:69
malloc
#define malloc
Definition: st.c:170
addrinfo
Definition: addrinfo.h:131
sockinet
Definition: getaddrinfo.c:108
sockinet::si_port
u_short si_port
Definition: getaddrinfo.c:111
error
void error(const char *msg)
Definition: untgz.c:593

Definition at line 182 of file getaddrinfo.c.

## ◆ 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;\
}\
}
AI_CANONNAME
#define AI_CANONNAME
Definition: addrinfo.h:97
str
char str[HTML_ESCAPE_MAX_LEN+1]
Definition: escape.c:18
strlen
size_t strlen(const char *)

Definition at line 172 of file getaddrinfo.c.

## ◆ N_INET

#define N_INET 0

## ◆ NO

#define NO 0

Definition at line 92 of file getaddrinfo.c.

## ◆ PTON_MAX

#define PTON_MAX 4

Definition at line 142 of file getaddrinfo.c.

## ◆ SUCCESS

#define SUCCESS 0

Definition at line 89 of file getaddrinfo.c.

## ◆ YES

#define YES 1

Definition at line 91 of file getaddrinfo.c.

## Typedef Documentation

## ◆ socklen_t

typedef int socklen_t

Definition at line 83 of file getaddrinfo.c.

## Function Documentation

## ◆ freeaddrinfo()

void freeaddrinfo | ( | struct addrinfo * | ai | ) |

Definition at line 216 of file getaddrinfo.c.

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

## ◆ gai_strerror()

char * gai_strerror | ( | int | ecode | ) |

Definition at line 207 of file getaddrinfo.c.

References EAI_MAX.

Referenced by rsock_raise_socket_error().

## ◆ getaddrinfo()

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

Definition at line 272 of file getaddrinfo.c.

References addrinfo::ai_addr, addrinfo::ai_addrlen, AI_CANONNAME, addrinfo::ai_canonname, addrinfo::ai_family, addrinfo::ai_flags, AI_MASK, addrinfo::ai_next, AI_NUMERICHOST, AI_NUMERICSERV, AI_PASSIVE, addrinfo::ai_protocol, addrinfo::ai_socktype, ANY, EAI_BADFLAGS, EAI_BADHINTS, EAI_FAIL, EAI_FAMILY, EAI_NONAME, EAI_PROTOCOL, EAI_SERVICE, EAI_SOCKTYPE, ERR, error(), free, freeaddrinfo, GET_AI, getenv, if(), IN_CLASSA_NSHIFT, IN_EXPERIMENTAL, IN_LOOPBACKNET, IN_MULTICAST, IPPROTO_TCP, IPPROTO_UDP, memcpy, NULL, PF_INET, PF_UNSPEC, PTON_MAX, SUCCESS, top, u_long, u_short, and YES.