Ruby  2.4.2p198(2017-09-14revision59899)
Macros | Functions | Variables
option.c File Reference
#include "rubysocket.h"
Include dependency graph for option.c:

Go to the source code of this file.

Macros

#define pack_var(v)   rb_str_new((const char *)&(v), sizeof(v))
 
#define CAT(x, y)   x##y
 
#define XCAT(x, y)   CAT(x,y)
 
#define TYPE_IP_MULTICAST_LOOP   byte
 
#define TYPE_IP_MULTICAST_TTL   byte
 
#define USE_INSPECT_BYTE   1
 
#define check_size(len, size)
 
#define inspect_ipv4_multicast_loop(a, b, c, d)   XCAT(inspect_,TYPE_IP_MULTICAST_LOOP)(a,b,c,d)
 
#define inspect_ipv4_multicast_ttl(a, b, c, d)   XCAT(inspect_,TYPE_IP_MULTICAST_TTL)(a,b,c,d)
 
#define IFNAMSIZ   (sizeof(unsigned int)*3+1)
 

Functions

static VALUE sockopt_pack_byte (VALUE value)
 
static VALUE sockopt_pack_int (VALUE value)
 
static VALUE constant_to_sym (int constant, ID(*intern_const)(int))
 
static VALUE optname_to_sym (int level, int optname)
 
static VALUE sockopt_initialize (VALUE self, VALUE vfamily, VALUE vlevel, VALUE voptname, VALUE data)
 
VALUE rsock_sockopt_new (int family, int level, int optname, VALUE data)
 
static VALUE sockopt_family_m (VALUE self)
 
static int sockopt_level (VALUE self)
 
static VALUE sockopt_level_m (VALUE self)
 
static int sockopt_optname (VALUE self)
 
static VALUE sockopt_optname_m (VALUE self)
 
static VALUE sockopt_data (VALUE self)
 
static VALUE sockopt_s_byte (VALUE klass, VALUE vfamily, VALUE vlevel, VALUE voptname, VALUE vint)
 
static VALUE sockopt_byte (VALUE self)
 
static VALUE sockopt_s_int (VALUE klass, VALUE vfamily, VALUE vlevel, VALUE voptname, VALUE vint)
 
static VALUE sockopt_int (VALUE self)
 
static VALUE sockopt_s_bool (VALUE klass, VALUE vfamily, VALUE vlevel, VALUE voptname, VALUE vbool)
 
static VALUE sockopt_bool (VALUE self)
 
static VALUE sockopt_s_linger (VALUE klass, VALUE vonoff, VALUE vsecs)
 
static VALUE sockopt_linger (VALUE self)
 
static VALUE sockopt_s_ipv4_multicast_loop (VALUE klass, VALUE value)
 
static VALUE sockopt_ipv4_multicast_loop (VALUE self)
 
static VALUE sockopt_s_ipv4_multicast_ttl (VALUE klass, VALUE value)
 
static VALUE sockopt_ipv4_multicast_ttl (VALUE self)
 
static int inspect_int (int level, int optname, VALUE data, VALUE ret)
 
static int inspect_byte (int level, int optname, VALUE data, VALUE ret)
 
static int inspect_errno (int level, int optname, VALUE data, VALUE ret)
 
static int inspect_timeval_as_interval (int level, int optname, VALUE data, VALUE ret)
 
const char * inet_ntop (int af, const void *addr, char *numaddr, size_t numaddr_len)
 
static int rb_if_indextoname (const char *succ_prefix, const char *fail_prefix, unsigned int ifindex, char *buf, size_t len)
 
static VALUE sockopt_inspect (VALUE self)
 
static VALUE sockopt_unpack (VALUE self, VALUE template)
 
void rsock_init_sockopt (void)
 

Variables

VALUE rb_cSockOpt
 

Macro Definition Documentation

◆ CAT

#define CAT (   x,
 
)    x##y

Definition at line 7 of file option.c.

◆ check_size

#define check_size (   len,
  size 
)
Value:
((len) == (size) ? \
(void)0 : \
rb_raise(rb_eTypeError, "size differ. expected as "#size"=%d but %ld", \
(int)size, (long)(len)))
VALUE rb_eTypeError
Definition: error.c:762
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:2207
register unsigned int len
Definition: zonetab.h:51
int size
Definition: encoding.c:57

Definition at line 30 of file option.c.

Referenced by sockopt_bool(), sockopt_byte(), sockopt_int(), and sockopt_linger().

◆ IFNAMSIZ

#define IFNAMSIZ   (sizeof(unsigned int)*3+1)

◆ inspect_ipv4_multicast_loop

#define inspect_ipv4_multicast_loop (   a,
  b,
  c,
 
)    XCAT(inspect_,TYPE_IP_MULTICAST_LOOP)(a,b,c,d)

Definition at line 430 of file option.c.

Referenced by sockopt_inspect().

◆ inspect_ipv4_multicast_ttl

#define inspect_ipv4_multicast_ttl (   a,
  b,
  c,
 
)    XCAT(inspect_,TYPE_IP_MULTICAST_TTL)(a,b,c,d)

Definition at line 481 of file option.c.

Referenced by sockopt_inspect().

◆ pack_var

#define pack_var (   v)    rb_str_new((const char *)&(v), sizeof(v))

Definition at line 5 of file option.c.

Referenced by sockopt_pack_byte(), sockopt_pack_int(), sockopt_s_bool(), and sockopt_s_linger().

◆ TYPE_IP_MULTICAST_LOOP

#define TYPE_IP_MULTICAST_LOOP   byte

Definition at line 25 of file option.c.

Referenced by sockopt_ipv4_multicast_loop(), and sockopt_s_ipv4_multicast_loop().

◆ TYPE_IP_MULTICAST_TTL

#define TYPE_IP_MULTICAST_TTL   byte

Definition at line 26 of file option.c.

Referenced by sockopt_ipv4_multicast_ttl(), and sockopt_s_ipv4_multicast_ttl().

◆ USE_INSPECT_BYTE

#define USE_INSPECT_BYTE   1

Definition at line 27 of file option.c.

◆ XCAT

#define XCAT (   x,
 
)    CAT(x,y)

Function Documentation

◆ constant_to_sym()

static VALUE constant_to_sym ( int  constant,
ID(*)(int)  intern_const 
)
static

Definition at line 51 of file option.c.

References ID2SYM, INT2NUM, and name.

Referenced by optname_to_sym().

◆ inet_ntop()

const char* inet_ntop ( int  af,
const void *  addr,
char *  numaddr,
size_t  numaddr_len 
)

Definition at line 651 of file option.c.

References memcpy, and snprintf.

Referenced by getnameinfo(), and rb_if_indextoname().

◆ inspect_byte()

static int inspect_byte ( int  level,
int  optname,
VALUE  data,
VALUE  ret 
)
static

Definition at line 500 of file option.c.

References rb_str_catf(), RSTRING_LEN, and RSTRING_PTR.

◆ inspect_errno()

static int inspect_errno ( int  level,
int  optname,
VALUE  data,
VALUE  ret 
)
static

◆ inspect_int()

static int inspect_int ( int  level,
int  optname,
VALUE  data,
VALUE  ret 
)
static

Definition at line 485 of file option.c.

References memcpy, rb_str_catf(), RSTRING_LEN, and RSTRING_PTR.

Referenced by sockopt_inspect().

◆ inspect_timeval_as_interval()

static int inspect_timeval_as_interval ( int  level,
int  optname,
VALUE  data,
VALUE  ret 
)
static

Definition at line 587 of file option.c.

References memcpy, rb_str_catf(), RSTRING_LEN, and RSTRING_PTR.

Referenced by sockopt_inspect().

◆ optname_to_sym()

static VALUE optname_to_sym ( int  level,
int  optname 
)
static

◆ rb_if_indextoname()

static int rb_if_indextoname ( const char *  succ_prefix,
const char *  fail_prefix,
unsigned int  ifindex,
char *  buf,
size_t  len 
)
static

◆ rsock_init_sockopt()

void rsock_init_sockopt ( void  )

◆ rsock_sockopt_new()

VALUE rsock_sockopt_new ( int  family,
int  level,
int  optname,
VALUE  data 
)

◆ sockopt_bool()

static VALUE sockopt_bool ( VALUE  self)
static

Definition at line 304 of file option.c.

References check_size, len, memcpy, Qfalse, Qtrue, RSTRING_LEN, RSTRING_PTR, sockopt_data(), and StringValue.

Referenced by rsock_init_sockopt().

◆ sockopt_byte()

static VALUE sockopt_byte ( VALUE  self)
static

Definition at line 218 of file option.c.

References check_size, CHR2FIX, RSTRING_LEN, RSTRING_PTR, sockopt_data(), and StringValue.

Referenced by rsock_init_sockopt().

◆ sockopt_data()

static VALUE sockopt_data ( VALUE  self)
static

◆ sockopt_family_m()

static VALUE sockopt_family_m ( VALUE  self)
static

◆ sockopt_initialize()

static VALUE sockopt_initialize ( VALUE  self,
VALUE  vfamily,
VALUE  vlevel,
VALUE  voptname,
VALUE  data 
)
static

◆ sockopt_inspect()

static VALUE sockopt_inspect ( VALUE  self)
static

◆ sockopt_int()

static VALUE sockopt_int ( VALUE  self)
static

Definition at line 258 of file option.c.

References check_size, INT2NUM, memcpy, RSTRING_LEN, RSTRING_PTR, sockopt_data(), and StringValue.

Referenced by rsock_init_sockopt().

◆ sockopt_ipv4_multicast_loop()

static VALUE sockopt_ipv4_multicast_loop ( VALUE  self)
static

◆ sockopt_ipv4_multicast_ttl()

static VALUE sockopt_ipv4_multicast_ttl ( VALUE  self)
static

◆ sockopt_level()

static int sockopt_level ( VALUE  self)
static

◆ sockopt_level_m()

static VALUE sockopt_level_m ( VALUE  self)
static

Definition at line 146 of file option.c.

References INT2NUM, and sockopt_level().

Referenced by rsock_init_sockopt(), and sockopt_inspect().

◆ sockopt_linger()

static VALUE sockopt_linger ( VALUE  self)
static

◆ sockopt_optname()

static int sockopt_optname ( VALUE  self)
static

◆ sockopt_optname_m()

static VALUE sockopt_optname_m ( VALUE  self)
static

Definition at line 167 of file option.c.

References INT2NUM, and sockopt_optname().

Referenced by rsock_init_sockopt(), and sockopt_inspect().

◆ sockopt_pack_byte()

static VALUE sockopt_pack_byte ( VALUE  value)
static

Definition at line 37 of file option.c.

References NUM2CHR, pack_var, and rb_to_int().

Referenced by sockopt_s_byte().

◆ sockopt_pack_int()

static VALUE sockopt_pack_int ( VALUE  value)
static

Definition at line 44 of file option.c.

References NUM2INT, pack_var, and rb_to_int().

Referenced by sockopt_s_int().

◆ sockopt_s_bool()

static VALUE sockopt_s_bool ( VALUE  klass,
VALUE  vfamily,
VALUE  vlevel,
VALUE  voptname,
VALUE  vbool 
)
static

◆ sockopt_s_byte()

static VALUE sockopt_s_byte ( VALUE  klass,
VALUE  vfamily,
VALUE  vlevel,
VALUE  voptname,
VALUE  vint 
)
static

◆ sockopt_s_int()

static VALUE sockopt_s_int ( VALUE  klass,
VALUE  vfamily,
VALUE  vlevel,
VALUE  voptname,
VALUE  vint 
)
static

◆ sockopt_s_ipv4_multicast_loop()

static VALUE sockopt_s_ipv4_multicast_loop ( VALUE  klass,
VALUE  value 
)
static

Definition at line 394 of file option.c.

References IPPROTO_IP, rsock_sockopt_new(), TYPE_IP_MULTICAST_LOOP, and XCAT.

Referenced by rsock_init_sockopt().

◆ sockopt_s_ipv4_multicast_ttl()

static VALUE sockopt_s_ipv4_multicast_ttl ( VALUE  klass,
VALUE  value 
)
static

Definition at line 446 of file option.c.

References IPPROTO_IP, rsock_sockopt_new(), TYPE_IP_MULTICAST_TTL, and XCAT.

Referenced by rsock_init_sockopt().

◆ sockopt_s_linger()

static VALUE sockopt_s_linger ( VALUE  klass,
VALUE  vonoff,
VALUE  vsecs 
)
static

Definition at line 334 of file option.c.

References AF_UNSPEC, NIL_P, NUM2INT, pack_var, rb_check_to_integer(), rsock_sockopt_new(), and RTEST.

Referenced by rsock_init_sockopt().

◆ sockopt_unpack()

static VALUE sockopt_unpack ( VALUE  self,
VALUE  template 
)
static

Definition at line 1432 of file option.c.

References rb_funcall(), rb_intern, and sockopt_data().

Referenced by rsock_init_sockopt().

Variable Documentation

◆ rb_cSockOpt

VALUE rb_cSockOpt

Definition at line 3 of file option.c.

Referenced by rsock_init_sockopt(), and rsock_sockopt_new().