Mailing List Archive

libnasl/nasl nasl_packet_forgery.c,1.3,1.4 capture_packet.c,1.2,1.3 capture_packet.h,1.2,1.3
Update of /usr/local/cvs/libnasl/nasl
In directory raccoon.nessus.org:/tmp/cvs-serv82462

Modified Files:
nasl_packet_forgery.c capture_packet.c capture_packet.h
Log Message:
o Change the API of capture_next_packet() so that it includes the effective
size of a captured packet (instead of relying on ip->ip_len)

o Fix a bug in get_ip_element() : the bogus size on non-BSD hosts

o Correct send_packet() so that it returns the real packet captured, instead
of relying on ip->ip_len (by using the new API of capture_next_packet())


Index: nasl_packet_forgery.c
===================================================================
RCS file: /usr/local/cvs/libnasl/nasl/nasl_packet_forgery.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- nasl_packet_forgery.c 14 Jan 2003 18:49:44 -0000 1.3
+++ nasl_packet_forgery.c 14 Jan 2003 20:15:58 -0000 1.4
@@ -138,7 +138,7 @@

else if(!strcmp(element, "ip_id")) { ret_int = ip->ip_id; flag ++ ; }
else if(!strcmp(element, "ip_hl")) { ret_int = ip->ip_hl; flag ++; }
else if(!strcmp(element, "ip_tos")) { ret_int = ip->ip_tos; flag ++; }
- else if(!strcmp(element, "ip_len")) { ret_int = ip->ip_len; flag ++; }
+ else if(!strcmp(element, "ip_len")) { ret_int = UNFIX(ip->ip_len); flag ++; }
else if(!strcmp(element, "ip_off")) { ret_int = UNFIX(ip->ip_off); flag ++; }
else if(!strcmp(element, "ip_ttl")) { ret_int = ip->ip_ttl; flag ++; }
else if(!strcmp(element, "ip_p")) { ret_int = ip->ip_p; flag ++; }
@@ -846,6 +846,7 @@

tree_cell *retc = NULL;
struct ip *ip;
struct ip *ip_icmp;
+ int ip_sz;
struct icmp *icmp;
char *data, *p;
int len;
@@ -853,6 +854,7 @@

int t;

ip = (struct ip*)get_str_local_var_by_name(lexic, "ip");
+ ip_sz = get_local_var_size_by_name(lexic, "ip");
if (ip != NULL)
{
data = get_str_local_var_by_name(lexic, "data");
@@ -895,7 +897,7 @@

retc = alloc_tree_cell(0, NULL);
retc->type = CONST_DATA;
retc->x.str_val = pkt;
- retc->size = UNFIX(ip->ip_len)+ len + 8;
+ retc->size = ip_sz + len + 8;
}
else
fprintf(stderr, "forge_icmp_packet: missing 'ip' parameter\n");
@@ -1121,7 +1123,7 @@

soca.sin_family = AF_INET;
soca.sin_addr = ip->ip_dst;
sendto(soc, (const void*)ip, 40, 0, (struct sockaddr *)&soca, sizeof(soca));
- if(bpf >= 0 && (pk = capture_next_packet(bpf, 0)))flag++;
+ if(bpf >= 0 && (pk = capture_next_packet(bpf, 0, NULL)))flag++;
i++;
}
}
@@ -1142,6 +1144,7 @@

tree_cell *retc;
int bpf;
u_char * answer;
+ int answer_sz;
struct sockaddr_in sockaddr;
char *ip;
struct ip *sip;
@@ -1187,22 +1190,22 @@

{
if(islocalhost(&sip->ip_dst))
{
- answer = (u_char*) capture_next_packet(bpf,10);
+ answer = (u_char*) capture_next_packet(bpf,10, &answer_sz);
while(answer != NULL && (!memcmp(answer, (char*)ip, sizeof(struct ip))))
{
efree(&answer);
- answer = (u_char*)capture_next_packet( bpf, 10);
+ answer = (u_char*)capture_next_packet( bpf, 10, &answer_sz);
}

}
else
- answer = (u_char*)capture_next_packet(bpf, to);
+ answer = (u_char*)capture_next_packet(bpf, to, &answer_sz);

if(answer)
{
struct ip * ip = (struct ip*)answer;
retc->x.str_val = answer;
- retc->size = UNFIX(ip->ip_len);
+ retc->size = answer_sz;
}
else
{

Index: capture_packet.c
===================================================================
RCS file: /usr/local/cvs/libnasl/nasl/capture_packet.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- capture_packet.c 7 Jan 2003 01:39:23 -0000 1.2
+++ capture_packet.c 14 Jan 2003 20:15:58 -0000 1.3
@@ -78,7 +78,7 @@




-struct ip * capture_next_packet(int bpf, int timeout)
+struct ip * capture_next_packet(int bpf, int timeout, int * sz)
{
struct pcap_pkthdr head;
int dl_len;
@@ -112,8 +112,9 @@

ip->ip_off = ntohs(ip->ip_off);
#endif
ip->ip_id = ntohs(ip->ip_id);
- ret = emalloc(UNFIX(ip->ip_len));
- bcopy(ip, ret, UNFIX(ip->ip_len));
+ ret = emalloc(head.caplen - dl_len);
+ bcopy(ip, ret, head.caplen - dl_len);
+ if(sz != NULL)*sz = head.caplen - dl_len;
}
return((struct ip*)ret);
}

Index: capture_packet.h
===================================================================
RCS file: /usr/local/cvs/libnasl/nasl/capture_packet.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- capture_packet.h 7 Jan 2003 01:39:23 -0000 1.2
+++ capture_packet.h 14 Jan 2003 20:15:58 -0000 1.3
@@ -2,6 +2,6 @@

#define CAPTURE_PACKET_H

int init_capture_device(struct in_addr, struct in_addr, char *);
-struct ip * capture_next_packet(int, int);
+struct ip * capture_next_packet(int, int, int *);