summaryrefslogtreecommitdiff
path: root/ext/socket/init.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/init.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/init.c')
-rw-r--r--ext/socket/init.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/ext/socket/init.c b/ext/socket/init.c
index fc3ab49..44228d3 100644
--- a/ext/socket/init.c
+++ b/ext/socket/init.c
@@ -91,7 +91,7 @@ struct recvfrom_arg {
int fd, flags;
VALUE str;
socklen_t alen;
- struct sockaddr_storage buf;
+ union_sockaddr buf;
};
static VALUE
@@ -101,7 +101,7 @@ recvfrom_blocking(void *data)
socklen_t len0 = arg->alen;
ssize_t ret;
ret = recvfrom(arg->fd, RSTRING_PTR(arg->str), RSTRING_LEN(arg->str),
- arg->flags, (struct sockaddr*)&arg->buf, &arg->alen);
+ arg->flags, &arg->buf.addr, &arg->alen);
if (ret != -1 && len0 < arg->alen)
arg->alen = len0;
return (VALUE)ret;
@@ -160,16 +160,16 @@ rsock_s_recvfrom(VALUE sock, int argc, VALUE *argv, enum sock_recv_type from)
}
#endif
if (arg.alen && arg.alen != sizeof(arg.buf)) /* OSX doesn't return a from result for connection-oriented sockets */
- return rb_assoc_new(str, rsock_ipaddr((struct sockaddr*)&arg.buf, arg.alen, fptr->mode & FMODE_NOREVLOOKUP));
+ return rb_assoc_new(str, rsock_ipaddr(&arg.buf.addr, arg.alen, fptr->mode & FMODE_NOREVLOOKUP));
else
return rb_assoc_new(str, Qnil);
#ifdef HAVE_SYS_UN_H
case RECV_UNIX:
- return rb_assoc_new(str, rsock_unixaddr((struct sockaddr_un*)&arg.buf, arg.alen));
+ return rb_assoc_new(str, rsock_unixaddr(&arg.buf.un, arg.alen));
#endif
case RECV_SOCKET:
- return rb_assoc_new(str, rsock_io_socket_addrinfo(sock, (struct sockaddr*)&arg.buf, arg.alen));
+ return rb_assoc_new(str, rsock_io_socket_addrinfo(sock, &arg.buf.addr, arg.alen));
default:
rb_bug("rsock_s_recvfrom called with bad value");
}
@@ -180,7 +180,7 @@ rsock_s_recvfrom_nonblock(VALUE sock, int argc, VALUE *argv, enum sock_recv_type
{
rb_io_t *fptr;
VALUE str;
- struct sockaddr_storage buf;
+ union_sockaddr buf;
socklen_t alen = (socklen_t)sizeof buf;
VALUE len, flg;
long buflen;
@@ -212,7 +212,7 @@ rsock_s_recvfrom_nonblock(VALUE sock, int argc, VALUE *argv, enum sock_recv_type
rb_io_check_closed(fptr);
rb_io_set_nonblock(fptr);
len0 = alen;
- slen = recvfrom(fd, RSTRING_PTR(str), buflen, flags, (struct sockaddr*)&buf, &alen);
+ slen = recvfrom(fd, RSTRING_PTR(str), buflen, flags, &buf.addr, &alen);
if (slen != -1 && len0 < alen)
alen = len0;
@@ -236,11 +236,11 @@ rsock_s_recvfrom_nonblock(VALUE sock, int argc, VALUE *argv, enum sock_recv_type
case RECV_IP:
if (alen && alen != sizeof(buf)) /* connection-oriented socket may not return a from result */
- addr = rsock_ipaddr((struct sockaddr*)&buf, alen, fptr->mode & FMODE_NOREVLOOKUP);
+ addr = rsock_ipaddr(&buf.addr, alen, fptr->mode & FMODE_NOREVLOOKUP);
break;
case RECV_SOCKET:
- addr = rsock_io_socket_addrinfo(sock, (struct sockaddr*)&buf, alen);
+ addr = rsock_io_socket_addrinfo(sock, &buf.addr, alen);
break;
default:
@@ -596,14 +596,14 @@ rsock_s_accept(VALUE klass, int fd, struct sockaddr *sockaddr, socklen_t *len)
int
rsock_getfamily(int sockfd)
{
- struct sockaddr_storage ss;
+ union_sockaddr ss;
socklen_t sslen = (socklen_t)sizeof(ss);
- ss.ss_family = AF_UNSPEC;
- if (getsockname(sockfd, (struct sockaddr*)&ss, &sslen) < 0)
+ ss.addr.sa_family = AF_UNSPEC;
+ if (getsockname(sockfd, &ss.addr, &sslen) < 0)
return AF_UNSPEC;
- return ss.ss_family;
+ return ss.addr.sa_family;
}
void