bonjour,
j'ai récuprer les sources d'un sniffer sur
http://www.estvideo.com/dew/index/page/sniffer
lorsque je compile sous linux, tout va bien. Mais quand je le
lance , il capture un paquet et il y a une 'erreur de segmentation' au
moment de l'analyse du datagramme IP.
Voila le morceau de code concerné :
/* Analyse IP (main.c)*/
void analyze_sniff_ip(const struct sniff_ip *ip) {
char buffer[60];
echo("+..............................................................+\n");
echo("| IP |\n");
echo("+..............................................................+\n");
sprintf(buffer,"| Version : %5d Header Length : %5d |\n",ip->ip_v,ip->ip_hl);
echo(buffer);
sprintf(buffer,"| Type of Service : %5x Total Length : %5d |\n",ip->ip_tos,ntohs(ip->ip_len));
echo(buffer);
if(ntohs(ip->ip_tos)>0) {
// Type of Service
}
sprintf(buffer,"| Identification : %5d Flags : %5x |\n",ntohs(ip->ip_id),ntohs(ip->ip_off));
echo(buffer);
sprintf(buffer,"| Protocol %5x : %s TTL : %5d |\n",ip->ip_p,analyze_ip_proto(ip->ip_p),ip->ip_ttl);
echo(buffer);
sprintf(buffer,"| From : %15s To : %15s |\n",iptos(ip->ip_src.s_addr),iptos(ip->ip_dst.s_addr));
echo(buffer);
}
/* IP header (main.h)*/
struct sniff_ip {
#if BYTE_ORDER == LITTLE_ENDIAN
u_int ip_hl:4, /* header length */
ip_v:4; /* version */
#if BYTE_ORDER == BIG_ENDIAN
u_int ip_v:4, /* version */
ip_hl:4; /* header length */
#endif
#endif /* not _IP_VHL */
u_char ip_tos; /* type of service */
u_short ip_len; /* total length */
u_short ip_id; /* identification */
u_short ip_off; /* fragment offset field */
#define IP_RF 0x8000 /* reserved fragment flag */
#define IP_DF 0x4000 /* dont fragment flag */
#define IP_MF 0x2000 /* more fragments flag */
#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
u_char ip_ttl; /* time to live */
u_char ip_p; /* protocol */
u_short ip_sum; /* checksum */
struct in_addr ip_src,ip_dst; /* source and dest address */
};
Lorsque je met cete partie du code en commentaire, plus de problème, il capture les paquets et saute tout le décodage ip.
Je n'arrive pas à trouver d'ou vient l'erreur.
Merci d'avance pour votre aide.
ps : la libpcap doit etre installer sur votre machine pour compiler. (g++ -o test main.c -lpcap)
ps2 : il manque '#include string.h' au main.c