summaryrefslogtreecommitdiff
path: root/ext/socket/raddrinfo.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/raddrinfo.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/raddrinfo.c')
-rw-r--r--ext/socket/raddrinfo.c34
1 files changed, 17 insertions, 17 deletions
diff --git a/ext/socket/raddrinfo.c b/ext/socket/raddrinfo.c
index a730a1b..8282173 100644
--- a/ext/socket/raddrinfo.c
+++ b/ext/socket/raddrinfo.c
@@ -229,27 +229,27 @@ rb_getnameinfo(const struct sockaddr *sa, socklen_t salen,
}
static void
-make_ipaddr0(struct sockaddr *addr, char *buf, size_t len)
+make_ipaddr0(struct sockaddr *addr, socklen_t addrlen, char *buf, size_t buflen)
{
int error;
- error = rb_getnameinfo(addr, SA_LEN(addr), buf, len, NULL, 0, NI_NUMERICHOST);
+ error = rb_getnameinfo(addr, addrlen, buf, buflen, NULL, 0, NI_NUMERICHOST);
if (error) {
rsock_raise_socket_error("getnameinfo", error);
}
}
VALUE
-rsock_make_ipaddr(struct sockaddr *addr)
+rsock_make_ipaddr(struct sockaddr *addr, socklen_t addrlen)
{
char hbuf[1024];
- make_ipaddr0(addr, hbuf, sizeof(hbuf));
+ make_ipaddr0(addr, addrlen, hbuf, sizeof(hbuf));
return rb_str_new2(hbuf);
}
static void
-make_inetaddr(unsigned int host, char *buf, size_t len)
+make_inetaddr(unsigned int host, char *buf, size_t buflen)
{
struct sockaddr_in sin;
@@ -257,7 +257,7 @@ make_inetaddr(unsigned int host, char *buf, size_t len)
sin.sin_family = AF_INET;
SET_SIN_LEN(&sin, sizeof(sin));
sin.sin_addr.s_addr = host;
- make_ipaddr0((struct sockaddr*)&sin, buf, len);
+ make_ipaddr0((struct sockaddr*)&sin, sizeof(sin), buf, buflen);
}
static int
@@ -276,7 +276,7 @@ str_is_number(const char *p)
}
static char*
-host_str(VALUE host, char *hbuf, size_t len, int *flags_ptr)
+host_str(VALUE host, char *hbuf, size_t hbuflen, int *flags_ptr)
{
if (NIL_P(host)) {
return NULL;
@@ -284,7 +284,7 @@ host_str(VALUE host, char *hbuf, size_t len, int *flags_ptr)
else if (rb_obj_is_kind_of(host, rb_cInteger)) {
unsigned int i = NUM2UINT(host);
- make_inetaddr(htonl(i), hbuf, len);
+ make_inetaddr(htonl(i), hbuf, hbuflen);
if (flags_ptr) *flags_ptr |= AI_NUMERICHOST;
return hbuf;
}
@@ -294,14 +294,14 @@ host_str(VALUE host, char *hbuf, size_t len, int *flags_ptr)
SafeStringValue(host);
name = RSTRING_PTR(host);
if (!name || *name == 0 || (name[0] == '<' && strcmp(name, "<any>") == 0)) {
- make_inetaddr(INADDR_ANY, hbuf, len);
+ make_inetaddr(INADDR_ANY, hbuf, hbuflen);
if (flags_ptr) *flags_ptr |= AI_NUMERICHOST;
}
else if (name[0] == '<' && strcmp(name, "<broadcast>") == 0) {
- make_inetaddr(INADDR_BROADCAST, hbuf, len);
+ make_inetaddr(INADDR_BROADCAST, hbuf, hbuflen);
if (flags_ptr) *flags_ptr |= AI_NUMERICHOST;
}
- else if (strlen(name) >= len) {
+ else if (strlen(name) >= hbuflen) {
rb_raise(rb_eArgError, "hostname too long (%"PRIuSIZE")",
strlen(name));
}
@@ -313,13 +313,13 @@ host_str(VALUE host, char *hbuf, size_t len, int *flags_ptr)
}
static char*
-port_str(VALUE port, char *pbuf, size_t len, int *flags_ptr)
+port_str(VALUE port, char *pbuf, size_t pbuflen, int *flags_ptr)
{
if (NIL_P(port)) {
return 0;
}
else if (FIXNUM_P(port)) {
- snprintf(pbuf, len, "%ld", FIX2LONG(port));
+ snprintf(pbuf, pbuflen, "%ld", FIX2LONG(port));
#ifdef AI_NUMERICSERV
if (flags_ptr) *flags_ptr |= AI_NUMERICSERV;
#endif
@@ -330,7 +330,7 @@ port_str(VALUE port, char *pbuf, size_t len, int *flags_ptr)
SafeStringValue(port);
serv = RSTRING_PTR(port);
- if (strlen(serv) >= len) {
+ if (strlen(serv) >= pbuflen) {
rb_raise(rb_eArgError, "service name too long (%"PRIuSIZE")",
strlen(serv));
}
@@ -380,7 +380,7 @@ rsock_addrinfo(VALUE host, VALUE port, int socktype, int flags)
}
VALUE
-rsock_ipaddr(struct sockaddr *sockaddr, int norevlookup)
+rsock_ipaddr(struct sockaddr *sockaddr, socklen_t sockaddrlen, int norevlookup)
{
VALUE family, port, addr1, addr2;
VALUE ary;
@@ -399,13 +399,13 @@ rsock_ipaddr(struct sockaddr *sockaddr, int norevlookup)
addr1 = Qnil;
if (!norevlookup) {
- error = rb_getnameinfo(sockaddr, SA_LEN(sockaddr), hbuf, sizeof(hbuf),
+ error = rb_getnameinfo(sockaddr, sockaddrlen, hbuf, sizeof(hbuf),
NULL, 0, 0);
if (! error) {
addr1 = rb_str_new2(hbuf);
}
}
- error = rb_getnameinfo(sockaddr, SA_LEN(sockaddr), hbuf, sizeof(hbuf),
+ error = rb_getnameinfo(sockaddr, sockaddrlen, hbuf, sizeof(hbuf),
pbuf, sizeof(pbuf), NI_NUMERICHOST | NI_NUMERICSERV);
if (error) {
rsock_raise_socket_error("getnameinfo", error);