diff --git a/api/ziflist.api b/api/ziflist.api index b540009b7..ed69a9b40 100644 --- a/api/ziflist.api +++ b/api/ziflist.api @@ -65,4 +65,9 @@ Reload network interfaces from system, including IPv6 + + + Return true if the current interface uses IPv6 + + diff --git a/bindings/jni/src/main/c/org_zeromq_czmq_Ziflist.c b/bindings/jni/src/main/c/org_zeromq_czmq_Ziflist.c index 1bf3d2b97..a3e414e5b 100644 --- a/bindings/jni/src/main/c/org_zeromq_czmq_Ziflist.c +++ b/bindings/jni/src/main/c/org_zeromq_czmq_Ziflist.c @@ -97,6 +97,13 @@ Java_org_zeromq_czmq_Ziflist__1_1reloadIpv6 (JNIEnv *env, jclass c, jlong self) ziflist_reload_ipv6 ((ziflist_t *) (intptr_t) self); } +JNIEXPORT jboolean JNICALL +Java_org_zeromq_czmq_Ziflist__1_1isIpv6 (JNIEnv *env, jclass c, jlong self) +{ + jboolean is_ipv6_ = (jboolean) ziflist_is_ipv6 ((ziflist_t *) (intptr_t) self); + return is_ipv6_; +} + JNIEXPORT void JNICALL Java_org_zeromq_czmq_Ziflist__1_1test (JNIEnv *env, jclass c, jboolean verbose) { diff --git a/bindings/jni/src/main/java/org/zeromq/czmq/Ziflist.java b/bindings/jni/src/main/java/org/zeromq/czmq/Ziflist.java index 889d965c9..f6c3e2629 100644 --- a/bindings/jni/src/main/java/org/zeromq/czmq/Ziflist.java +++ b/bindings/jni/src/main/java/org/zeromq/czmq/Ziflist.java @@ -108,6 +108,13 @@ public void reloadIpv6 () { __reloadIpv6 (self); } /* + Return true if the current interface uses IPv6 + */ + native static boolean __isIpv6 (long self); + public boolean isIpv6 () { + return __isIpv6 (self); + } + /* Self test of this class. */ native static void __test (boolean verbose); diff --git a/bindings/lua_ffi/czmq_ffi.lua b/bindings/lua_ffi/czmq_ffi.lua index ec382fe7f..ef35b4cc4 100644 --- a/bindings/lua_ffi/czmq_ffi.lua +++ b/bindings/lua_ffi/czmq_ffi.lua @@ -1477,6 +1477,10 @@ ziflist_t * void ziflist_reload_ipv6 (ziflist_t *self); +// Return true if the current interface uses IPv6 +bool + ziflist_is_ipv6 (ziflist_t *self); + // Self test of this class. void ziflist_test (bool verbose); diff --git a/bindings/nodejs/README.md b/bindings/nodejs/README.md index e15cebba8..bcf60d757 100644 --- a/bindings/nodejs/README.md +++ b/bindings/nodejs/README.md @@ -1545,6 +1545,12 @@ nothing my_ziflist.reloadIpv6 () Reload network interfaces from system, including IPv6 +``` +boolean my_ziflist.isIpv6 () +``` + +Return true if the current interface uses IPv6 + ``` nothing my_ziflist.test (Boolean) ``` diff --git a/bindings/nodejs/binding.cc b/bindings/nodejs/binding.cc index 26d5c0846..62b8a0e8b 100644 --- a/bindings/nodejs/binding.cc +++ b/bindings/nodejs/binding.cc @@ -2839,6 +2839,7 @@ NAN_MODULE_INIT (Ziflist::Init) { Nan::SetPrototypeMethod (tpl, "print", _print); Nan::SetPrototypeMethod (tpl, "newIpv6", _new_ipv6); Nan::SetPrototypeMethod (tpl, "reloadIpv6", _reload_ipv6); + Nan::SetPrototypeMethod (tpl, "isIpv6", _is_ipv6); Nan::SetPrototypeMethod (tpl, "test", _test); constructor ().Reset (Nan::GetFunction (tpl).ToLocalChecked ()); @@ -2939,6 +2940,12 @@ NAN_METHOD (Ziflist::_reload_ipv6) { ziflist_reload_ipv6 (ziflist->self); } +NAN_METHOD (Ziflist::_is_ipv6) { + Ziflist *ziflist = Nan::ObjectWrap::Unwrap (info.Holder ()); + bool result = ziflist_is_ipv6 (ziflist->self); + info.GetReturnValue ().Set (Nan::New(result)); +} + NAN_METHOD (Ziflist::_test) { if (info [0]->IsUndefined ()) return Nan::ThrowTypeError ("method requires a `verbose`"); diff --git a/bindings/nodejs/binding.h b/bindings/nodejs/binding.h index a8db00ce4..fc6ed66de 100644 --- a/bindings/nodejs/binding.h +++ b/bindings/nodejs/binding.h @@ -414,6 +414,7 @@ class Ziflist: public Nan::ObjectWrap { static NAN_METHOD (_print); static NAN_METHOD (_new_ipv6); static NAN_METHOD (_reload_ipv6); + static NAN_METHOD (_is_ipv6); static NAN_METHOD (_test); }; diff --git a/bindings/python/czmq/_czmq_ctypes.py b/bindings/python/czmq/_czmq_ctypes.py index 885373b60..a2cc94ab1 100644 --- a/bindings/python/czmq/_czmq_ctypes.py +++ b/bindings/python/czmq/_czmq_ctypes.py @@ -3120,6 +3120,8 @@ def test(verbose): lib.ziflist_new_ipv6.argtypes = [] lib.ziflist_reload_ipv6.restype = None lib.ziflist_reload_ipv6.argtypes = [ziflist_p] +lib.ziflist_is_ipv6.restype = c_bool +lib.ziflist_is_ipv6.argtypes = [ziflist_p] lib.ziflist_test.restype = None lib.ziflist_test.argtypes = [c_bool] @@ -3233,6 +3235,12 @@ def reload_ipv6(self): """ return lib.ziflist_reload_ipv6(self._as_parameter_) + def is_ipv6(self): + """ + Return true if the current interface uses IPv6 + """ + return lib.ziflist_is_ipv6(self._as_parameter_) + @staticmethod def test(verbose): """ diff --git a/bindings/python_cffi/czmq_cffi.py b/bindings/python_cffi/czmq_cffi.py index b2378f9fd..e564315db 100644 --- a/bindings/python_cffi/czmq_cffi.py +++ b/bindings/python_cffi/czmq_cffi.py @@ -1504,6 +1504,10 @@ void ziflist_reload_ipv6 (ziflist_t *self); +// Return true if the current interface uses IPv6 +bool + ziflist_is_ipv6 (ziflist_t *self); + // Self test of this class. void ziflist_test (bool verbose); diff --git a/bindings/qml/src/QmlZiflist.cpp b/bindings/qml/src/QmlZiflist.cpp index 8b49b734d..2db46647b 100644 --- a/bindings/qml/src/QmlZiflist.cpp +++ b/bindings/qml/src/QmlZiflist.cpp @@ -62,6 +62,12 @@ void QmlZiflist::reloadIpv6 () { ziflist_reload_ipv6 (self); }; +/// +// Return true if the current interface uses IPv6 +bool QmlZiflist::isIpv6 () { + return ziflist_is_ipv6 (self); +}; + QObject* QmlZiflist::qmlAttachedProperties(QObject* object) { return new QmlZiflistAttached(object); diff --git a/bindings/qml/src/QmlZiflist.h b/bindings/qml/src/QmlZiflist.h index d990b0d8d..29248689b 100644 --- a/bindings/qml/src/QmlZiflist.h +++ b/bindings/qml/src/QmlZiflist.h @@ -54,6 +54,9 @@ public slots: // Reload network interfaces from system, including IPv6 void reloadIpv6 (); + + // Return true if the current interface uses IPv6 + bool isIpv6 (); }; class QmlZiflistAttached : public QObject diff --git a/bindings/qt/src/qziflist.cpp b/bindings/qt/src/qziflist.cpp index b67eefd98..dd447498d 100644 --- a/bindings/qt/src/qziflist.cpp +++ b/bindings/qt/src/qziflist.cpp @@ -110,6 +110,14 @@ void QZiflist::reloadIpv6 () } +/// +// Return true if the current interface uses IPv6 +bool QZiflist::isIpv6 () +{ + bool rv = ziflist_is_ipv6 (self); + return rv; +} + /// // Self test of this class. void QZiflist::test (bool verbose) diff --git a/bindings/qt/src/qziflist.h b/bindings/qt/src/qziflist.h index 4be90e543..c34a69593 100644 --- a/bindings/qt/src/qziflist.h +++ b/bindings/qt/src/qziflist.h @@ -54,6 +54,9 @@ class QT_CZMQ_EXPORT QZiflist : public QObject // Reload network interfaces from system, including IPv6 void reloadIpv6 (); + // Return true if the current interface uses IPv6 + bool isIpv6 (); + // Self test of this class. static void test (bool verbose); diff --git a/bindings/ruby/lib/czmq/ffi.rb b/bindings/ruby/lib/czmq/ffi.rb index 69d0aaae2..3c72b8811 100644 --- a/bindings/ruby/lib/czmq/ffi.rb +++ b/bindings/ruby/lib/czmq/ffi.rb @@ -453,6 +453,17 @@ def self.ziflist_reload_ipv6(*) raise NotImplementedError, "compile CZMQ with --enable-drafts" end end + begin # DRAFT method + attach_function :ziflist_is_ipv6, [:pointer], :bool, **opts + rescue ::FFI::NotFoundError + if $VERBOSE || $DEBUG + warn "The DRAFT function ziflist_is_ipv6()" + + " is not provided by the installed CZMQ library." + end + def self.ziflist_is_ipv6(*) + raise NotImplementedError, "compile CZMQ with --enable-drafts" + end + end attach_function :ziflist_test, [:bool], :void, **opts require_relative 'ffi/ziflist' diff --git a/bindings/ruby/lib/czmq/ffi/ziflist.rb b/bindings/ruby/lib/czmq/ffi/ziflist.rb index b0821a873..586dee5e8 100644 --- a/bindings/ruby/lib/czmq/ffi/ziflist.rb +++ b/bindings/ruby/lib/czmq/ffi/ziflist.rb @@ -190,6 +190,16 @@ def reload_ipv6() result end + # Return true if the current interface uses IPv6 + # + # @return [Boolean] + def is_ipv6() + raise DestroyedError unless @ptr + self_p = @ptr + result = ::CZMQ::FFI.ziflist_is_ipv6(self_p) + result + end + # Self test of this class. # # @param verbose [Boolean] diff --git a/include/ziflist.h b/include/ziflist.h index 8131b2b2d..fa777c1f4 100644 --- a/include/ziflist.h +++ b/include/ziflist.h @@ -82,6 +82,11 @@ CZMQ_EXPORT ziflist_t * CZMQ_EXPORT void ziflist_reload_ipv6 (ziflist_t *self); +// *** Draft method, for development use, may change without warning *** +// Return true if the current interface uses IPv6 +CZMQ_EXPORT bool + ziflist_is_ipv6 (ziflist_t *self); + #endif // CZMQ_BUILD_DRAFT_API // @end diff --git a/src/czmq_classes.h b/src/czmq_classes.h index 326baa9e7..363766785 100644 --- a/src/czmq_classes.h +++ b/src/czmq_classes.h @@ -112,6 +112,11 @@ CZMQ_PRIVATE ziflist_t * CZMQ_PRIVATE void ziflist_reload_ipv6 (ziflist_t *self); +// *** Draft method, defined for internal use only *** +// Return true if the current interface uses IPv6 +CZMQ_PRIVATE bool + ziflist_is_ipv6 (ziflist_t *self); + // *** Draft method, defined for internal use only *** // Return message routing ID, if the message came from a ZMQ_SERVER socket. // Else returns zero. diff --git a/src/ziflist.c b/src/ziflist.c index f4f6b7679..11313e3e8 100644 --- a/src/ziflist.c +++ b/src/ziflist.c @@ -30,6 +30,7 @@ typedef struct { char *address; char *netmask; char *broadcast; + bool is_ipv6; } interface_t; @@ -99,6 +100,8 @@ s_interface_new (char *name, struct sockaddr *address, struct sockaddr *netmask, assert (self->broadcast); } + self->is_ipv6 = address->sa_family == AF_INET6 ? true : false; + return self; } @@ -423,6 +426,18 @@ ziflist_netmask (ziflist_t *self) } +// -------------------------------------------------------------------------- +// Return true if the current interface uses IPv6 + +bool +ziflist_is_ipv6 (ziflist_t *self) +{ + assert (self); + interface_t *iface = (interface_t *) zlistx_item ((zlistx_t *) self); + return iface->is_ipv6; +} + + // -------------------------------------------------------------------------- // Selftest for this class