summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/socket/raddrinfo.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/ext/socket/raddrinfo.c b/ext/socket/raddrinfo.c
index e9785d448b2..05cd2b2138c 100644
--- a/ext/socket/raddrinfo.c
+++ b/ext/socket/raddrinfo.c
@@ -1592,8 +1592,14 @@ addrinfo_ip_port(VALUE self)
int family = ai_get_afamily(rai);
int port;
- if (!IS_IP_FAMILY(family))
+ if (!IS_IP_FAMILY(family)) {
+ bad_family:
+#ifdef AF_INET6
rb_raise(rb_eSocket, "need IPv4 or IPv6 address");
+#else
+ rb_raise(rb_eSocket, "need IPv4 address");
+#endif
+ }
switch (family) {
case AF_INET:
@@ -1602,14 +1608,16 @@ addrinfo_ip_port(VALUE self)
port = ntohs(((struct sockaddr_in *)&rai->addr)->sin_port);
break;
+#ifdef AF_INET6
case AF_INET6:
if (rai->sockaddr_len != sizeof(struct sockaddr_in6))
rb_raise(rb_eSocket, "unexpected sockaddr size for IPv6");
port = ntohs(((struct sockaddr_in6 *)&rai->addr)->sin6_port);
break;
+#endif
default:
- rb_raise(rb_eSocket, "need IPv4 or IPv6 address");
+ goto bad_family;
}
return INT2NUM(port);