summaryrefslogtreecommitdiff
path: root/ext/socket/ipsocket.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-02-24 17:51:17 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-02-24 17:51:17 +0000
commitc89844dbc50c1422774c39b03e0757c91531e586 (patch)
tree6b025765ef5e602e8d11c3c83b11ed7d5c9361ea /ext/socket/ipsocket.c
parentef339580947c7df1281263ccfb99718887e5378d (diff)
* ext/socket: define and use union_sockaddr instead of struct
sockaddr_storage for less casts. * ext/socket/rubysocket.h (union_sockaddr): defined. * ext/socket/socket.c (sock_accept): use union_sockaddr. (sock_accept_nonblock): ditto. (sock_sysaccept): ditto. (sock_s_getnameinfo): ditto. * ext/socket/basicsocket.c (bsock_getsockname): ditto. (bsock_getpeername): ditto. (bsock_local_address): ditto. (bsock_remote_address): ditto. * ext/socket/ancdata.c (bsock_recvmsg_internal): ditto. * ext/socket/init.c (recvfrom_arg): ditto. (recvfrom_blocking): ditto. (rsock_s_recvfrom): ditto. (rsock_s_recvfrom_nonblock): ditto. (rsock_getfamily): ditto. * ext/socket/raddrinfo.c (rb_addrinfo_t): ditto. (ai_get_afamily): ditto. (inspect_sockaddr): ditto. (addrinfo_mdump): ditto. (addrinfo_mload): ditto. (addrinfo_getnameinfo): ditto. (addrinfo_ip_port): ditto. (extract_in_addr): ditto. (addrinfo_ipv6_to_ipv4): ditto. (addrinfo_unix_path): ditto. * ext/socket/tcpserver.c (tcp_accept): ditto. (tcp_accept_nonblock): ditto. (tcp_sysaccept): ditto. * ext/socket/ipsocket.c (ip_addr): ditto. (ip_peeraddr): ditto. (ip_s_getaddress): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39477 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket/ipsocket.c')
-rw-r--r--ext/socket/ipsocket.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/ext/socket/ipsocket.c b/ext/socket/ipsocket.c
index bd14ba9..84bc897 100644
--- a/ext/socket/ipsocket.c
+++ b/ext/socket/ipsocket.c
@@ -184,7 +184,7 @@ static VALUE
ip_addr(int argc, VALUE *argv, VALUE sock)
{
rb_io_t *fptr;
- struct sockaddr_storage addr;
+ union_sockaddr addr;
socklen_t len = (socklen_t)sizeof addr;
int norevlookup;
@@ -192,9 +192,9 @@ ip_addr(int argc, VALUE *argv, VALUE sock)
if (argc < 1 || !rsock_revlookup_flag(argv[0], &norevlookup))
norevlookup = fptr->mode & FMODE_NOREVLOOKUP;
- if (getsockname(fptr->fd, (struct sockaddr*)&addr, &len) < 0)
+ if (getsockname(fptr->fd, &addr.addr, &len) < 0)
rb_sys_fail("getsockname(2)");
- return rsock_ipaddr((struct sockaddr*)&addr, len, norevlookup);
+ return rsock_ipaddr(&addr.addr, len, norevlookup);
}
/*
@@ -225,7 +225,7 @@ static VALUE
ip_peeraddr(int argc, VALUE *argv, VALUE sock)
{
rb_io_t *fptr;
- struct sockaddr_storage addr;
+ union_sockaddr addr;
socklen_t len = (socklen_t)sizeof addr;
int norevlookup;
@@ -233,9 +233,9 @@ ip_peeraddr(int argc, VALUE *argv, VALUE sock)
if (argc < 1 || !rsock_revlookup_flag(argv[0], &norevlookup))
norevlookup = fptr->mode & FMODE_NOREVLOOKUP;
- if (getpeername(fptr->fd, (struct sockaddr*)&addr, &len) < 0)
+ if (getpeername(fptr->fd, &addr.addr, &len) < 0)
rb_sys_fail("getpeername(2)");
- return rsock_ipaddr((struct sockaddr*)&addr, len, norevlookup);
+ return rsock_ipaddr(&addr.addr, len, norevlookup);
}
/*
@@ -278,14 +278,14 @@ ip_recvfrom(int argc, VALUE *argv, VALUE sock)
static VALUE
ip_s_getaddress(VALUE obj, VALUE host)
{
- struct sockaddr_storage addr;
+ union_sockaddr addr;
struct addrinfo *res = rsock_addrinfo(host, Qnil, SOCK_STREAM, 0);
/* just take the first one */
memcpy(&addr, res->ai_addr, res->ai_addrlen);
freeaddrinfo(res);
- return rsock_make_ipaddr((struct sockaddr*)&addr, res->ai_addrlen);
+ return rsock_make_ipaddr(&addr.addr, res->ai_addrlen);
}
void