Skip to content

Commit

Permalink
Problem: no way to check if ziflist interface has IPv6
Browse files Browse the repository at this point in the history
Solution: add a new (draft) ziflist_is_ipv6 API that returns
true/false.
  • Loading branch information
bluca committed Jan 29, 2017
1 parent d9dad1d commit 4e89146
Show file tree
Hide file tree
Showing 18 changed files with 115 additions and 0 deletions.
5 changes: 5 additions & 0 deletions api/ziflist.api
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,9 @@
<method name = "reload ipv6" state = "draft">
Reload network interfaces from system, including IPv6
</method>

<method name = "is ipv6" state = "draft">
Return true if the current interface uses IPv6
<return type = "boolean" />
</method>
</class>
7 changes: 7 additions & 0 deletions bindings/jni/src/main/c/org_zeromq_czmq_Ziflist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
7 changes: 7 additions & 0 deletions bindings/jni/src/main/java/org/zeromq/czmq/Ziflist.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions bindings/lua_ffi/czmq_ffi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions bindings/nodejs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```
Expand Down
7 changes: 7 additions & 0 deletions bindings/nodejs/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 ());
Expand Down Expand Up @@ -2939,6 +2940,12 @@ NAN_METHOD (Ziflist::_reload_ipv6) {
ziflist_reload_ipv6 (ziflist->self);
}

NAN_METHOD (Ziflist::_is_ipv6) {
Ziflist *ziflist = Nan::ObjectWrap::Unwrap <Ziflist> (info.Holder ());
bool result = ziflist_is_ipv6 (ziflist->self);
info.GetReturnValue ().Set (Nan::New<Boolean>(result));
}

NAN_METHOD (Ziflist::_test) {
if (info [0]->IsUndefined ())
return Nan::ThrowTypeError ("method requires a `verbose`");
Expand Down
1 change: 1 addition & 0 deletions bindings/nodejs/binding.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
8 changes: 8 additions & 0 deletions bindings/python/czmq/_czmq_ctypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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):
"""
Expand Down
4 changes: 4 additions & 0 deletions bindings/python_cffi/czmq_cffi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions bindings/qml/src/QmlZiflist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions bindings/qml/src/QmlZiflist.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions bindings/qt/src/qziflist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions bindings/qt/src/qziflist.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
11 changes: 11 additions & 0 deletions bindings/ruby/lib/czmq/ffi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
10 changes: 10 additions & 0 deletions bindings/ruby/lib/czmq/ffi/ziflist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
5 changes: 5 additions & 0 deletions include/ziflist.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions src/czmq_classes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 15 additions & 0 deletions src/ziflist.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ typedef struct {
char *address;
char *netmask;
char *broadcast;
bool is_ipv6;
} interface_t;


Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 4e89146

Please sign in to comment.