Method: Capp.devices
- Defined in:
- ext/capp/capp.c
.devices ⇒ Array
Returns an Array containing the devices and their addresses:
[#<struct Capp::Address
address="lo0",
netmask=nil,
broadcast=
[#<struct Capp::Address
address="0:0:0:0:0:0",
netmask=nil,
broadcast=nil,
destination=nil>,
#<struct Capp::Address
address="fe80::1%lo0",
netmask="ffff:ffff:ffff:ffff::",
broadcast=nil,
destination=nil>,
#<struct Capp::Address
address="127.0.0.1",
netmask="255.0.0.0",
broadcast=nil,
destination=nil>,
#<struct Capp::Address
address="::1",
netmask="ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff",
broadcast=nil,
destination=nil>],
destination=1>,
# [...]
]
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
# File 'ext/capp/capp.c', line 236
static VALUE
capp_s_devices(VALUE klass)
{
VALUE device, devices, dev_args[4];
char errbuf[PCAP_ERRBUF_SIZE];
pcap_if_t *iface, *ifaces;
*errbuf = '\0';
if (pcap_findalldevs(&ifaces, errbuf))
rb_raise(eCappError, "pcap_create: %s", errbuf);
if (*errbuf)
rb_warn("%s", errbuf);
devices = rb_ary_new();
for (iface = ifaces; iface; iface = iface->next) {
dev_args[0] = rb_usascii_str_new_cstr(iface->name);
if (iface->description) {
dev_args[1] = rb_usascii_str_new_cstr(iface->description);
} else {
dev_args[1] = Qnil;
}
dev_args[2] = capp_addr_to_addresses(iface->addresses);
dev_args[3] = UINT2NUM(iface->flags);
device = rb_class_new_instance(4, dev_args, cCappDevice);
rb_ary_push(devices, device);
}
pcap_freealldevs(ifaces);
return devices;
}
|