summaryrefslogtreecommitdiff
path: root/ext/socket
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-01-07 15:21:43 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-01-07 15:21:43 +0000
commit69d908a10c6ed9e1dd9887d5fe89fc71ec15437b (patch)
tree7543063bac2dc34312e93c7daa7349cad29c8a85 /ext/socket
parent0e9023acd07476e1a8bd613f395c95b71b277086 (diff)
* ext/socket/socket.c (host_str): add flags_ptr argument to specify
AI_NUMERICHOST if host is numeric form. (port_str): add flags_ptr argument to specify AI_NUMERICSERV if port is numeric form. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21373 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket')
-rw-r--r--ext/socket/socket.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index 12b6fda877d..49bd7503c5b 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -1101,7 +1101,7 @@ str_isnumber(const char *p)
}
static char*
-host_str(VALUE host, char *hbuf, size_t len)
+host_str(VALUE host, char *hbuf, size_t len, int *flags_ptr)
{
if (NIL_P(host)) {
return NULL;
@@ -1110,6 +1110,7 @@ host_str(VALUE host, char *hbuf, size_t len)
unsigned long i = NUM2ULONG(host);
make_inetaddr(htonl(i), hbuf, len);
+ if (flags_ptr) *flags_ptr |= AI_NUMERICHOST;
return hbuf;
}
else {
@@ -1119,9 +1120,11 @@ host_str(VALUE host, char *hbuf, size_t len)
name = RSTRING_PTR(host);
if (!name || *name == 0 || (name[0] == '<' && strcmp(name, "<any>") == 0)) {
make_inetaddr(INADDR_ANY, hbuf, len);
+ if (flags_ptr) *flags_ptr |= AI_NUMERICHOST;
}
else if (name[0] == '<' && strcmp(name, "<broadcast>") == 0) {
make_inetaddr(INADDR_BROADCAST, hbuf, len);
+ if (flags_ptr) *flags_ptr |= AI_NUMERICHOST;
}
else if (strlen(name) >= len) {
rb_raise(rb_eArgError, "hostname too long (%"PRIuSIZE")",
@@ -1135,13 +1138,14 @@ host_str(VALUE host, char *hbuf, size_t len)
}
static char*
-port_str(VALUE port, char *pbuf, size_t len)
+port_str(VALUE port, char *pbuf, size_t len, int *flags_ptr)
{
if (NIL_P(port)) {
return 0;
}
else if (FIXNUM_P(port)) {
snprintf(pbuf, len, "%ld", FIX2LONG(port));
+ if (flags_ptr) *flags_ptr |= AI_NUMERICSERV;
return pbuf;
}
else {
@@ -1172,13 +1176,15 @@ sock_getaddrinfo(VALUE host, VALUE port, struct addrinfo *hints, int socktype_ha
char *hostp, *portp;
int error;
char hbuf[NI_MAXHOST], pbuf[NI_MAXSERV];
+ int additional_flags = 0;
- hostp = host_str(host, hbuf, sizeof(hbuf));
- portp = port_str(port, pbuf, sizeof(pbuf));
+ hostp = host_str(host, hbuf, sizeof(hbuf), &additional_flags);
+ portp = port_str(port, pbuf, sizeof(pbuf), &additional_flags);
if (socktype_hack && hints->ai_socktype == 0 && str_isnumber(portp)) {
hints->ai_socktype = SOCK_DGRAM;
}
+ hints->ai_flags |= additional_flags;
error = rb_getaddrinfo(hostp, portp, hints, &res);
if (error) {
@@ -1662,7 +1668,7 @@ make_hostent_internal(struct hostent_arg *arg)
hostp = addr->ai_canonname;
}
else {
- hostp = host_str(host, hbuf, sizeof(hbuf));
+ hostp = host_str(host, hbuf, sizeof(hbuf), NULL);
}
rb_ary_push(ary, rb_str_new2(hostp));