diff --git a/ChangeLog b/ChangeLog index ba2ebc4553..3f05db5699 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Tue Feb 10 23:30:32 2009 Tanaka Akira + + * ext/socket/basicsocket.c (bsock_getpeername): use struct + sockaddr_storage. + (bsock_local_address): ditto. + (bsock_remote_address): ditto. + Tue Feb 10 21:26:33 2009 Tanaka Akira * ext/socket/lib/socket.rb (Socket.udp_server_sockets): new method. diff --git a/ext/socket/basicsocket.c b/ext/socket/basicsocket.c index 7690fb60ef..88f8b1ba67 100644 --- a/ext/socket/basicsocket.c +++ b/ext/socket/basicsocket.c @@ -351,14 +351,14 @@ bsock_getsockname(VALUE sock) static VALUE bsock_getpeername(VALUE sock) { - char buf[1024]; + struct sockaddr_storage buf; socklen_t len = sizeof buf; rb_io_t *fptr; GetOpenFile(sock, fptr); - if (getpeername(fptr->fd, (struct sockaddr*)buf, &len) < 0) + if (getpeername(fptr->fd, (struct sockaddr*)&buf, &len) < 0) rb_sys_fail("getpeername(2)"); - return rb_str_new(buf, len); + return rb_str_new((char*)&buf, len); } /* @@ -377,14 +377,14 @@ bsock_getpeername(VALUE sock) static VALUE bsock_local_address(VALUE sock) { - char buf[1024]; + struct sockaddr_storage buf; socklen_t len = sizeof buf; rb_io_t *fptr; GetOpenFile(sock, fptr); - if (getsockname(fptr->fd, (struct sockaddr*)buf, &len) < 0) + if (getsockname(fptr->fd, (struct sockaddr*)&buf, &len) < 0) rb_sys_fail("getsockname(2)"); - return fd_socket_addrinfo(fptr->fd, (struct sockaddr *)buf, len); + return fd_socket_addrinfo(fptr->fd, (struct sockaddr *)&buf, len); } /* @@ -405,14 +405,14 @@ bsock_local_address(VALUE sock) static VALUE bsock_remote_address(VALUE sock) { - char buf[1024]; + struct sockaddr_storage buf; socklen_t len = sizeof buf; rb_io_t *fptr; GetOpenFile(sock, fptr); - if (getpeername(fptr->fd, (struct sockaddr*)buf, &len) < 0) + if (getpeername(fptr->fd, (struct sockaddr*)&buf, &len) < 0) rb_sys_fail("getpeername(2)"); - return fd_socket_addrinfo(fptr->fd, (struct sockaddr *)buf, len); + return fd_socket_addrinfo(fptr->fd, (struct sockaddr *)&buf, len); } /*