Ejemplo n.º 1
0
void do_icmp(void *p)
{
	g.packet_icmp++;

	if(g.print_flag_icmp)
		print_icmp(p);
}
Ejemplo n.º 2
0
void do_icmp( char * data )
{
	global.packet_icmp ++;

	struct icmphdr * picmp = ( struct icmphdr * ) data;
	
	if( global.print_flag_icmp )
		print_icmp( picmp );
}
Ejemplo n.º 3
0
static void print_ipv4(FILE* dst, const struct ip* ip, bool compact){
	void* payload = ((char*)ip) + 4*ip->ip_hl;
	fprintf(dst, ";IPv4[%d/", 4*ip->ip_hl);
	if(!compact){
	  fprintf(dst, "%d/",(u_int16_t)ntohs(ip->ip_len));
	  fprintf(dst, "%d",(u_int8_t)ip->ip_ttl);
	} else {
	  fprintf(dst, "Len=%d:",(u_int16_t)ntohs(ip->ip_len));
	  fprintf(dst, "ID=%d:",(u_int16_t)ntohs(ip->ip_id));
	  fprintf(dst, "TTL=%d:",(u_int8_t)ip->ip_ttl);
	  fprintf(dst, "Chk=%d:",(u_int16_t)ntohs(ip->ip_sum));
	}
	if(ntohs(ip->ip_off) & IP_DF) {
	  fprintf(dst, "DF");
	}
	if(ntohs(ip->ip_off) & IP_MF) {
	  fprintf(dst, "MF");
	}
	if(!compact){
	  fprintf(dst, "] ; ");
	} else {
	  fprintf(dst, " Tos=%0x];\t",(u_int8_t)ip->ip_tos);
	}

	switch( ip->ip_p ) {
	case IPPROTO_TCP:
	  print_tcp(dst, ip, (const struct tcphdr*)payload,compact);
		break;

	case IPPROTO_UDP:
	  print_udp(dst, ip, (const struct udphdr*)payload,compact);
		break;

	case IPPROTO_ICMP:
	  print_icmp(dst, ip, (const struct icmphdr*)payload,compact);
		break;

	case IPPROTO_IGMP:
		fprintf(dst, "IGMP");
		break;

	default:
		fprintf(dst, "Unknown transport protocol: %d \n", ip->ip_p);
		break;
	}
}
Ejemplo n.º 4
0
int analyze_ip(u_char *data, int size) {
	
	u_char *mdata = data;
	int msize = size;
	struct iphdr *miphdr = (struct iphdr *)mdata;

	u_char *option;
	int option_len;
	int length;
	unsigned short sum;
	
	if (msize < sizeof(struct iphdr)) return(-1);

	miphdr = (struct iphdr *)mdata;
	mdata += sizeof(struct iphdr);
	msize -= sizeof(struct iphdr);

	option_len = miphdr->ihl*4 - sizeof(struct iphdr); // TODO 
	if ( option_len > 0 ) {
		if ( option_len >= 1500 ) return(-1);
		option = mdata;
		mdata += option_len;
		msize -= option_len;
	}

//	if (checksum_ip(miphdr, option, option_len) == 0) return(-1);
	
//	print_ip_header(miphdr, option, option_len, stdout);

	if (miphdr->protocol == IPPROTO_ICMP) {
		printf("ICMP\n");
		print_icmp(mdata+sizeof(struct iphdr), msize-sizeof(struct iphdr)); 
	} else if (miphdr->protocol == IPPROTO_TCP) {

		printf("TCP\n");
	} else if (miphdr->protocol == IPPROTO_UDP) {

		printf("UDP\n");
	}

	return(0);
}