summaryrefslogtreecommitdiff
path: root/ext/socket
diff options
context:
space:
mode:
Diffstat (limited to 'ext/socket')
-rw-r--r--ext/socket/extconf.rb15
-rw-r--r--ext/socket/ifaddr.c4
-rw-r--r--ext/socket/rubysocket.h7
3 files changed, 25 insertions, 1 deletions
diff --git a/ext/socket/extconf.rb b/ext/socket/extconf.rb
index 88e7366..458871f 100644
--- a/ext/socket/extconf.rb
+++ b/ext/socket/extconf.rb
@@ -421,7 +421,20 @@ EOF
have_func("getpeerucred(0, (ucred_t **)NULL)", headers) # SunOS
- have_func('if_indextoname(0, "")', headers)
+ have_func_decl = proc do |name, headers|
+ if !checking_for("declaration of #{name}()") {!%w[int void].all? {|ret| try_compile(<<EOF)}}
+#{cpp_include(headers)}
+#{ret} #{name}(void);
+EOF
+ $defs << "-DNEED_#{name.tr_cpp}_DECL"
+ end
+ end
+ if have_func('if_indextoname(0, "")', headers)
+ have_func_decl["if_indextoname"]
+ end
+ if have_func('if_nametoindex("")', headers)
+ have_func_decl["if_nametoindex"]
+ end
have_func("hsterror", headers)
have_func('getipnodebyname("", 0, 0, (int *)0)', headers) # RFC 2553
diff --git a/ext/socket/ifaddr.c b/ext/socket/ifaddr.c
index 446fe20..e5eb48b 100644
--- a/ext/socket/ifaddr.c
+++ b/ext/socket/ifaddr.c
@@ -135,6 +135,7 @@ ifaddr_name(VALUE self)
* Returns the interface index of _ifaddr_.
*/
+#ifdef HAVE_IF_NAMETOINDEX
static VALUE
ifaddr_ifindex(VALUE self)
{
@@ -146,6 +147,9 @@ ifaddr_ifindex(VALUE self)
}
return UINT2NUM(ifindex);
}
+#else
+#define ifaddr_ifindex rb_f_notimplement
+#endif
/*
* call-seq:
diff --git a/ext/socket/rubysocket.h b/ext/socket/rubysocket.h
index 7b1d43a..97c02fc 100644
--- a/ext/socket/rubysocket.h
+++ b/ext/socket/rubysocket.h
@@ -106,6 +106,13 @@
typedef int socklen_t;
#endif
+#ifdef NEED_IF_INDEXTONAME_DECL
+char *if_indextoname(unsigned int, char *);
+#endif
+#ifdef NEED_IF_NAMETOINDEX_DECL
+unsigned int if_nametoindex(const char *);
+#endif
+
#define SOCKLEN_MAX \
(0 < (socklen_t)-1 ? \
~(socklen_t)0 : \