network.c (ssldump-0.9b3) | : | network.c (ssldump-1.3) | ||
---|---|---|---|---|
skipping to change at line 44 | skipping to change at line 44 | |||
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY SUCH DAMA GE. | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY SUCH DAMA GE. | |||
$Id: network.c,v 1.10 2002/09/09 21:02:58 ekr Exp $ | $Id: network.c,v 1.10 2002/09/09 21:02:58 ekr Exp $ | |||
ekr@rtfm.com Tue Dec 29 09:52:54 1998 | ekr@rtfm.com Tue Dec 29 09:52:54 1998 | |||
*/ | */ | |||
static char *RCSSTRING="$Id: network.c,v 1.10 2002/09/09 21:02:58 ekr Exp $"; | ||||
#include <sys/types.h> | #include <sys/types.h> | |||
#include <r_common.h> | #include <r_common.h> | |||
#include "network.h" | #include "network.h" | |||
#ifndef _WIN32 | #ifndef _WIN32 | |||
#include <sys/socket.h> | #include <sys/socket.h> | |||
#include <netinet/in.h> | #include <netinet/in.h> | |||
#include <arpa/inet.h> | #include <arpa/inet.h> | |||
#include <netdb.h> | #include <netdb.h> | |||
#endif | #endif | |||
skipping to change at line 79 | skipping to change at line 77 | |||
int network_handler_create(mod,handlerp) | int network_handler_create(mod,handlerp) | |||
proto_mod *mod; | proto_mod *mod; | |||
n_handler **handlerp; | n_handler **handlerp; | |||
{ | { | |||
int r,_status; | int r,_status; | |||
n_handler *handler=0; | n_handler *handler=0; | |||
if(!(handler=(n_handler *)malloc(sizeof(n_handler)))) | if(!(handler=(n_handler *)malloc(sizeof(n_handler)))) | |||
ABORT(R_NO_MEMORY); | ABORT(R_NO_MEMORY); | |||
if(mod->vtbl->create_ctx){ | if(mod->vtbl->create_ctx){ | |||
if(r=mod->vtbl->create_ctx(mod->handle,&handler->ctx)) | if((r=mod->vtbl->create_ctx(mod->handle,&handler->ctx))) | |||
ABORT(r); | ABORT(r); | |||
} | } | |||
handler->mod=mod; | handler->mod=mod; | |||
*handlerp=handler; | *handlerp=handler; | |||
_status=0; | _status=0; | |||
abort: | abort: | |||
if(_status){ | if(_status){ | |||
network_handler_destroy(&handler); | network_handler_destroy(mod, &handler); | |||
} | } | |||
return(_status); | return(_status); | |||
} | } | |||
int network_handler_destroy(handlerp) | int network_handler_destroy(mod,handlerp) | |||
proto_mod *mod; | ||||
n_handler **handlerp; | n_handler **handlerp; | |||
{ | { | |||
n_handler *handler=0; | ||||
if(!handlerp || !*handlerp) | if(!handlerp || !*handlerp) | |||
return(0); | return(0); | |||
handler = *handlerp; | ||||
mod->vtbl->destroy_ctx(mod->handle,&handler->ctx); | ||||
free(*handlerp); | free(*handlerp); | |||
*handlerp=0; | *handlerp=0; | |||
return(0); | return(0); | |||
} | } | |||
int network_process_packet(handler,timestamp,data,length) | int network_process_packet(handler,timestamp,data,length) | |||
n_handler *handler; | n_handler *handler; | |||
struct timeval *timestamp; | struct timeval *timestamp; | |||
UCHAR *data; | UCHAR *data; | |||
int length; | int length; | |||
skipping to change at line 122 | skipping to change at line 125 | |||
u_short off; | u_short off; | |||
/*We can pretty much ignore all the options*/ | /*We can pretty much ignore all the options*/ | |||
memcpy(&p.ts,timestamp,sizeof(struct timeval)); | memcpy(&p.ts,timestamp,sizeof(struct timeval)); | |||
p.base=data; | p.base=data; | |||
p._len=length; | p._len=length; | |||
p.data=data; | p.data=data; | |||
p.len=length; | p.len=length; | |||
p.ip=(struct ip *)data; | p.ip=(struct ip *)data; | |||
if(p.len < 20) { | ||||
if(!(NET_print_flags & NET_PRINT_JSON)) | ||||
printf("Malformed packet, packet too small to contain IP header, skippin | ||||
g ...\n"); | ||||
return(0); | ||||
} | ||||
/*Handle, or rather mishandle, fragmentation*/ | /*Handle, or rather mishandle, fragmentation*/ | |||
off=ntohs(p.ip->ip_off); | off=ntohs(p.ip->ip_off); | |||
if((off & 0x1fff) || /*Later fragment*/ | if((off & 0x1fff) || /*Later fragment*/ | |||
(off & 0x2000)){ /*More fragments*/ | (off & 0x2000)){ /*More fragments*/ | |||
/* fprintf(stderr,"Fragmented packet! rejecting\n"); */ | /* fprintf(stderr,"Fragmented packet! rejecting\n"); */ | |||
return(0); | return(0); | |||
} | } | |||
hlen=p.ip->ip_hl * 4; | hlen=p.ip->ip_hl * 4; | |||
p.data += hlen; | p.data += hlen; | |||
p.len =ntohs(p.ip->ip_len)-hlen; | p.len = ntohs(p.ip->ip_len); | |||
if(p.len > length) { | ||||
if(!(NET_print_flags & NET_PRINT_JSON)) | ||||
printf("Malformed packet, size from IP header is larger than size report | ||||
ed by libpcap, skipping ...\n"); | ||||
return(0); | ||||
} | ||||
if (p.len == 0) { | ||||
DBG((0,"ip length reported as 0, presumed to be because of 'TCP segmenta | ||||
tion offload' (TSO)\n")); | ||||
p.len = p._len; | ||||
} | ||||
p.len -= hlen; | ||||
switch(p.ip->ip_p){ | switch(p.ip->ip_p){ | |||
case IPPROTO_TCP: | case IPPROTO_TCP: | |||
if(r=process_tcp_packet(handler->mod,handler->ctx,&p)) | if((r=process_tcp_packet(handler->mod,handler->ctx,&p))) | |||
ERETURN(r); | ERETURN(r); | |||
break; | break; | |||
} | } | |||
return(0); | return(0); | |||
} | } | |||
int packet_copy(in,out) | int packet_copy(in,out) | |||
packet *in; | packet *in; | |||
packet **out; | packet **out; | |||
{ | { | |||
int _status; | int _status; | |||
packet *p=0; | packet *p=0; | |||
if(!(p=(packet *)calloc(sizeof(packet),1))) | if(!(p=(packet *)calloc(1,sizeof(packet)))) | |||
ABORT(R_NO_MEMORY); | ABORT(R_NO_MEMORY); | |||
memcpy(&p->ts,&in->ts,sizeof(struct timeval)); | memcpy(&p->ts,&in->ts,sizeof(struct timeval)); | |||
if(!(p->base=(UCHAR *)malloc(in->_len))) | if(!(p->base=(UCHAR *)malloc(in->_len))) | |||
ABORT(R_NO_MEMORY); | ABORT(R_NO_MEMORY); | |||
memcpy(p->base,in->base,p->_len=in->_len); | memcpy(p->base,in->base,p->_len=in->_len); | |||
p->data=p->base + (in->data - in->base); | p->data=p->base + (in->data - in->base); | |||
p->len=in->len; | p->len=in->len; | |||
skipping to change at line 183 | skipping to change at line 204 | |||
return(_status); | return(_status); | |||
} | } | |||
int packet_destroy(p) | int packet_destroy(p) | |||
packet *p; | packet *p; | |||
{ | { | |||
if(!p) | if(!p) | |||
return(0); | return(0); | |||
FREE(p->base); | FREE(p->base); | |||
FREE(p); | ||||
return(0); | return(0); | |||
} | } | |||
int timestamp_diff(t1,t0,diff) | int timestamp_diff(t1,t0,diff) | |||
struct timeval *t1; | struct timeval *t1; | |||
struct timeval *t0; | struct timeval *t0; | |||
struct timeval *diff; | struct timeval *diff; | |||
{ | { | |||
long d; | long d; | |||
End of changes. 11 change blocks. | ||||
8 lines changed or deleted | 33 lines changed or added |