2 #define RUBY_SOCKET_H 1 10 #include <sys/types.h> 26 # if defined(_MSC_VER) 27 # undef HAVE_TYPE_STRUCT_SOCKADDR_DL 30 # include <sys/socket.h> 31 # include <netinet/in.h> 32 # ifdef HAVE_NETINET_IN_SYSTM_H 33 # include <netinet/in_systm.h> 35 # ifdef HAVE_NETINET_TCP_H 36 # include <netinet/tcp.h> 38 # ifdef HAVE_NETINET_TCP_FSM_H 39 # include <netinet/tcp_fsm.h> 41 # ifdef HAVE_NETINET_UDP_H 42 # include <netinet/udp.h> 44 # ifdef HAVE_ARPA_INET_H 45 # include <arpa/inet.h> 50 #ifdef HAVE_NETPACKET_PACKET_H 51 # include <netpacket/packet.h> 53 #ifdef HAVE_NET_ETHERNET_H 54 # include <net/ethernet.h> 63 #if defined(HAVE_FCNTL) 64 # ifdef HAVE_SYS_SELECT_H 65 # include <sys/select.h> 67 # ifdef HAVE_SYS_TYPES_H 68 # include <sys/types.h> 70 # ifdef HAVE_SYS_TIME_H 71 # include <sys/time.h> 84 #ifdef HAVE_SYS_IOCTL_H 85 # include <sys/ioctl.h> 87 #ifdef HAVE_SYS_SOCKIO_H 88 # include <sys/sockio.h> 94 #ifdef HAVE_SYS_PARAM_H 95 # include <sys/param.h> 97 #ifdef HAVE_SYS_UCRED_H 98 # include <sys/ucred.h> 103 #ifdef HAVE_NET_IF_DL_H 104 # include <net/if_dl.h> 107 #ifndef HAVE_TYPE_SOCKLEN_T 111 #ifdef NEED_IF_INDEXTONAME_DECL 112 char *if_indextoname(
unsigned int,
char *);
114 #ifdef NEED_IF_NAMETOINDEX_DECL 115 unsigned int if_nametoindex(
const char *);
118 #define SOCKLEN_MAX \ 119 (0 < (socklen_t)-1 ? \ 121 (((((socklen_t)1) << (sizeof(socklen_t) * CHAR_BIT - 2)) - 1) * 2 + 1)) 123 #ifndef RSTRING_SOCKLEN 124 # define RSTRING_SOCKLEN (socklen_t)RSTRING_LENINT 128 # define EWOULDBLOCK EAGAIN 138 #define pseudo_AF_FTIP pseudo_AF_RTIP 140 #ifndef HAVE_GETADDRINFO 147 # define NI_MAXHOST 1025 150 # define NI_MAXSERV 32 154 # define IS_IP_FAMILY(af) ((af) == AF_INET || (af) == AF_INET6) 156 # define IS_IP_FAMILY(af) ((af) == AF_INET) 159 #ifndef IN6_IS_ADDR_UNIQUE_LOCAL 160 # define IN6_IS_ADDR_UNIQUE_LOCAL(a) (((a)->s6_addr[0] == 0xfc) || ((a)->s6_addr[0] == 0xfd)) 163 #ifndef HAVE_TYPE_STRUCT_SOCKADDR_STORAGE 167 # define _SS_MAXSIZE 128 168 # define _SS_ALIGNSIZE (sizeof(double)) 169 # define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof(unsigned char) * 2) 170 # define _SS_PAD2SIZE (_SS_MAXSIZE - sizeof(unsigned char) * 2 - \ 171 _SS_PAD1SIZE - _SS_ALIGNSIZE) 174 # ifdef HAVE_STRUCT_SOCKADDR_SA_LEN 175 unsigned char ss_len;
187 struct sockaddr addr;
188 struct sockaddr_in in;
190 struct sockaddr_in6 in6;
192 #ifdef HAVE_TYPE_STRUCT_SOCKADDR_UN 193 struct sockaddr_un un;
195 #ifdef HAVE_TYPE_STRUCT_SOCKADDR_DL 196 struct sockaddr_dl dl;
199 char place_holder[2048];
208 # undef __DARWIN_ALIGNBYTES 209 # define __DARWIN_ALIGNBYTES (sizeof(unsigned int) - 1) 214 # define CMSG_SPACE(len) (_CMSG_ALIGN(sizeof(struct cmsghdr)) + _CMSG_ALIGN(len)) 217 # define CMSG_LEN(len) (_CMSG_ALIGN(sizeof(struct cmsghdr)) + (len)) 221 #define INET_CLIENT 0 222 #define INET_SERVER 1 227 #define FMODE_NOREVLOOKUP 0x100 230 #define FMODE_UNIX 0x00200000 231 #define FMODE_INET 0x00400000 232 #define FMODE_INET6 0x00800000 233 #define FMODE_SOCK (FMODE_UNIX|FMODE_INET|FMODE_INET6) 241 extern VALUE rb_cUNIXSocket;
242 extern VALUE rb_cUNIXServer;
251 extern VALUE rb_cSOCKSSocket;
262 #define BLOCKING_REGION_FD(func, arg) (long)rb_thread_io_blocking_region((func), (arg), (arg)->fd) 264 #define SockAddrStringValue(v) rsock_sockaddr_string_value(&(v)) 265 #define SockAddrStringValuePtr(v) rsock_sockaddr_string_value_ptr(&(v)) 266 #define SockAddrStringValueWithAddrinfo(v, rai_ret) rsock_sockaddr_string_value_with_addrinfo(&(v), &(rai_ret)) 291 int rb_getnameinfo(
const struct sockaddr *sa,
socklen_t salen,
char *host,
size_t hostlen,
char *serv,
size_t servlen,
int flags);
345 int rsock_connect(
int fd,
const struct sockaddr *sockaddr,
int len,
int socks);
354 #if defined(HAVE_SENDMSG) 360 #define rsock_bsock_sendmsg rb_f_notimplement 361 #define rsock_bsock_sendmsg_nonblock rb_f_notimplement 364 #if defined(HAVE_RECVMSG) 369 ssize_t rsock_recvmsg(
int socket,
struct msghdr *message,
int flags);
371 #define rsock_bsock_recvmsg rb_f_notimplement 372 #define rsock_bsock_recvmsg_nonblock rb_f_notimplement 375 #ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL 376 void rsock_discard_cmsg_resource(
struct msghdr *mh,
int msg_peek_p);
414 #if defined(__linux__) 418 # define MSG_DONTWAIT_RELIABLE 1 421 # define rsock_maybe_fd_writable(fd) rb_thread_fd_writable((fd)) 422 # define rsock_maybe_wait_fd(fd) rb_thread_wait_fd((fd)) 429 #ifndef MSG_DONTWAIT_RELIABLE 430 # define MSG_DONTWAIT_RELIABLE 0 433 #if !defined HAVE_INET_NTOP && ! defined _WIN32 434 const char *
inet_ntop(
int,
const void *,
char *,
size_t);
435 #elif defined __MINGW32__ 436 # define inet_ntop(f,a,n,l) rb_w32_inet_ntop(f,a,n,l) 437 #elif defined _MSC_VER && RUBY_MSVCRT_VERSION < 90 438 const char *WSAAPI
inet_ntop(
int,
const void *,
char *,
size_t);
int rsock_optname_arg(int family, int level, VALUE optname)
VALUE rsock_init_unixsock(VALUE sock, VALUE path, int server)
void rsock_syserr_fail_raddrinfo_or_sockaddr(int err, const char *mesg, VALUE addr, VALUE rai)
VALUE rsock_init_inetsock(VALUE sock, VALUE remote_host, VALUE remote_serv, VALUE local_host, VALUE local_serv, int type)
VALUE rsock_addrinfo_inspect_sockaddr(VALUE rai)
void rsock_init_sockifaddr(void)
int rsock_fd_family(int fd)
VALUE rsock_ipaddr(struct sockaddr *sockaddr, socklen_t sockaddrlen, int norevlookup)
int rsock_shutdown_how_arg(VALUE how)
const char * inet_ntop(int, const void *, char *, size_t)
void rsock_init_basicsocket(void)
VALUE rsock_sockaddr_obj(struct sockaddr *addr, socklen_t len)
int rsock_do_not_reverse_lookup
int rsock_level_arg(int family, VALUE level)
VALUE rsock_sock_listen(VALUE sock, VALUE log)
VALUE rsock_bsock_send(int argc, VALUE *argv, VALUE sock)
VALUE rsock_send_blocking(void *data)
VALUE rsock_io_socket_addrinfo(VALUE io, struct sockaddr *addr, socklen_t len)
void rsock_init_unixsocket(void)
#define rsock_maybe_fd_writable(fd)
void rsock_init_socket_init(void)
void rsock_init_tcpserver(void)
#define rsock_bsock_sendmsg
char __ss_pad2[_SS_PAD2SIZE]
int rsock_cmsg_cloexec_state
void rsock_syserr_fail_raddrinfo(int err, const char *mesg, VALUE rai)
VALUE rsock_make_ipaddr(struct sockaddr *addr, socklen_t addrlen)
socklen_t rsock_sockaddr_len(struct sockaddr *addr)
void rsock_init_socket_constants(void)
void rsock_syserr_fail_host_port(int err, const char *mesg, VALUE host, VALUE port)
VALUE rsock_sockaddr_string_value(volatile VALUE *)
VALUE rsock_make_hostent(VALUE host, struct rb_addrinfo *addr, VALUE(*ipaddr)(struct sockaddr *, socklen_t))
VALUE rsock_sock_s_socketpair(int argc, VALUE *argv, VALUE klass)
void rsock_init_tcpsocket(void)
#define rsock_bsock_sendmsg_nonblock
VALUE rsock_addrinfo_new(struct sockaddr *addr, socklen_t len, int family, int socktype, int protocol, VALUE canonname, VALUE inspectname)
void rsock_init_sockssocket(void)
void rsock_syserr_fail_path(int err, const char *mesg, VALUE path)
void rsock_init_sockopt(void)
VALUE rsock_sockaddr_string_value_with_addrinfo(volatile VALUE *v, VALUE *ai_ret)
int rsock_detect_cloexec(int fd)
#define rsock_bsock_recvmsg_nonblock
VALUE rsock_s_recvfrom(VALUE sock, int argc, VALUE *argv, enum sock_recv_type from)
VALUE rb_check_sockaddr_string_type(VALUE)
VALUE rsock_sockopt_new(int family, int level, int optname, VALUE data)
NORETURN(void rsock_raise_socket_error(const char *, int))
void rsock_syserr_fail_sockaddr(int err, const char *mesg, struct sockaddr *addr, socklen_t len)
VALUE rsock_init_sock(VALUE sock, int fd)
VALUE rsock_s_accept_nonblock(VALUE klass, VALUE ex, rb_io_t *fptr, struct sockaddr *sockaddr, socklen_t *len)
void rsock_init_udpsocket(void)
void rsock_sys_fail_sockaddr(const char *mesg, struct sockaddr *addr, socklen_t len)
void rsock_sys_fail_host_port(const char *mesg, VALUE host, VALUE port)
void rsock_init_ipsocket(void)
int rsock_socket(int domain, int type, int proto)
int rsock_revlookup_flag(VALUE revlookup, int *norevlookup)
int rsock_connect(int fd, const struct sockaddr *sockaddr, int len, int socks)
struct rb_addrinfo * rsock_getaddrinfo(VALUE host, VALUE port, struct addrinfo *hints, int socktype_hack)
VALUE rsock_freeaddrinfo(VALUE arg)
register unsigned int len
int rsock_getfamily(rb_io_t *fptr)
void rsock_sys_fail_raddrinfo(const char *mesg, VALUE rai)
int rb_getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags)
int rsock_socktype_arg(VALUE type)
void rsock_sys_fail_raddrinfo_or_sockaddr(const char *mesg, VALUE addr, VALUE rai)
void rsock_raise_socket_error(const char *reason, int error)
#define rsock_maybe_wait_fd(fd)
void rsock_init_ancdata(void)
VALUE rsock_s_recvfrom_nonblock(VALUE sock, VALUE len, VALUE flg, VALUE str, VALUE ex, enum sock_recv_type from)
char __ss_pad1[_SS_PAD1SIZE]
VALUE rsock_inspect_sockaddr(struct sockaddr *addr, socklen_t socklen, VALUE ret)
VALUE rsock_s_accept(VALUE klass, int fd, struct sockaddr *sockaddr, socklen_t *len)
void rsock_init_unixserver(void)
int rsock_family_arg(VALUE domain)
void rsock_sys_fail_path(const char *mesg, VALUE path)
char * rsock_sockaddr_string_value_ptr(volatile VALUE *)
#define rsock_bsock_recvmsg
struct rb_addrinfo * rsock_addrinfo(VALUE host, VALUE port, int family, int socktype, int flags)
int rb_getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct rb_addrinfo **res)
void rsock_init_addrinfo(void)
VALUE rsock_sendto_blocking(void *data)
void rb_freeaddrinfo(struct rb_addrinfo *ai)
int rsock_cmsg_type_arg(int family, int level, VALUE type)
VALUE rsock_fd_socket_addrinfo(int fd, struct sockaddr *addr, socklen_t len)