Method: Capp.live
- Defined in:
- ext/capp/capp.c
.live ⇒ Object .device ⇒ Object .device ⇒ Object .device ⇒ Object .device ⇒ Object
Creates a Capp instance that will capture packets from a network device.
device is the device to capture packets from. If the device is omitted the default device (::default_device_name) is used.
capture_length is the number of bytes to capture from each packet. If a length is omitted 65535 is used.
promiscuous places the device in promiscuous mode when true, allowing you to see packets not sent directly to or from the device. Promiscuous mode is enabled by default.
The timeout is the number of maximum number of milliseconds that will elapse between receiving a packet and yielding it to the block given to #loop. The default timeout is 10 milliseconds. See #timeout= for further discussion.
After creating an instance use #loop to start capturing packets.
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
# File 'ext/capp/capp.c', line 300 static VALUE capp_s_open_live(int argc, VALUE *argv, VALUE klass) { VALUE obj, device, snaplen, promiscuous, timeout; int promisc = 0; char errbuf[PCAP_ERRBUF_SIZE]; pcap_t *handle; rb_scan_args(argc, argv, "04", &device, &snaplen, &promiscuous, &timeout); if (!RTEST(device)) device = capp_s_default_device_name(klass); if (!RTEST(snaplen)) snaplen = INT2NUM(65535); if (!RTEST(promiscuous)) promiscuous = Qtrue; if (!RTEST(timeout)) timeout = INT2NUM(10); if (RTEST(promiscuous)) promisc = 1; *errbuf = '\0'; handle = pcap_open_live(StringValueCStr(device), NUM2INT(snaplen), promisc, NUM2INT(timeout), errbuf); if (NULL == handle) rb_raise(eCappError, "pcap_create: %s", errbuf); if (*errbuf) rb_warn("%s", errbuf); obj = Data_Wrap_Struct(klass, NULL, pcap_close, handle); rb_ivar_set(obj, id_iv_device, device); return obj; } |