summaryrefslogtreecommitdiff
path: root/ext/socket/socket.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/socket.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/socket.c')
-rw-r--r--ext/socket/socket.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index 7e5a8b9..a8f38ce 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -755,13 +755,13 @@ sock_accept(VALUE sock)
{
rb_io_t *fptr;
VALUE sock2;
- struct sockaddr_storage buf;
+ union_sockaddr buf;
socklen_t len = (socklen_t)sizeof buf;
GetOpenFile(sock, fptr);
- sock2 = rsock_s_accept(rb_cSocket,fptr->fd,(struct sockaddr*)&buf,&len);
+ sock2 = rsock_s_accept(rb_cSocket,fptr->fd,&buf.addr,&len);
- return rb_assoc_new(sock2, rsock_io_socket_addrinfo(sock2, (struct sockaddr*)&buf, len));
+ return rb_assoc_new(sock2, rsock_io_socket_addrinfo(sock2, &buf.addr, len));
}
/*
@@ -820,12 +820,12 @@ sock_accept_nonblock(VALUE sock)
{
rb_io_t *fptr;
VALUE sock2;
- struct sockaddr_storage buf;
+ union_sockaddr buf;
socklen_t len = (socklen_t)sizeof buf;
GetOpenFile(sock, fptr);
- sock2 = rsock_s_accept_nonblock(rb_cSocket, fptr, (struct sockaddr *)&buf, &len);
- return rb_assoc_new(sock2, rsock_io_socket_addrinfo(sock2, (struct sockaddr*)&buf, len));
+ sock2 = rsock_s_accept_nonblock(rb_cSocket, fptr, &buf.addr, &len);
+ return rb_assoc_new(sock2, rsock_io_socket_addrinfo(sock2, &buf.addr, len));
}
/*
@@ -871,13 +871,13 @@ sock_sysaccept(VALUE sock)
{
rb_io_t *fptr;
VALUE sock2;
- struct sockaddr_storage buf;
+ union_sockaddr buf;
socklen_t len = (socklen_t)sizeof buf;
GetOpenFile(sock, fptr);
- sock2 = rsock_s_accept(0,fptr->fd,(struct sockaddr*)&buf,&len);
+ sock2 = rsock_s_accept(0,fptr->fd,&buf.addr,&len);
- return rb_assoc_new(sock2, rsock_io_socket_addrinfo(sock2, (struct sockaddr*)&buf, len));
+ return rb_assoc_new(sock2, rsock_io_socket_addrinfo(sock2, &buf.addr, len));
}
#ifdef HAVE_GETHOSTNAME
@@ -1217,7 +1217,7 @@ sock_s_getnameinfo(int argc, VALUE *argv)
int fl;
struct addrinfo hints, *res = NULL, *r;
int error;
- struct sockaddr_storage ss;
+ union_sockaddr ss;
struct sockaddr *sap;
socklen_t salen;
@@ -1235,10 +1235,10 @@ sock_s_getnameinfo(int argc, VALUE *argv)
rb_raise(rb_eTypeError, "sockaddr length too big");
}
memcpy(&ss, RSTRING_PTR(sa), RSTRING_LEN(sa));
- if (!VALIDATE_SOCKLEN((struct sockaddr *)&ss, RSTRING_LEN(sa))) {
+ if (!VALIDATE_SOCKLEN(&ss.addr, RSTRING_LEN(sa))) {
rb_raise(rb_eTypeError, "sockaddr size differs - should not happen");
}
- sap = (struct sockaddr*)&ss;
+ sap = &ss.addr;
salen = RSTRING_LENINT(sa);
goto call_nameinfo;
}
@@ -1658,7 +1658,7 @@ socket_s_ip_address_list(VALUE self)
#elif defined(SIOCGIFCONF)
int fd = -1;
int ret;
-#define EXTRA_SPACE (sizeof(struct ifconf) + sizeof(struct sockaddr_storage))
+#define EXTRA_SPACE (sizeof(struct ifconf) + sizeof(union_sockaddr))
char initbuf[4096+EXTRA_SPACE];
char *buf = initbuf;
int bufsize;