summaryrefslogtreecommitdiff
path: root/ext/socket/socket.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-02-14 11:28:49 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-02-14 11:28:49 +0000
commit18a8046d1c76209449f11207ba1140d4a6c28a1b (patch)
tree14247717863b13a34b621ebad11921b79760fcda /ext/socket/socket.c
parent64db9dcbd5451f5f3ad4ef69662311a7cbb44a95 (diff)
* ext/socket: always operate length of socket addess companion with
socket address. * ext/socket/rubysocket.h (rsock_make_ipaddr): add an argument for socket address length. (rsock_ipaddr): ditto. * ext/socket/ipsocket.c (ip_addr): pass length to rsock_ipaddr. (ip_peeraddr): ditto. (ip_s_getaddress): pass length to rsock_make_ipaddr. * ext/socket/socket.c (make_addrinfo): pass length to rsock_ipaddr. (sock_s_getnameinfo): pass actual address length to rb_getnameinfo. (sock_s_unpack_sockaddr_in): pass length to rsock_make_ipaddr. * ext/socket/init.c (rsock_s_recvfrom): pass length to rsock_ipaddr. (rsock_s_recvfrom_nonblock): ditto. * ext/socket/tcpsocket.c (tcp_sockaddr): pass length to rsock_make_ipaddr. * ext/socket/raddrinfo.c (make_ipaddr0): add an argument for socket address length. pass the length to rb_getnameinfo. (rsock_ipaddr): ditto. (rsock_make_ipaddr): add an argument for socket address length. pass the length to make_ipaddr0. (make_inetaddr): pass length to make_ipaddr0. a local variable renamed. (host_str): a local variable renamed. (port_str): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39239 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket/socket.c')
-rw-r--r--ext/socket/socket.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index af9c182..4473234 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -937,7 +937,7 @@ make_addrinfo(struct addrinfo *res0, int norevlookup)
}
base = rb_ary_new();
for (res = res0; res; res = res->ai_next) {
- ary = rsock_ipaddr(res->ai_addr, norevlookup);
+ ary = rsock_ipaddr(res->ai_addr, res->ai_addrlen, norevlookup);
if (res->ai_canonname) {
RARRAY_PTR(ary)[2] = rb_str_new2(res->ai_canonname);
}
@@ -1219,6 +1219,7 @@ sock_s_getnameinfo(int argc, VALUE *argv)
int error;
struct sockaddr_storage ss;
struct sockaddr *sap;
+ socklen_t salen;
sa = flags = Qnil;
rb_scan_args(argc, argv, "11", &sa, &flags);
@@ -1238,6 +1239,7 @@ sock_s_getnameinfo(int argc, VALUE *argv)
rb_raise(rb_eTypeError, "sockaddr size differs - should not happen");
}
sap = (struct sockaddr*)&ss;
+ salen = RSTRING_LEN(sa);
goto call_nameinfo;
}
tmp = rb_check_array_type(sa);
@@ -1299,13 +1301,14 @@ sock_s_getnameinfo(int argc, VALUE *argv)
error = rb_getaddrinfo(hptr, pptr, &hints, &res);
if (error) goto error_exit_addr;
sap = res->ai_addr;
+ salen = res->ai_addrlen;
}
else {
rb_raise(rb_eTypeError, "expecting String or Array");
}
call_nameinfo:
- error = rb_getnameinfo(sap, SA_LEN(sap), hbuf, sizeof(hbuf),
+ error = rb_getnameinfo(sap, salen, hbuf, sizeof(hbuf),
pbuf, sizeof(pbuf), fl);
if (error) goto error_exit_name;
if (res) {
@@ -1313,7 +1316,8 @@ sock_s_getnameinfo(int argc, VALUE *argv)
char hbuf2[1024], pbuf2[1024];
sap = r->ai_addr;
- error = rb_getnameinfo(sap, SA_LEN(sap), hbuf2, sizeof(hbuf2),
+ salen = r->ai_addrlen;
+ error = rb_getnameinfo(sap, salen, hbuf2, sizeof(hbuf2),
pbuf2, sizeof(pbuf2), fl);
if (error) goto error_exit_name;
if (strcmp(hbuf, hbuf2) != 0|| strcmp(pbuf, pbuf2) != 0) {
@@ -1399,7 +1403,7 @@ sock_s_unpack_sockaddr_in(VALUE self, VALUE addr)
rb_raise(rb_eArgError, "not an AF_INET sockaddr");
#endif
}
- host = rsock_make_ipaddr((struct sockaddr*)sockaddr);
+ host = rsock_make_ipaddr((struct sockaddr*)sockaddr, RSTRING_LEN(addr));
OBJ_INFECT(host, addr);
return rb_assoc_new(INT2NUM(ntohs(sockaddr->sin_port)), host);
}