Skip to content

Commit 0b3a4c5

Browse files
authored
Feature: adding macaddress to ziflist items (#2259)
1 parent 4390cc8 commit 0b3a4c5

File tree

24 files changed

+220
-7
lines changed

24 files changed

+220
-7
lines changed

AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,4 @@ Michal Hrusecky
6767
Alena Chernikava
6868
Stephen Procter
6969
Wes Young
70+
Arnaud Loonstra

api/python_cffi.slurp

+4
Original file line numberDiff line numberDiff line change
@@ -1625,6 +1625,10 @@ const char *
16251625
const char *
16261626
ziflist_netmask (ziflist_t *self);
16271627

1628+
// Return the current interface MAC address as a printable string
1629+
const char *
1630+
ziflist_mac (ziflist_t *self);
1631+
16281632
// Return the list of interfaces.
16291633
void
16301634
ziflist_print (ziflist_t *self);

api/ziflist.api

+5
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@
5252
<return type = "string" />
5353
</method>
5454

55+
<method name = "mac" state = "draft">
56+
Return the current interface MAC address as a printable string
57+
<return type = "string" />
58+
</method>
59+
5560
<method name = "print">
5661
Return the list of interfaces.
5762
</method>

bindings/delphi/CZMQ.pas

+11
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,9 @@ interface
892892
// Return the current interface network mask as a printable string
893893
function Netmask: string;
894894

895+
// Return the current interface MAC address as a printable string
896+
function Mac: string;
897+
895898
// Return the list of interfaces.
896899
procedure Print;
897900

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

3623+
// Return the current interface MAC address as a printable string
3624+
function Mac: string;
3625+
36203626
// Return the list of interfaces.
36213627
procedure Print;
36223628

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

7670+
function TZiflist.Mac: string;
7671+
begin
7672+
Result := string(UTF8String(ziflist_mac(FHandle)));
7673+
end;
7674+
76647675
procedure TZiflist.Print;
76657676
begin
76667677
ziflist_print(FHandle);

bindings/delphi/libczmq.pas

+3
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,9 @@ interface
13151315
// Return the current interface network mask as a printable string
13161316
function ziflist_netmask(self: PZiflist): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
13171317

1318+
// Return the current interface MAC address as a printable string
1319+
function ziflist_mac(self: PZiflist): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1320+
13181321
// Return the list of interfaces.
13191322
procedure ziflist_print(self: PZiflist); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
13201323

bindings/jni/czmq-jni/src/main/c/org_zeromq_czmq_Ziflist.c

+8
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ Java_org_zeromq_czmq_Ziflist__1_1netmask (JNIEnv *env, jclass c, jlong self)
7878
return return_string_;
7979
}
8080

81+
JNIEXPORT jstring JNICALL
82+
Java_org_zeromq_czmq_Ziflist__1_1mac (JNIEnv *env, jclass c, jlong self)
83+
{
84+
char *mac_ = (char *) ziflist_mac ((ziflist_t *) (intptr_t) self);
85+
jstring return_string_ = (*env)->NewStringUTF (env, mac_);
86+
return return_string_;
87+
}
88+
8189
JNIEXPORT void JNICALL
8290
Java_org_zeromq_czmq_Ziflist__1_1print (JNIEnv *env, jclass c, jlong self)
8391
{

bindings/jni/czmq-jni/src/main/java/org/zeromq/czmq/Ziflist.java

+7
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ public String netmask () {
9696
return __netmask (self);
9797
}
9898
/*
99+
Return the current interface MAC address as a printable string
100+
*/
101+
native static String __mac (long self);
102+
public String mac () {
103+
return __mac (self);
104+
}
105+
/*
99106
Return the list of interfaces.
100107
*/
101108
native static void __print (long self);

bindings/lua_ffi/czmq_ffi.lua

+4
Original file line numberDiff line numberDiff line change
@@ -1620,6 +1620,10 @@ const char *
16201620
const char *
16211621
ziflist_netmask (ziflist_t *self);
16221622

1623+
// Return the current interface MAC address as a printable string
1624+
const char *
1625+
ziflist_mac (ziflist_t *self);
1626+
16231627
// Return the list of interfaces.
16241628
void
16251629
ziflist_print (ziflist_t *self);

bindings/nodejs/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -1691,6 +1691,12 @@ string my_ziflist.netmask ()
16911691

16921692
Return the current interface network mask as a printable string
16931693

1694+
```
1695+
string my_ziflist.mac ()
1696+
```
1697+
1698+
Return the current interface MAC address as a printable string
1699+
16941700
```
16951701
nothing my_ziflist.print ()
16961702
```

bindings/nodejs/binding.cc

+7
Original file line numberDiff line numberDiff line change
@@ -3261,6 +3261,7 @@ NAN_MODULE_INIT (Ziflist::Init) {
32613261
Nan::SetPrototypeMethod (tpl, "address", _address);
32623262
Nan::SetPrototypeMethod (tpl, "broadcast", _broadcast);
32633263
Nan::SetPrototypeMethod (tpl, "netmask", _netmask);
3264+
Nan::SetPrototypeMethod (tpl, "mac", _mac);
32643265
Nan::SetPrototypeMethod (tpl, "print", _print);
32653266
Nan::SetPrototypeMethod (tpl, "newIpv6", _new_ipv6);
32663267
Nan::SetPrototypeMethod (tpl, "reloadIpv6", _reload_ipv6);
@@ -3344,6 +3345,12 @@ NAN_METHOD (Ziflist::_netmask) {
33443345
info.GetReturnValue ().Set (Nan::New (result).ToLocalChecked ());
33453346
}
33463347

3348+
NAN_METHOD (Ziflist::_mac) {
3349+
Ziflist *ziflist = Nan::ObjectWrap::Unwrap <Ziflist> (info.Holder ());
3350+
char *result = (char *) ziflist_mac (ziflist->self);
3351+
info.GetReturnValue ().Set (Nan::New (result).ToLocalChecked ());
3352+
}
3353+
33473354
NAN_METHOD (Ziflist::_print) {
33483355
Ziflist *ziflist = Nan::ObjectWrap::Unwrap <Ziflist> (info.Holder ());
33493356
ziflist_print (ziflist->self);

bindings/nodejs/binding.h

+1
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ class Ziflist: public Nan::ObjectWrap {
445445
static NAN_METHOD (_address);
446446
static NAN_METHOD (_broadcast);
447447
static NAN_METHOD (_netmask);
448+
static NAN_METHOD (_mac);
448449
static NAN_METHOD (_print);
449450
static NAN_METHOD (_new_ipv6);
450451
static NAN_METHOD (_reload_ipv6);

bindings/python/czmq/_czmq_ctypes.py

+8
Original file line numberDiff line numberDiff line change
@@ -3451,6 +3451,8 @@ def test(verbose):
34513451
lib.ziflist_broadcast.argtypes = [ziflist_p]
34523452
lib.ziflist_netmask.restype = c_char_p
34533453
lib.ziflist_netmask.argtypes = [ziflist_p]
3454+
lib.ziflist_mac.restype = c_char_p
3455+
lib.ziflist_mac.argtypes = [ziflist_p]
34543456
lib.ziflist_print.restype = None
34553457
lib.ziflist_print.argtypes = [ziflist_p]
34563458
lib.ziflist_new_ipv6.restype = ziflist_p
@@ -3552,6 +3554,12 @@ def netmask(self):
35523554
"""
35533555
return lib.ziflist_netmask(self._as_parameter_)
35543556

3557+
def mac(self):
3558+
"""
3559+
Return the current interface MAC address as a printable string
3560+
"""
3561+
return lib.ziflist_mac(self._as_parameter_)
3562+
35553563
def print(self):
35563564
"""
35573565
Return the list of interfaces.

bindings/python_cffi/czmq_cffi/Ziflist.py

+6
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ def netmask(self):
6666
"""
6767
return utils.lib.ziflist_netmask(self._p)
6868

69+
def mac(self):
70+
"""
71+
Return the current interface MAC address as a printable string
72+
"""
73+
return utils.lib.ziflist_mac(self._p)
74+
6975
def print_py(self):
7076
"""
7177
Return the list of interfaces.

bindings/python_cffi/czmq_cffi/cdefs.py

+4
Original file line numberDiff line numberDiff line change
@@ -1627,6 +1627,10 @@
16271627
const char *
16281628
ziflist_netmask (ziflist_t *self);
16291629
1630+
// Return the current interface MAC address as a printable string
1631+
const char *
1632+
ziflist_mac (ziflist_t *self);
1633+
16301634
// Return the list of interfaces.
16311635
void
16321636
ziflist_print (ziflist_t *self);

bindings/qml/src/QmlZiflist.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ const QString QmlZiflist::netmask () {
5050
return QString (ziflist_netmask (self));
5151
};
5252

53+
///
54+
// Return the current interface MAC address as a printable string
55+
const QString QmlZiflist::mac () {
56+
return QString (ziflist_mac (self));
57+
};
58+
5359
///
5460
// Return the list of interfaces.
5561
void QmlZiflist::print () {

bindings/qml/src/QmlZiflist.h

+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public slots:
4949
// Return the current interface network mask as a printable string
5050
const QString netmask ();
5151

52+
// Return the current interface MAC address as a printable string
53+
const QString mac ();
54+
5255
// Return the list of interfaces.
5356
void print ();
5457

bindings/qt/src/qziflist.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ const QString QZiflist::netmask ()
8585
return rv;
8686
}
8787

88+
///
89+
// Return the current interface MAC address as a printable string
90+
const QString QZiflist::mac ()
91+
{
92+
const QString rv = QString (ziflist_mac (self));
93+
return rv;
94+
}
95+
8896
///
8997
// Return the list of interfaces.
9098
void QZiflist::print ()

bindings/qt/src/qziflist.h

+3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ class QT_CZMQ_EXPORT QZiflist : public QObject
4444
// Return the current interface network mask as a printable string
4545
const QString netmask ();
4646

47+
// Return the current interface MAC address as a printable string
48+
const QString mac ();
49+
4750
// Return the list of interfaces.
4851
void print ();
4952

bindings/ruby/lib/czmq/ffi.rb

+1
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ def self.attach_function(name, *rest)
383383
attach_function :ziflist_address, [:pointer], :string, **opts
384384
attach_function :ziflist_broadcast, [:pointer], :string, **opts
385385
attach_function :ziflist_netmask, [:pointer], :string, **opts
386+
attach_function :ziflist_mac, [:pointer], :string, **opts
386387
attach_function :ziflist_print, [:pointer], :void, **opts
387388
attach_function :ziflist_new_ipv6, [], :pointer, **opts
388389
attach_function :ziflist_reload_ipv6, [:pointer], :void, **opts

bindings/ruby/lib/czmq/ffi/ziflist.rb

+10
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,16 @@ def netmask()
160160
result
161161
end
162162

163+
# Return the current interface MAC address as a printable string
164+
#
165+
# @return [String]
166+
def mac()
167+
raise DestroyedError unless @ptr
168+
self_p = @ptr
169+
result = ::CZMQ::FFI.ziflist_mac(self_p)
170+
result
171+
end
172+
163173
# Return the list of interfaces.
164174
#
165175
# @return [void]

include/czmq_prelude.h

+9
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,15 @@
327327
# if (defined (__UTYPE_LINUX) && defined (HAVE_LIBSYSTEMD))
328328
# include <systemd/sd-daemon.h>
329329
# endif
330+
# if (defined (HAVE_GETIFADDRS))
331+
# if (defined (__UTYPE_OSX))
332+
# include <net/ethernet.h> // For struct sockaddr_dl
333+
# include <net/if_dl.h>
334+
# include <net/if_types.h>
335+
# else
336+
# include <netpacket/packet.h> // For struct sockaddr_ll
337+
# endif
338+
# endif
330339
#endif
331340

332341
#if (defined (__VMS__))

include/ziflist.h

+5
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ CZMQ_EXPORT void
7070
ziflist_test (bool verbose);
7171

7272
#ifdef CZMQ_BUILD_DRAFT_API
73+
// *** Draft method, for development use, may change without warning ***
74+
// Return the current interface MAC address as a printable string
75+
CZMQ_EXPORT const char *
76+
ziflist_mac (ziflist_t *self);
77+
7378
// *** Draft method, for development use, may change without warning ***
7479
// Get a list of network interfaces currently defined on the system
7580
// Includes IPv6 interfaces

src/czmq_classes.h

+5
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,11 @@ CZMQ_PRIVATE zframe_t *
212212
CZMQ_PRIVATE zhashx_t *
213213
zhashx_unpack_own (zframe_t *frame, zhashx_deserializer_fn deserializer);
214214

215+
// *** Draft method, defined for internal use only ***
216+
// Return the current interface MAC address as a printable string
217+
CZMQ_PRIVATE const char *
218+
ziflist_mac (ziflist_t *self);
219+
215220
// *** Draft method, defined for internal use only ***
216221
// Get a list of network interfaces currently defined on the system
217222
// Includes IPv6 interfaces

0 commit comments

Comments
 (0)