class PCAPRUB::Packet
Public Class Methods
new()
click to toggle source
Creates a new Packet instance and returns the object itself.
static VALUE
rbpacket_new_s(VALUE class)
{
VALUE self;
rbpacket_t *rbpacket;
// need to make destructor do a pcap_close later
self = Data_Make_Struct(class, rbpacket_t, 0, rbpacket_free, rbpacket);
rb_obj_call_init(self, 0, 0);
memset(rbpacket, 0, sizeof(rbpacket_t));
return self;
}
Public Instance Methods
caplen()
click to toggle source
Returns the integer length of capture len from the in the PCAP::Packet header
static VALUE
rbpacket_caplen(VALUE self)
{
rbpacket_t* rbpacket;
Data_Get_Struct(self, rbpacket_t, rbpacket);
//test incorrect case
if (rbpacket->hdr.caplen > rbpacket->hdr.len)
return INT2NUM(rbpacket->hdr.len);
return INT2NUM(rbpacket->hdr.caplen);
}
data()
click to toggle source
Returns the integer PCAP MINOR LIBRARY value unless capture
static VALUE
rbpacket_data(VALUE self)
{
rbpacket_t* rbpacket;
Data_Get_Struct(self, rbpacket_t, rbpacket);
if ((rbpacket->pkt == NULL) || (rbpacket->hdr.caplen > rbpacket->hdr.len))
return Qnil;
return rb_str_new((char *) rbpacket->pkt, rbpacket->hdr.caplen);
}
length()
click to toggle source
Returns the integer length of packet length field from the in the PCAP::Packet header
static VALUE
rbpacket_length(VALUE self)
{
rbpacket_t* rbpacket;
Data_Get_Struct(self, rbpacket_t, rbpacket);
return INT2NUM(rbpacket->hdr.len);
}
microsec()
click to toggle source
Returns the tv_usec integer from the ts.tv_usec record in the PCAP::Packet header timestamp microseconds the microseconds when this packet was captured, as an offset to ts_sec. Beware: this value shouldn't reach 1 second (1 000 000), in this case ts_sec must be increased instead!
Ruby Microsecond Handling Time.at(946684800.2).usec #=> 200000 Time.now.usec
static VALUE
rbpacket_microsec(VALUE self)
{
rbpacket_t* rbpacket;
Data_Get_Struct(self, rbpacket_t, rbpacket);
return INT2NUM(rbpacket->hdr.ts.tv_usec);
}
time()
click to toggle source
Returns the EPOCH integer from the ts.tv_sec record in the PCAP::Packet header
static VALUE
rbpacket_time(VALUE self)
{
rbpacket_t* rbpacket;
Data_Get_Struct(self, rbpacket_t, rbpacket);
return INT2NUM(rbpacket->hdr.ts.tv_sec);
}
to_s()
click to toggle source
Alias of data
static VALUE
rbpacket_data(VALUE self)
{
rbpacket_t* rbpacket;
Data_Get_Struct(self, rbpacket_t, rbpacket);
if ((rbpacket->pkt == NULL) || (rbpacket->hdr.caplen > rbpacket->hdr.len))
return Qnil;
return rb_str_new((char *) rbpacket->pkt, rbpacket->hdr.caplen);
}