From 2ee08591190bed1f57a43a5cdd6486e3abfa664f Mon Sep 17 00:00:00 2001 From: akr Date: Tue, 10 Feb 2009 14:46:51 +0000 Subject: [PATCH] * ext/socket/init.c (struct recvfrom_arg): use struct sockaddr_storage. (recvfrom_blocking): follow struct recvfrom_arg change. (s_recvfrom): ditto. (s_recvfrom_nonblock): use struct sockaddr_storage. * ext/socket/socket.c (sock_accept): use struct sockaddr_storage. (sock_accept_nonblock): ditto. (sock_sysaccept): ditto. * ext/socket/ancdata.c (bsock_recvmsg_internal): use struct sockaddr_storage. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22214 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 15 +++++++++++++++ ext/socket/ancdata.c | 6 +++--- ext/socket/init.c | 18 +++++++++--------- ext/socket/socket.c | 18 +++++++++--------- 4 files changed, 36 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3f05db5699..9aa81fa902 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +Tue Feb 10 23:44:53 2009 Tanaka Akira + + * ext/socket/init.c (struct recvfrom_arg): use struct + sockaddr_storage. + (recvfrom_blocking): follow struct recvfrom_arg change. + (s_recvfrom): ditto. + (s_recvfrom_nonblock): use struct sockaddr_storage. + + * ext/socket/socket.c (sock_accept): use struct sockaddr_storage. + (sock_accept_nonblock): ditto. + (sock_sysaccept): ditto. + + * ext/socket/ancdata.c (bsock_recvmsg_internal): use struct + sockaddr_storage. + Tue Feb 10 23:30:32 2009 Tanaka Akira * ext/socket/basicsocket.c (bsock_getpeername): use struct diff --git a/ext/socket/ancdata.c b/ext/socket/ancdata.c index 5e6920de1a..7f55f3b4fd 100644 --- a/ext/socket/ancdata.c +++ b/ext/socket/ancdata.c @@ -952,7 +952,7 @@ bsock_recvmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock) #if defined(HAVE_ST_MSG_CONTROL) struct cmsghdr *cmh; #endif - char namebuf[1024]; + struct sockaddr_storage namebuf; char datbuf0[4096], *datbuf; char ctlbuf0[4096], *ctlbuf; VALUE dat_str = Qnil; @@ -1014,8 +1014,8 @@ bsock_recvmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock) memset(&mh, 0, sizeof(mh)); - memset(namebuf, 0, sizeof(namebuf)); - mh.msg_name = namebuf; + memset(&namebuf, 0, sizeof(namebuf)); + mh.msg_name = (struct sockaddr *)&namebuf; mh.msg_namelen = sizeof(namebuf); mh.msg_iov = &iov; diff --git a/ext/socket/init.c b/ext/socket/init.c index f0e34d1fa8..4665e3e49a 100644 --- a/ext/socket/init.c +++ b/ext/socket/init.c @@ -78,7 +78,7 @@ struct recvfrom_arg { int fd, flags; VALUE str; socklen_t alen; - char buf[1024]; + struct sockaddr_storage buf; }; static VALUE @@ -86,7 +86,7 @@ recvfrom_blocking(void *data) { struct recvfrom_arg *arg = data; return (VALUE)recvfrom(arg->fd, RSTRING_PTR(arg->str), RSTRING_LEN(arg->str), - arg->flags, (struct sockaddr*)arg->buf, &arg->alen); + arg->flags, (struct sockaddr*)&arg->buf, &arg->alen); } VALUE @@ -139,16 +139,16 @@ 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, ipaddr((struct sockaddr*)arg.buf, fptr->mode & FMODE_NOREVLOOKUP)); + return rb_assoc_new(str, ipaddr((struct sockaddr*)&arg.buf, fptr->mode & FMODE_NOREVLOOKUP)); else return rb_assoc_new(str, Qnil); #ifdef HAVE_SYS_UN_H case RECV_UNIX: - return rb_assoc_new(str, unixaddr((struct sockaddr_un*)arg.buf, arg.alen)); + return rb_assoc_new(str, unixaddr((struct sockaddr_un*)&arg.buf, arg.alen)); #endif case RECV_SOCKET: - return rb_assoc_new(str, io_socket_addrinfo(sock, (struct sockaddr*)arg.buf, arg.alen)); + return rb_assoc_new(str, io_socket_addrinfo(sock, (struct sockaddr*)&arg.buf, arg.alen)); default: rb_bug("s_recvfrom called with bad value"); } @@ -159,7 +159,7 @@ s_recvfrom_nonblock(VALUE sock, int argc, VALUE *argv, enum sock_recv_type from) { rb_io_t *fptr; VALUE str; - char buf[1024]; + struct sockaddr_storage buf; socklen_t alen = sizeof buf; VALUE len, flg; long buflen; @@ -189,7 +189,7 @@ s_recvfrom_nonblock(VALUE sock, int argc, VALUE *argv, enum sock_recv_type from) rb_io_check_closed(fptr); rb_io_set_nonblock(fptr); - slen = recvfrom(fd, RSTRING_PTR(str), buflen, flags, (struct sockaddr*)buf, &alen); + slen = recvfrom(fd, RSTRING_PTR(str), buflen, flags, (struct sockaddr*)&buf, &alen); if (slen < 0) { rb_sys_fail("recvfrom(2)"); @@ -204,11 +204,11 @@ s_recvfrom_nonblock(VALUE sock, int argc, VALUE *argv, enum sock_recv_type from) case RECV_IP: if (alen && alen != sizeof(buf)) /* connection-oriented socket may not return a from result */ - addr = ipaddr((struct sockaddr*)buf, fptr->mode & FMODE_NOREVLOOKUP); + addr = ipaddr((struct sockaddr*)&buf, fptr->mode & FMODE_NOREVLOOKUP); break; case RECV_SOCKET: - addr = io_socket_addrinfo(sock, (struct sockaddr*)buf, alen); + addr = io_socket_addrinfo(sock, (struct sockaddr*)&buf, alen); break; default: diff --git a/ext/socket/socket.c b/ext/socket/socket.c index 7e33de1411..abce61307a 100644 --- a/ext/socket/socket.c +++ b/ext/socket/socket.c @@ -688,13 +688,13 @@ sock_accept(VALUE sock) { rb_io_t *fptr; VALUE sock2; - char buf[1024]; + struct sockaddr_storage buf; socklen_t len = sizeof buf; GetOpenFile(sock, fptr); - sock2 = s_accept(rb_cSocket,fptr->fd,(struct sockaddr*)buf,&len); + sock2 = s_accept(rb_cSocket,fptr->fd,(struct sockaddr*)&buf,&len); - return rb_assoc_new(sock2, io_socket_addrinfo(sock2, (struct sockaddr*)buf, len)); + return rb_assoc_new(sock2, io_socket_addrinfo(sock2, (struct sockaddr*)&buf, len)); } /* @@ -750,12 +750,12 @@ sock_accept_nonblock(VALUE sock) { rb_io_t *fptr; VALUE sock2; - char buf[1024]; + struct sockaddr_storage buf; socklen_t len = sizeof buf; GetOpenFile(sock, fptr); - sock2 = s_accept_nonblock(rb_cSocket, fptr, (struct sockaddr *)buf, &len); - return rb_assoc_new(sock2, io_socket_addrinfo(sock2, (struct sockaddr*)buf, len)); + sock2 = s_accept_nonblock(rb_cSocket, fptr, (struct sockaddr *)&buf, &len); + return rb_assoc_new(sock2, io_socket_addrinfo(sock2, (struct sockaddr*)&buf, len)); } /* @@ -802,13 +802,13 @@ sock_sysaccept(VALUE sock) { rb_io_t *fptr; VALUE sock2; - char buf[1024]; + struct sockaddr_storage buf; socklen_t len = sizeof buf; GetOpenFile(sock, fptr); - sock2 = s_accept(0,fptr->fd,(struct sockaddr*)buf,&len); + sock2 = s_accept(0,fptr->fd,(struct sockaddr*)&buf,&len); - return rb_assoc_new(sock2, io_socket_addrinfo(sock2, (struct sockaddr*)buf, len)); + return rb_assoc_new(sock2, io_socket_addrinfo(sock2, (struct sockaddr*)&buf, len)); } #ifdef HAVE_GETHOSTNAME