Skip to content

Commit

Permalink
Feature: adding macaddress to ziflist items (#2259)
Browse files Browse the repository at this point in the history
  • Loading branch information
sphaero authored Feb 28, 2023
1 parent 4390cc8 commit 0b3a4c5
Show file tree
Hide file tree
Showing 24 changed files with 220 additions and 7 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,4 @@ Michal Hrusecky
Alena Chernikava
Stephen Procter
Wes Young
Arnaud Loonstra
4 changes: 4 additions & 0 deletions api/python_cffi.slurp
Original file line number Diff line number Diff line change
Expand Up @@ -1625,6 +1625,10 @@ const char *
const char *
ziflist_netmask (ziflist_t *self);

// Return the current interface MAC address as a printable string
const char *
ziflist_mac (ziflist_t *self);

// Return the list of interfaces.
void
ziflist_print (ziflist_t *self);
Expand Down
5 changes: 5 additions & 0 deletions api/ziflist.api
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
<return type = "string" />
</method>

<method name = "mac" state = "draft">
Return the current interface MAC address as a printable string
<return type = "string" />
</method>

<method name = "print">
Return the list of interfaces.
</method>
Expand Down
11 changes: 11 additions & 0 deletions bindings/delphi/CZMQ.pas
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,9 @@ interface
// Return the current interface network mask as a printable string
function Netmask: string;

// Return the current interface MAC address as a printable string
function Mac: string;

// Return the list of interfaces.
procedure Print;

Expand Down Expand Up @@ -3617,6 +3620,9 @@ TZiflist = class(TInterfacedObject, IZiflist)
// Return the current interface network mask as a printable string
function Netmask: string;

// Return the current interface MAC address as a printable string
function Mac: string;

// Return the list of interfaces.
procedure Print;

Expand Down Expand Up @@ -7661,6 +7667,11 @@ function ZFreeString(const str: PAnsiChar): string;
Result := string(UTF8String(ziflist_netmask(FHandle)));
end;

function TZiflist.Mac: string;
begin
Result := string(UTF8String(ziflist_mac(FHandle)));
end;

procedure TZiflist.Print;
begin
ziflist_print(FHandle);
Expand Down
3 changes: 3 additions & 0 deletions bindings/delphi/libczmq.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,9 @@ interface
// Return the current interface network mask as a printable string
function ziflist_netmask(self: PZiflist): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};

// Return the current interface MAC address as a printable string
function ziflist_mac(self: PZiflist): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};

// Return the list of interfaces.
procedure ziflist_print(self: PZiflist); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};

Expand Down
8 changes: 8 additions & 0 deletions bindings/jni/czmq-jni/src/main/c/org_zeromq_czmq_Ziflist.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ Java_org_zeromq_czmq_Ziflist__1_1netmask (JNIEnv *env, jclass c, jlong self)
return return_string_;
}

JNIEXPORT jstring JNICALL
Java_org_zeromq_czmq_Ziflist__1_1mac (JNIEnv *env, jclass c, jlong self)
{
char *mac_ = (char *) ziflist_mac ((ziflist_t *) (intptr_t) self);
jstring return_string_ = (*env)->NewStringUTF (env, mac_);
return return_string_;
}

JNIEXPORT void JNICALL
Java_org_zeromq_czmq_Ziflist__1_1print (JNIEnv *env, jclass c, jlong self)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ public String netmask () {
return __netmask (self);
}
/*
Return the current interface MAC address as a printable string
*/
native static String __mac (long self);
public String mac () {
return __mac (self);
}
/*
Return the list of interfaces.
*/
native static void __print (long self);
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 @@ -1620,6 +1620,10 @@ const char *
const char *
ziflist_netmask (ziflist_t *self);

// Return the current interface MAC address as a printable string
const char *
ziflist_mac (ziflist_t *self);

// Return the list of interfaces.
void
ziflist_print (ziflist_t *self);
Expand Down
6 changes: 6 additions & 0 deletions bindings/nodejs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1691,6 +1691,12 @@ string my_ziflist.netmask ()

Return the current interface network mask as a printable string

```
string my_ziflist.mac ()
```

Return the current interface MAC address as a printable string

```
nothing my_ziflist.print ()
```
Expand Down
7 changes: 7 additions & 0 deletions bindings/nodejs/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3261,6 +3261,7 @@ NAN_MODULE_INIT (Ziflist::Init) {
Nan::SetPrototypeMethod (tpl, "address", _address);
Nan::SetPrototypeMethod (tpl, "broadcast", _broadcast);
Nan::SetPrototypeMethod (tpl, "netmask", _netmask);
Nan::SetPrototypeMethod (tpl, "mac", _mac);
Nan::SetPrototypeMethod (tpl, "print", _print);
Nan::SetPrototypeMethod (tpl, "newIpv6", _new_ipv6);
Nan::SetPrototypeMethod (tpl, "reloadIpv6", _reload_ipv6);
Expand Down Expand Up @@ -3344,6 +3345,12 @@ NAN_METHOD (Ziflist::_netmask) {
info.GetReturnValue ().Set (Nan::New (result).ToLocalChecked ());
}

NAN_METHOD (Ziflist::_mac) {
Ziflist *ziflist = Nan::ObjectWrap::Unwrap <Ziflist> (info.Holder ());
char *result = (char *) ziflist_mac (ziflist->self);
info.GetReturnValue ().Set (Nan::New (result).ToLocalChecked ());
}

NAN_METHOD (Ziflist::_print) {
Ziflist *ziflist = Nan::ObjectWrap::Unwrap <Ziflist> (info.Holder ());
ziflist_print (ziflist->self);
Expand Down
1 change: 1 addition & 0 deletions bindings/nodejs/binding.h
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ class Ziflist: public Nan::ObjectWrap {
static NAN_METHOD (_address);
static NAN_METHOD (_broadcast);
static NAN_METHOD (_netmask);
static NAN_METHOD (_mac);
static NAN_METHOD (_print);
static NAN_METHOD (_new_ipv6);
static NAN_METHOD (_reload_ipv6);
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 @@ -3451,6 +3451,8 @@ def test(verbose):
lib.ziflist_broadcast.argtypes = [ziflist_p]
lib.ziflist_netmask.restype = c_char_p
lib.ziflist_netmask.argtypes = [ziflist_p]
lib.ziflist_mac.restype = c_char_p
lib.ziflist_mac.argtypes = [ziflist_p]
lib.ziflist_print.restype = None
lib.ziflist_print.argtypes = [ziflist_p]
lib.ziflist_new_ipv6.restype = ziflist_p
Expand Down Expand Up @@ -3552,6 +3554,12 @@ def netmask(self):
"""
return lib.ziflist_netmask(self._as_parameter_)

def mac(self):
"""
Return the current interface MAC address as a printable string
"""
return lib.ziflist_mac(self._as_parameter_)

def print(self):
"""
Return the list of interfaces.
Expand Down
6 changes: 6 additions & 0 deletions bindings/python_cffi/czmq_cffi/Ziflist.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ def netmask(self):
"""
return utils.lib.ziflist_netmask(self._p)

def mac(self):
"""
Return the current interface MAC address as a printable string
"""
return utils.lib.ziflist_mac(self._p)

def print_py(self):
"""
Return the list of interfaces.
Expand Down
4 changes: 4 additions & 0 deletions bindings/python_cffi/czmq_cffi/cdefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1627,6 +1627,10 @@
const char *
ziflist_netmask (ziflist_t *self);
// Return the current interface MAC address as a printable string
const char *
ziflist_mac (ziflist_t *self);
// Return the list of interfaces.
void
ziflist_print (ziflist_t *self);
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 @@ -50,6 +50,12 @@ const QString QmlZiflist::netmask () {
return QString (ziflist_netmask (self));
};

///
// Return the current interface MAC address as a printable string
const QString QmlZiflist::mac () {
return QString (ziflist_mac (self));
};

///
// Return the list of interfaces.
void QmlZiflist::print () {
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 @@ -49,6 +49,9 @@ public slots:
// Return the current interface network mask as a printable string
const QString netmask ();

// Return the current interface MAC address as a printable string
const QString mac ();

// Return the list of interfaces.
void print ();

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 @@ -85,6 +85,14 @@ const QString QZiflist::netmask ()
return rv;
}

///
// Return the current interface MAC address as a printable string
const QString QZiflist::mac ()
{
const QString rv = QString (ziflist_mac (self));
return rv;
}

///
// Return the list of interfaces.
void QZiflist::print ()
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 @@ -44,6 +44,9 @@ class QT_CZMQ_EXPORT QZiflist : public QObject
// Return the current interface network mask as a printable string
const QString netmask ();

// Return the current interface MAC address as a printable string
const QString mac ();

// Return the list of interfaces.
void print ();

Expand Down
1 change: 1 addition & 0 deletions bindings/ruby/lib/czmq/ffi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ def self.attach_function(name, *rest)
attach_function :ziflist_address, [:pointer], :string, **opts
attach_function :ziflist_broadcast, [:pointer], :string, **opts
attach_function :ziflist_netmask, [:pointer], :string, **opts
attach_function :ziflist_mac, [:pointer], :string, **opts
attach_function :ziflist_print, [:pointer], :void, **opts
attach_function :ziflist_new_ipv6, [], :pointer, **opts
attach_function :ziflist_reload_ipv6, [:pointer], :void, **opts
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 @@ -160,6 +160,16 @@ def netmask()
result
end

# Return the current interface MAC address as a printable string
#
# @return [String]
def mac()
raise DestroyedError unless @ptr
self_p = @ptr
result = ::CZMQ::FFI.ziflist_mac(self_p)
result
end

# Return the list of interfaces.
#
# @return [void]
Expand Down
9 changes: 9 additions & 0 deletions include/czmq_prelude.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,15 @@
# if (defined (__UTYPE_LINUX) && defined (HAVE_LIBSYSTEMD))
# include <systemd/sd-daemon.h>
# endif
# if (defined (HAVE_GETIFADDRS))
# if (defined (__UTYPE_OSX))
# include <net/ethernet.h> // For struct sockaddr_dl
# include <net/if_dl.h>
# include <net/if_types.h>
# else
# include <netpacket/packet.h> // For struct sockaddr_ll
# endif
# endif
#endif

#if (defined (__VMS__))
Expand Down
5 changes: 5 additions & 0 deletions include/ziflist.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ CZMQ_EXPORT void
ziflist_test (bool verbose);

#ifdef CZMQ_BUILD_DRAFT_API
// *** Draft method, for development use, may change without warning ***
// Return the current interface MAC address as a printable string
CZMQ_EXPORT const char *
ziflist_mac (ziflist_t *self);

// *** Draft method, for development use, may change without warning ***
// Get a list of network interfaces currently defined on the system
// Includes IPv6 interfaces
Expand Down
5 changes: 5 additions & 0 deletions src/czmq_classes.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ CZMQ_PRIVATE zframe_t *
CZMQ_PRIVATE zhashx_t *
zhashx_unpack_own (zframe_t *frame, zhashx_deserializer_fn deserializer);

// *** Draft method, defined for internal use only ***
// Return the current interface MAC address as a printable string
CZMQ_PRIVATE const char *
ziflist_mac (ziflist_t *self);

// *** Draft method, defined for internal use only ***
// Get a list of network interfaces currently defined on the system
// Includes IPv6 interfaces
Expand Down
Loading

0 comments on commit 0b3a4c5

Please sign in to comment.