Ruby: ext/socket/raddrinfo.c File Reference

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

Data Structures | Macros | Functions
raddrinfo.c File Reference
`#include "rubysocket.h"`

Go to the source code of this file.

## Data Structures
struct | getaddrinfo_arg
struct | getnameinfo_arg
struct | hostent_arg
struct | rb_addrinfo_t

## Macros
#define | str_equal(ptr, len, name)
#define | addrinfo_free RUBY_TYPED_DEFAULT_FREE
#define | IS_ADDRINFO(obj) rb_typeddata_is_kind_of((obj), &addrinfo_type)

## Functions
int | rb_getaddrinfo (const char *node, const char *service, const struct addrinfo *hints, struct rb_addrinfo **res)
void | rb_freeaddrinfo (struct rb_addrinfo *ai)
int | rb_getnameinfo (const struct sockaddr *sa, socklen_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags)
VALUE | rsock_make_ipaddr (struct sockaddr *addr, socklen_t addrlen)
struct rb_addrinfo * | rsock_getaddrinfo (VALUE host, VALUE port, struct addrinfo *hints, int socktype_hack)
int | rsock_fd_family (int fd)
struct rb_addrinfo * | rsock_addrinfo (VALUE host, VALUE port, int family, int socktype, int flags)
VALUE | rsock_ipaddr (struct sockaddr *sockaddr, socklen_t sockaddrlen, int norevlookup)
VALUE | rsock_freeaddrinfo (VALUE arg)
VALUE | rsock_make_hostent (VALUE host, struct rb_addrinfo *addr, VALUE(*ipaddr)(struct sockaddr *, socklen_t))
VALUE | rsock_addrinfo_new (struct sockaddr *addr, socklen_t len, int family, int socktype, int protocol, VALUE canonname, VALUE inspectname)
VALUE | rsock_inspect_sockaddr (struct sockaddr *sockaddr_arg, socklen_t socklen, VALUE ret)
VALUE | rsock_addrinfo_inspect_sockaddr (VALUE self)
VALUE | rsock_sockaddr_string_value (volatile VALUE *v)
VALUE | rsock_sockaddr_string_value_with_addrinfo (volatile VALUE *v, VALUE *rai_ret)
char * | rsock_sockaddr_string_value_ptr (volatile VALUE *v)
VALUE | rb_check_sockaddr_string_type (VALUE val)
VALUE | rsock_fd_socket_addrinfo (int fd, struct sockaddr *addr, socklen_t len)
VALUE | rsock_io_socket_addrinfo (VALUE io, struct sockaddr *addr, socklen_t len)
void | rsock_init_addrinfo (void)

## Macro Definition Documentation

## ◆ addrinfo_free

#define addrinfo_free RUBY_TYPED_DEFAULT_FREE

Definition at line 735 of file raddrinfo.c.

## ◆ IS_ADDRINFO

#define IS_ADDRINFO | ( |  | obj | ) | rb_typeddata_is_kind_of((obj), &addrinfo_type)

Definition at line 754 of file raddrinfo.c.

## ◆ str_equal

#define str_equal | ( |  | ptr,
|  |  | len,
|  |  | name
| ) |  |

Value:
((ptr)[0] == name[0] && \
rb_strlen_lit(name) == (len) && memcmp(ptr, name, len) == 0)
ptr
struct RIMemo * ptr
Definition: debug.c:88
len
uint8_t len
Definition: escape.c:17
rb_strlen_lit
#define rb_strlen_lit(str)
Definition: string.h:286
memcmp
int memcmp(const void *s1, const void *s2, size_t len)
Definition: memcmp.c:7
name
const char * name
Definition: nkf.c:208

Definition at line 429 of file raddrinfo.c.

## Function Documentation

## ◆ rb_check_sockaddr_string_type()

VALUE rb_check_sockaddr_string_type | ( | VALUE | val | ) |

Definition at line 2510 of file raddrinfo.c.

References IS_ADDRINFO, and rb_check_string_type().

## ◆ rb_freeaddrinfo()

void rb_freeaddrinfo | ( | struct rb_addrinfo * | ai | ) |

Definition at line 322 of file raddrinfo.c.

References rb_addrinfo::ai, addrinfo::ai_addr, addrinfo::ai_next, freeaddrinfo, and xfree.

Referenced by rsock_freeaddrinfo().

## ◆ rb_getaddrinfo()

int rb_getaddrinfo | ( | const char * | node,
|  | const char * | service,
|  | const struct addrinfo * | hints,
|  | struct rb_addrinfo ** | res
| ) |  |

Definition at line 288 of file raddrinfo.c.

References rb_addrinfo::ai, rb_addrinfo::allocated_by_malloc, getaddrinfo, getaddrinfo_arg::hints, int(), MEMZERO, getaddrinfo_arg::node, rb_thread_call_without_gvl(), getaddrinfo_arg::res, RUBY_UBF_IO, getaddrinfo_arg::service, and xmalloc.

Referenced by rsock_getaddrinfo().

## ◆ rb_getnameinfo()

int rb_getnameinfo | ( | const struct sockaddr * | sa,
|  | socklen_t | salen,
|  | char * | host,
|  | size_t | hostlen,
|  | char * | serv,
|  | size_t | servlen,
|  | int | flags
| ) |  |

Definition at line 363 of file raddrinfo.c.

References getnameinfo_arg::flags, getnameinfo, getnameinfo_arg::host, getnameinfo_arg::hostlen, int(), rb_thread_call_without_gvl(), RUBY_UBF_IO, getnameinfo_arg::sa, getnameinfo_arg::salen, getnameinfo_arg::serv, and getnameinfo_arg::servlen.

Referenced by rsock_ipaddr().

## ◆ rsock_addrinfo()

struct rb_addrinfo * rsock_addrinfo | ( | VALUE | host,
|  | VALUE | port,
|  | int | family,
|  | int | socktype,
|  | int | flags
| ) |  |

Definition at line 543 of file raddrinfo.c.

References addrinfo::ai_family, addrinfo::ai_flags, addrinfo::ai_socktype, MEMZERO, and rsock_getaddrinfo().

## ◆ rsock_addrinfo_inspect_sockaddr()

VALUE rsock_addrinfo_inspect_sockaddr | ( | VALUE | self | ) |

Definition at line 1523 of file raddrinfo.c.

References rb_str_new.

Referenced by rsock_init_addrinfo(), and rsock_syserr_fail_raddrinfo().

## ◆ rsock_addrinfo_new()

VALUE rsock_addrinfo_new | ( | struct sockaddr * | addr,
|  | socklen_t | len,
|  | int | family,
|  | int | socktype,
|  | int | protocol,
|  | VALUE | canonname,
|  | VALUE | inspectname
| ) |  |

Definition at line 800 of file raddrinfo.c.

References DATA_PTR, len, and rb_cAddrinfo.

Referenced by rsock_fd_socket_addrinfo(), and rsock_syserr_fail_sockaddr().

## ◆ rsock_fd_family()

int rsock_fd_family | ( | int | fd | ) |

Definition at line 530 of file raddrinfo.c.

References AF_UNSPEC, and offsetof.

## ◆ rsock_fd_socket_addrinfo()

VALUE rsock_fd_socket_addrinfo | ( | int | fd,
|  | struct sockaddr * | addr,
|  | socklen_t | len
| ) |  |

Definition at line 2518 of file raddrinfo.c.

References len, Qnil, rb_sys_fail(), and rsock_addrinfo_new().

Referenced by rsock_io_socket_addrinfo().

## ◆ rsock_freeaddrinfo()

VALUE rsock_freeaddrinfo | ( | VALUE | arg | ) |

Definition at line 698 of file raddrinfo.c.

References Qnil, and rb_freeaddrinfo().

Referenced by rsock_make_hostent().

## ◆ rsock_getaddrinfo()

struct rb_addrinfo * rsock_getaddrinfo | ( | VALUE | host,
|  | VALUE | port,
|  | struct addrinfo * | hints,
|  | int | socktype_hack
| ) |  |

Definition at line 502 of file raddrinfo.c.

References addrinfo::ai_flags, addrinfo::ai_socktype, error(), NI_MAXHOST, NI_MAXSERV, NULL, rb_eSocket, rb_getaddrinfo(), rb_raise(), rsock_raise_socket_error(), and strlen().

Referenced by rsock_addrinfo().

## ◆ rsock_init_addrinfo()

void rsock_init_addrinfo | ( | void |  | ) |

Definition at line 2563 of file raddrinfo.c.

References rb_cAddrinfo, rb_cObject, rb_define_alloc_func(), rb_define_class(), rb_define_method, rb_define_singleton_method, rb_intern(), and rsock_addrinfo_inspect_sockaddr().

Referenced by rsock_init_socket_init().

## ◆ rsock_inspect_sockaddr()

VALUE rsock_inspect_sockaddr | ( | struct sockaddr * | sockaddr_arg,
|  | socklen_t | socklen,
|  | VALUE | ret
| ) |  |

Definition at line 1148 of file raddrinfo.c.

References union_sockaddr::addr, AF_UNSPEC, error(), getnameinfo, IFNAMSIZ, union_sockaddr::in, int(), ISPRINT, ISSPACE, len, NI_NUMERICHOST, NI_NUMERICSERV, NULL, offsetof, rb_id2name(), rb_str_cat(), rb_str_cat2, rb_str_catf(), rsock_intern_family(), and rsock_raise_socket_error().

## ◆ rsock_io_socket_addrinfo()

VALUE rsock_io_socket_addrinfo | ( | VALUE | io,
|  | struct sockaddr * | addr,
|  | socklen_t | len
| ) |  |

Definition at line 2537 of file raddrinfo.c.

References rb_io_t::fd, FIX2INT, GetOpenFile, len, NUM2INT, Qnil, rb_eTypeError, rb_raise(), rsock_fd_socket_addrinfo(), T_BIGNUM, T_FILE, T_FIXNUM, TYPE, and UNREACHABLE_RETURN.

Referenced by rsock_s_recvfrom(), and rsock_s_recvfrom_nonblock().

## ◆ rsock_ipaddr()

VALUE rsock_ipaddr | ( | struct sockaddr * | sockaddr,
|  | socklen_t | sockaddrlen,
|  | int | norevlookup
| ) |  |

Definition at line 555 of file raddrinfo.c.

References error(), id, INT2FIX, NI_NUMERICHOST, NI_NUMERICSERV, NULL, Qnil, rb_ary_new3, rb_getnameinfo(), rb_id2str, rb_str_dup(), rb_str_new2, rsock_intern_family(), and rsock_raise_socket_error().

Referenced by rsock_s_recvfrom(), and rsock_s_recvfrom_nonblock().

## ◆ rsock_make_hostent()

VALUE rsock_make_hostent | ( | VALUE | host,
|  | struct rb_addrinfo * | addr,
|  | VALUE(*)(struct sockaddr *, socklen_t) | ipaddr
| ) |  |

Definition at line 706 of file raddrinfo.c.

References hostent_arg::addr, hostent_arg::host, hostent_arg::ipaddr, rb_ensure(), and rsock_freeaddrinfo().

## ◆ rsock_make_ipaddr()

VALUE rsock_make_ipaddr | ( | struct sockaddr * | addr,
|  | socklen_t | addrlen
| ) |  |

Definition at line 396 of file raddrinfo.c.

References rb_str_new2.

## ◆ rsock_sockaddr_string_value()

VALUE rsock_sockaddr_string_value | ( | volatile VALUE * | v | ) |

Definition at line 2479 of file raddrinfo.c.

References IS_ADDRINFO, and StringValue.

Referenced by rsock_sockaddr_string_value_ptr().

## ◆ rsock_sockaddr_string_value_ptr()

char * rsock_sockaddr_string_value_ptr | ( | volatile VALUE * | v | ) |

Definition at line 2503 of file raddrinfo.c.

References rsock_sockaddr_string_value(), and RSTRING_PTR.

## ◆ rsock_sockaddr_string_value_with_addrinfo()

VALUE rsock_sockaddr_string_value_with_addrinfo | ( | volatile VALUE * | v,
|  | VALUE * | rai_ret
| ) |  |

Definition at line 2490 of file raddrinfo.c.

References IS_ADDRINFO, Qnil, and StringValue.