network_interface 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/Gemfile.lock +1 -1
- data/README.md +70 -2
- data/ext/network_interface_ext/netifaces.c +16 -14
- data/lib/network_interface/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 758a87463cdbf1569ad80a19c47a95e2c91e1eacb6cace97885d84cad09fd8a9
|
4
|
+
data.tar.gz: 6599981462fab25a7914b847f9ddbf42fabf7c260ad3501e3ab3441100e6a6ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf7eaade6035c18e9120a75c0eb86ab2303f9b7ea76f96f6e33b8e256874f854550144f3350309fb6291f2ddd1b78afda9269054c1f3c601ff910c1c6fdeac78
|
7
|
+
data.tar.gz: f5903780de195f98824f5ccdbbee8f749f21094d1885d1e1de5f7d0067ba1c65a3fba1c4ce820bddcf1a48a54ad47b597507bad9ad29bd290fa22a20add80737
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# NetworkInterface
|
2
2
|
|
3
|
-
|
3
|
+
A simple Ruby wrapper for accessing network interface information
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,7 +18,75 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
```ruby
|
22
|
+
require 'network_interface'
|
23
|
+
|
24
|
+
puts NetworkInterface.interfaces
|
25
|
+
puts NetworkInterface.addresses('eth0')
|
26
|
+
```
|
27
|
+
|
28
|
+
## Development
|
29
|
+
|
30
|
+
Compiling:
|
31
|
+
|
32
|
+
```
|
33
|
+
bundle install
|
34
|
+
bundle exec rake clean
|
35
|
+
bundle exec rake compile
|
36
|
+
```
|
37
|
+
|
38
|
+
Running the test suite, requires `ifconfig`/`ipconfig` to be installed:
|
39
|
+
|
40
|
+
```
|
41
|
+
bundle exec rspec
|
42
|
+
```
|
43
|
+
|
44
|
+
To debug with GDB:
|
45
|
+
|
46
|
+
1. Optional: Explicitly add `asm("int3");` into the C code that you wish to have a breakpoint for:
|
47
|
+
|
48
|
+
```c
|
49
|
+
VALUE rb_cNetworkInterface;
|
50
|
+
void
|
51
|
+
Init_network_interface_ext()
|
52
|
+
{
|
53
|
+
asm("int3");
|
54
|
+
|
55
|
+
// ...
|
56
|
+
}
|
57
|
+
```
|
58
|
+
|
59
|
+
2. Compile and start GDB:
|
60
|
+
|
61
|
+
```shell
|
62
|
+
bundle exec rake compile
|
63
|
+
gdb run --args ruby -e '$LOAD_PATH.unshift(File.join(Dir.pwd, "lib")); require("network_interface"); puts NetworkInterface.interfaces'
|
64
|
+
```
|
65
|
+
|
66
|
+
3. Add a runtime breakpoint:
|
67
|
+
|
68
|
+
```shell
|
69
|
+
(gdb) add-symbol-file ./lib/network_interface_ext.so
|
70
|
+
Reading symbols from ./lib/network_interface_ext.so...
|
71
|
+
|
72
|
+
(gdb) break Init_network_interface_ext
|
73
|
+
Breakpoint 1 at 0x1850: file ../../../../ext/network_interface_ext/netifaces.c, line 825.
|
74
|
+
|
75
|
+
(gdb) run
|
76
|
+
Starting program: /usr/bin/ruby -e \$LOAD_PATH.unshift\(File.join\(Dir.pwd,\ \"lib\"\)\)\;\ require\(\"network_interface\"\)\;\ puts\ NetworkInterface.interfaces
|
77
|
+
[Thread debugging using libthread_db enabled]
|
78
|
+
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
|
79
|
+
|
80
|
+
Breakpoint 1.2, Init_network_interface_ext () at ../../../../ext/network_interface_ext/netifaces.c:825
|
81
|
+
825 rb_cNetworkInterface = rb_define_module("NetworkInterface");
|
82
|
+
(gdb)
|
83
|
+
```
|
84
|
+
|
85
|
+
To use a development build of this gem in another project, add this to the target project's `Gemfile`:
|
86
|
+
|
87
|
+
```
|
88
|
+
gem 'network_interface', path: '../network_interface'
|
89
|
+
```
|
22
90
|
|
23
91
|
## Contributing
|
24
92
|
|
@@ -1,6 +1,9 @@
|
|
1
1
|
#include "ruby.h"
|
2
2
|
#include "netifaces.h"
|
3
3
|
|
4
|
+
VALUE rb_cNetworkInterface;
|
5
|
+
VALUE rb_cNetworkInterfaceError;
|
6
|
+
|
4
7
|
#if !defined(WIN32)
|
5
8
|
#if !HAVE_GETNAMEINFO
|
6
9
|
#undef getnameinfo
|
@@ -245,7 +248,7 @@ rbnetifaces_s_addresses (VALUE class, VALUE dev)
|
|
245
248
|
|
246
249
|
if (!pAdapterInfo)
|
247
250
|
{
|
248
|
-
rb_raise(
|
251
|
+
rb_raise(rb_cNetworkInterfaceError, "Could not malloc ADAPTER_INFO");
|
249
252
|
return Qnil;
|
250
253
|
}
|
251
254
|
}
|
@@ -256,7 +259,7 @@ rbnetifaces_s_addresses (VALUE class, VALUE dev)
|
|
256
259
|
{
|
257
260
|
if (pAdapterInfo)
|
258
261
|
free (pAdapterInfo);
|
259
|
-
rb_raise(
|
262
|
+
rb_raise(rb_cNetworkInterfaceError, "Unable to obtain adapter information via GetAdaptersInfo");
|
260
263
|
return Qnil;
|
261
264
|
}
|
262
265
|
|
@@ -347,7 +350,7 @@ rbnetifaces_s_addresses (VALUE class, VALUE dev)
|
|
347
350
|
#elif HAVE_GETIFADDRS
|
348
351
|
if (getifaddrs (&addrs) < 0)
|
349
352
|
{
|
350
|
-
rb_raise(
|
353
|
+
rb_raise(rb_cNetworkInterfaceError, "Unable to retrieve network interface info via getifaddrs");
|
351
354
|
}
|
352
355
|
|
353
356
|
for (addr = addrs; addr; addr = addr->ifa_next)
|
@@ -401,7 +404,7 @@ rbnetifaces_s_addresses (VALUE class, VALUE dev)
|
|
401
404
|
|
402
405
|
if (sock < 0)
|
403
406
|
{
|
404
|
-
|
407
|
+
rb_raise(rb_cNetworkInterfaceError, "Socket not created");
|
405
408
|
return Qnil;
|
406
409
|
}
|
407
410
|
|
@@ -530,7 +533,6 @@ rbnetifaces_s_addresses (VALUE class, VALUE dev)
|
|
530
533
|
return Qnil;
|
531
534
|
|
532
535
|
}
|
533
|
-
|
534
536
|
VALUE
|
535
537
|
rbnetifaces_s_interfaces (VALUE self)
|
536
538
|
{
|
@@ -566,7 +568,7 @@ rbnetifaces_s_interfaces (VALUE self)
|
|
566
568
|
|
567
569
|
if (!pAdapterInfo)
|
568
570
|
{
|
569
|
-
rb_raise(
|
571
|
+
rb_raise(rb_cNetworkInterfaceError, "Could not malloc ADAPTER_INFO");
|
570
572
|
}
|
571
573
|
}
|
572
574
|
} while (dwRet == ERROR_BUFFER_OVERFLOW);
|
@@ -577,7 +579,7 @@ rbnetifaces_s_interfaces (VALUE self)
|
|
577
579
|
if (pAdapterInfo)
|
578
580
|
free (pAdapterInfo);
|
579
581
|
|
580
|
-
rb_raise(
|
582
|
+
rb_raise(rb_cNetworkInterfaceError, "Unable to retrieve adapter info via GetAdaptersInfo");
|
581
583
|
return Qnil;
|
582
584
|
}
|
583
585
|
if (dwRet == ERROR_NO_DATA)
|
@@ -606,7 +608,7 @@ rbnetifaces_s_interfaces (VALUE self)
|
|
606
608
|
#elif HAVE_GETIFADDRS
|
607
609
|
if (getifaddrs (&addrs) < 0)
|
608
610
|
{
|
609
|
-
rb_raise(
|
611
|
+
rb_raise(rb_cNetworkInterfaceError, "Unable to retrieve adapter info via getifaddrs");
|
610
612
|
}
|
611
613
|
|
612
614
|
for (addr = addrs; addr; addr = addr->ifa_next)
|
@@ -628,7 +630,7 @@ rbnetifaces_s_interfaces (VALUE self)
|
|
628
630
|
fd = socket (AF_INET, SOCK_DGRAM, 0);
|
629
631
|
len = -1;
|
630
632
|
if (fd < 0) {
|
631
|
-
rb_raise(
|
633
|
+
rb_raise(rb_cNetworkInterfaceError, "Error creating socket");
|
632
634
|
return Qnil;
|
633
635
|
}
|
634
636
|
|
@@ -661,7 +663,7 @@ rbnetifaces_s_interfaces (VALUE self)
|
|
661
663
|
|
662
664
|
if (!ifc.CNAME(ifc_buf)) {
|
663
665
|
close (fd);
|
664
|
-
rb_raise(
|
666
|
+
rb_raise(rb_cNetworkInterfaceError, "Not enough memory");
|
665
667
|
return Qnil;
|
666
668
|
}
|
667
669
|
|
@@ -673,7 +675,7 @@ rbnetifaces_s_interfaces (VALUE self)
|
|
673
675
|
#endif
|
674
676
|
free (ifc.CNAME(ifc_req));
|
675
677
|
close (fd);
|
676
|
-
rb_raise(
|
678
|
+
rb_raise(rb_cNetworkInterfaceError, "Unable to calculate buffer size");
|
677
679
|
return Qnil;
|
678
680
|
}
|
679
681
|
|
@@ -724,7 +726,7 @@ rbnetifaces_s_interface_info (VALUE self, VALUE dev)
|
|
724
726
|
|
725
727
|
if (!pAdapterInfo)
|
726
728
|
{
|
727
|
-
rb_raise(
|
729
|
+
rb_raise(rb_cNetworkInterfaceError, "Could not malloc ADAPTER_INFO");
|
728
730
|
}
|
729
731
|
}
|
730
732
|
} while (dwRet == ERROR_BUFFER_OVERFLOW);
|
@@ -735,7 +737,7 @@ rbnetifaces_s_interface_info (VALUE self, VALUE dev)
|
|
735
737
|
if (pAdapterInfo)
|
736
738
|
free (pAdapterInfo);
|
737
739
|
|
738
|
-
rb_raise(
|
740
|
+
rb_raise(rb_cNetworkInterfaceError, "Unable to obtain adapter information via GetAdaptersInfo");
|
739
741
|
return Qnil;
|
740
742
|
}
|
741
743
|
if (dwRet == ERROR_NO_DATA)
|
@@ -817,11 +819,11 @@ rbnetifaces_s_interface_info (VALUE self, VALUE dev)
|
|
817
819
|
return result;
|
818
820
|
}
|
819
821
|
|
820
|
-
VALUE rb_cNetworkInterface;
|
821
822
|
void
|
822
823
|
Init_network_interface_ext()
|
823
824
|
{
|
824
825
|
rb_cNetworkInterface = rb_define_module("NetworkInterface");
|
826
|
+
rb_cNetworkInterfaceError = rb_define_class_under(rb_cNetworkInterface, "Error", rb_eRuntimeError);
|
825
827
|
rb_define_module_function(rb_cNetworkInterface, "interfaces", rbnetifaces_s_interfaces, 0);
|
826
828
|
rb_define_module_function(rb_cNetworkInterface, "addresses", rbnetifaces_s_addresses, 1);
|
827
829
|
rb_define_module_function(rb_cNetworkInterface, "interface_info", rbnetifaces_s_interface_info, 1);
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: network_interface
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Turner
|
@@ -94,7 +94,7 @@ cert_chain:
|
|
94
94
|
EknWpNgVhohbot1lfVAMmIhdtOVaRVcQQixWPwprDj/ydB8ryDMDosIMcw+fkoXU
|
95
95
|
9GJsSaSRRYQ9UUkVL27b64okU8D48m8=
|
96
96
|
-----END CERTIFICATE-----
|
97
|
-
date: 2023-08-
|
97
|
+
date: 2023-08-17 00:00:00.000000000 Z
|
98
98
|
dependencies:
|
99
99
|
- !ruby/object:Gem::Dependency
|
100
100
|
name: rake
|
metadata.gz.sig
CHANGED
Binary file
|