Esempio n. 1
0
void ip_handle() {
    int * data = ethernet_rx_data + ETHERNET_HDR_LEN;
    // not IPv4 or header is longer than 20bit
    if(data[IP_VERSION] != IP_VERSION_VAL)
        return;

	if (data[IP_DST] != IP_ADDR[0] || 
	    data[IP_DST + 1] != IP_ADDR[1] || 
		data[IP_DST + 2] != IP_ADDR[2] || 
		data[IP_DST + 3] != IP_ADDR[3]) {
		//cprintf("IP destination not correct.\n");
		return;
	}
	
	
    int length = (data[IP_TOTAL_LEN] << 8) | data[IP_TOTAL_LEN + 1];
    length -= 20; // ip header

    if(data[IP_PROTOCAL] == IP_PROTOCAL_ICMP)
        icmp_handle(length);
    else if(data[IP_PROTOCAL] == IP_PROTOCAL_TCP)
        tcp_handle(length);
	else if (data[IP_PROTOCAL] == IP_PROTOCAL_UDP) {
		//cprintf("udp\n");
		udp_handle(length);
	}
	else
		cprintf("unknown protocal %x\n", data[IP_PROTOCAL]);
}
Esempio n. 2
0
File: ip.c Progetto: cjld/armcpu
void ip_handle() {
    int * data = ethernet_rx_data + ETHERNET_HDR_LEN;
    // not IPv4 or header is longer than 20bit
    if(data[IP_VERSION] != IP_VERSION_VAL)
        return;

    int length = (data[IP_TOTAL_LEN] << 8) | data[IP_TOTAL_LEN + 1];
    length -= 20; // ip header

    if(data[IP_PROTOCAL] == IP_PROTOCAL_ICMP)
        icmp_handle(length);
    if(data[IP_PROTOCAL] == IP_PROTOCAL_TCP)
        tcp_handle(length);
}
Esempio n. 3
0
void ip_handle(int *dataHead, int length) {
//    kprintf("handle ip\n");
    int * data = dataHead + ETHERNET_HDR_LEN;
    // not IPv4 or header is longer than 20bit
    if(data[IP_VERSION] != IP_VERSION_VAL)
        return;

    int IPlength = (data[IP_TOTAL_LEN] << 8) | data[IP_TOTAL_LEN + 1];
    IPlength -= 20; // ip header

    if(data[IP_PROTOCAL] == IP_PROTOCAL_ICMP)
        icmp_handle(dataHead, IPlength);
    if(data[IP_PROTOCAL] == IP_PROTOCAL_TCP)
        tcp_handle(dataHead, IPlength);
}