OpenCores
URL https://opencores.org/ocsvn/1g_ethernet_dpi/1g_ethernet_dpi/trunk

Subversion Repositories 1g_ethernet_dpi

[/] [1g_ethernet_dpi/] [trunk/] [sw/] [dev/] [test_main/] [src/] [net/] [icmp.c] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 kuzmi4
 
2
#include "xil_lib.h" 
3
#include "ip.h"
4
#include "icmp.h"
5
 
6
// net-if
7
net_if_t *ifp;
8
 
9
// ??
10
void eth_icmp_init(net_if_t *ip_net_if)
11
{
12
    ifp = ip_net_if;
13
    // Final
14
}
15
// {ICMP_ECHO_REQ+ICMP_ECHO_RESP} only!!!
16
void eth_icmp(char *iv_data)
17
{
18
 
19
    // 
20
    ip_hdr_t *pip = ip_head(iv_data);
21
 
22
    // chk ipkt
23
    icmp_hdr_t *in = (icmp_hdr_t *)(ip_data(pip));
24
    int len = htons(pip->ip_len) - ip_hlen(pip);
25
 
26
    // !check ICMP Header checksum
27
 
28
    // pass pkt to proper ICMP routine
29
    switch(in->ptype) {
30
        case ICMP_ECHO_REQ : {
31
            // mac
32
            xil_memmove(iv_data + ETH_DST_OFST, iv_data + ETH_SRC_OFST, 6);
33
            xil_memmove(iv_data + ETH_SRC_OFST, ifp->mac_addr, 6);
34
            // ptype
35
            in->ptype = ICMP_ECHO_RESP;
36
            // checksum
37
            in->pchksum = 0;
38
            in->pchksum = cksum(in, len);
39
            // ip-addr
40
            pip->ip_dest = pip->ip_src;
41
            pip->ip_src = ifp->ip_addr;
42
            // 
43
            ifp->net_raw_send(iv_data, ETH_HDR_SZ+htons(pip->ip_len));
44
            break;
45
        }
46
        default : {
47
            //printf("eth_icmp: ptype=%x\n", in->ptype);
48
            break;
49
        }
50
    }
51
    // Final
52
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.