1
mirror of https://github.com/rapid7/metasploit-framework synced 2024-11-05 14:57:30 +01:00

Fixes #352 and fixes #350. Can no longer reproduce memory corruption or packet loss with this code

git-svn-id: file:///home/svn/framework3/trunk@7287 4d416f70-5f16-0410-b530-b9f4589650da
This commit is contained in:
HD Moore 2009-10-26 22:49:43 +00:00
parent b662d044a6
commit 3b99a513ec
2 changed files with 16 additions and 6 deletions

View File

@ -14,4 +14,8 @@ else
have_library("pcap", "pcap_setnonblock")
end
if ( RUBY_VERSION =~ /^1\.9/ )
$CFLAGS += " -DRUBY_19"
end
create_makefile("pcaprub")

View File

@ -1,5 +1,9 @@
#include "ruby.h"
#ifndef RUBY_19
#include "rubysig.h"
#endif
#include <pcap.h>
@ -27,7 +31,7 @@ typedef struct rbpcap {
typedef struct rbpcapjob {
struct pcap_pkthdr hdr;
char *pkt;
unsigned char *pkt;
int wtf;
} rbpcapjob_t;
@ -328,7 +332,7 @@ rbpcap_dump(VALUE self, VALUE caplen, VALUE pktlen, VALUE packet)
pcap_dump(
(u_char*)rbp->pdt,
&pcap_hdr,
RSTRING_PTR(packet)
(unsigned char *)RSTRING_PTR(packet)
);
return self;
@ -360,7 +364,7 @@ rbpcap_inject(VALUE self, VALUE payload)
static void rbpcap_handler(rbpcapjob_t *job, struct pcap_pkthdr *hdr, u_char *pkt){
job->pkt = pkt;
job->pkt = (unsigned char *)pkt;
job->hdr = *hdr;
}
@ -376,16 +380,18 @@ rbpcap_next(VALUE self)
if(! rbpcap_ready(rbp)) return self;
pcap_setnonblock(rbp->pd, 1, eb);
#ifndef RUBY_19
TRAP_BEG;
#endif
ret = pcap_dispatch(rbp->pd, 1, (pcap_handler) rbpcap_handler, (u_char *)&job);
#ifndef RUBY_19
TRAP_END;
#endif
if(rbp->type == OFFLINE && ret <= 0) return Qnil;
if(ret > 0 && job.hdr.caplen > 0)
return rb_str_new(job.pkt, job.hdr.caplen);
return rb_str_new((char *) job.pkt, job.hdr.caplen);
return Qnil;
}