URGENT - HELP Forming ICMP Header

URGENT - HELP Forming ICMP Header

Post by bhi.. » Sat, 13 May 2000 04:00:00



Hello,

Can anyone help me in forming ICMP header. What I am doing is

#define SKB_SIZE        sizeof(struct iphdr)+sizeof(struct icmphdr)

void pkt_send(char *dest,char *src)
{
        struct icmphdr *icmph;
        struct iphdr *iph;
        struct rtable *rt;
        static int icmp_seq = 0;
        int i,errno;
        struct sk_buff *skb;
        struct device *dev = dev_get("eth1");

        skb = alloc_skb(SKB_SIZE+dev->hard_header_len+15,GFP_ATOMIC);
        skb->dev = dev;
        skb_reserve(skb,(dev->hard_header_len+15)&~15);

        /* form ip hdr */
        skb->nh.iph = iph = (struct iphdr *)skb_put(skb,sizeof(struct
iphdr));

        /* fill ip header */
        iph->daddr = in_aton(dest);
        iph->saddr = in_aton(src);
        iph->version = 4;
        iph->ihl = 5;
        iph->tos = 0;
        iph->tot_len = htons(skb->len);
        iph->id = 10;
        iph->frag_off = 0;
        iph->ttl = 64; /* default ip ttl */
        iph->protocol = IPPROTO_ICMP; /* icmp */
        iph->check = 0;
        iph->check = ip_fast_csum((unsigned char *)iph,iph->ihl);
        printk("\n ip formed %s",dest);

        /* fill icmp hdr */
        skb->h.icmph = icmph = (struct icmphdr *)skb_put(skb,sizeof
(struct icmphdr));
        icmph->type = ICMP_ECHO;
        icmph->code = 0;
        icmph->checksum = 0;
        icmph->un.echo.id = 0;
        icmph->un.echo.sequence = icmp_seq;
        icmph->checksum = cksum((u_short *)icmph,sizeof(icmph),0);
        icmp_seq++;

        skb->protocol = __constant_htons (ETH_P_IP);

        /* now to get the routing info*/
        rt = NULL;
        ip_route_output(&rt,iph->daddr,iph->saddr,0,0);
        if(&rt->u.dst == NULL)
                printk("\n error");
        skb->dst = &rt->u.dst;
        skb->dst->output(skb);
        printk("\n pkt send to %s",dest);

Quote:}

u_short cksum(const u_short *buf, int length, u_short csum)
{
        int nleft = length;
        const u_short *buffer = buf;
        int sum = csum;
        u_short ret_val = 0;

        while(nleft > 1)
        {
                sum += *buffer++;
                nleft -= 2;
        }
        if(nleft == 1)
        {
                sum += htons(*(u_char *)buffer << 8);
        }
        sum = (sum >> 16) + (sum & 0xffff);  /* add top 16 to low 16 */
        sum += (sum >> 16);               /* add carry */

        ret_val = ~sum;                 /* truncate to 16 bit */
        return(ret_val);

Quote:}

At the destination through tcpdump I can c the packet coming but giving
wrong icmp csum error and because of which not getting the reply for
the same.
 Can any one guide me in this regards.

Thanks in advance
Bhagyashree

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

URGENT - HELP Forming ICMP Header

Post by bhi.. » Sat, 13 May 2000 04:00:00


Hello,

Can anyone help me in forming ICMP header. What I am doing is

#define SKB_SIZE        sizeof(struct iphdr)+sizeof(struct icmphdr)

void pkt_send(char *dest,char *src)
{
        struct icmphdr *icmph;
        struct iphdr *iph;
        struct rtable *rt;
        static int icmp_seq = 0;
        int i,errno;
        struct sk_buff *skb;
        struct device *dev = dev_get("eth1");

        skb = alloc_skb(SKB_SIZE+dev->hard_header_len+15,GFP_ATOMIC);
        skb->dev = dev;
        skb_reserve(skb,(dev->hard_header_len+15)&~15);

        /* form ip hdr */
        skb->nh.iph = iph = (struct iphdr *)skb_put(skb,sizeof(struct
iphdr));

        /* fill ip header */
        iph->daddr = in_aton(dest);
        iph->saddr = in_aton(src);
        iph->version = 4;
        iph->ihl = 5;
        iph->tos = 0;
        iph->tot_len = htons(skb->len);
        iph->id = 10;
        iph->frag_off = 0;
        iph->ttl = 64; /* default ip ttl */
        iph->protocol = IPPROTO_ICMP; /* icmp */
        iph->check = 0;
        iph->check = ip_fast_csum((unsigned char *)iph,iph->ihl);
        printk("\n ip formed %s",dest);

        /* fill icmp hdr */
        skb->h.icmph = icmph = (struct icmphdr *)skb_put(skb,sizeof
(struct icmphdr));
        icmph->type = ICMP_ECHO;
        icmph->code = 0;
        icmph->checksum = 0;
        icmph->un.echo.id = 0;
        icmph->un.echo.sequence = icmp_seq;
        icmph->checksum = cksum((u_short *)icmph,sizeof(icmph),0);
        icmp_seq++;

        skb->protocol = __constant_htons (ETH_P_IP);

        /* now to get the routing info*/
        rt = NULL;
        ip_route_output(&rt,iph->daddr,iph->saddr,0,0);
        if(&rt->u.dst == NULL)
                printk("\n error");
        skb->dst = &rt->u.dst;
        skb->dst->output(skb);
        printk("\n pkt send to %s",dest);

Quote:}

u_short cksum(const u_short *buf, int length, u_short csum)
{
        int nleft = length;
        const u_short *buffer = buf;
        int sum = csum;
        u_short ret_val = 0;

        while(nleft > 1)
        {
                sum += *buffer++;
                nleft -= 2;
        }
        if(nleft == 1)
        {
                sum += htons(*(u_char *)buffer << 8);
        }
        sum = (sum >> 16) + (sum & 0xffff);  /* add top 16 to low 16 */
        sum += (sum >> 16);               /* add carry */

        ret_val = ~sum;                 /* truncate to 16 bit */
        return(ret_val);

Quote:}

At the destination through tcpdump I can c the packet coming but giving
wrong icmp csum error and because of which not getting the reply for
the same.
 Can any one guide me in this regards.

Thanks in advance
Bhagyashree

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

1. URGENT - Help forming ICMP header

Hello,

Can anyone help me in forming ICMP header. What I am doing is

#define SKB_SIZE sizeof(struct iphdr)+sizeof(struct icmphdr)

void pkt_send(char *dest,char *src)
{
struct icmphdr *icmph;
struct iphdr *iph;
struct rtable *rt;
static int icmp_seq = 0;
int i,errno;
struct sk_buff *skb;
struct device *dev = dev_get("eth1");

        skb = alloc_skb(SKB_SIZE+dev->hard_header_len+15,GFP_ATOMIC);
skb->dev = dev;
skb_reserve(skb,(dev->hard_header_len+15)&~15);

/* form ip hdr */
skb->nh.iph = iph = (struct iphdr *)skb_put(skb,sizeof(struct iphdr));

/* fill ip header */
iph->daddr = in_aton(dest);
iph->saddr = in_aton(src);
iph->version = 4;
iph->ihl = 5;
iph->tos = 0;
iph->tot_len = htons(skb->len);
iph->id = 10;
iph->frag_off = 0;
iph->ttl = 64; /* default ip ttl */
iph->protocol = IPPROTO_ICMP; /* icmp */
iph->check = 0;
iph->check = ip_fast_csum((unsigned char *)iph,iph->ihl); printk("\n ip
formed %s",dest);

/* fill icmp hdr */
skb->h.icmph = icmph = (struct icmphdr *)skb_put(skb,sizeof
(struct icmphdr));
icmph->type = ICMP_ECHO;
icmph->code = 0;
icmph->checksum = 0;
icmph->un.echo.id = 0;
icmph->un.echo.sequence = icmp_seq;
icmph->checksum = cksum((u_short *)icmph,sizeof(icmph),0);
icmp_seq++;

skb->protocol = __constant_htons (ETH_P_IP);

/* now to get the routing info*/
rt = NULL;
ip_route_output(&rt,iph->daddr,iph->saddr,0,0);
if(&rt->u.dst == NULL)
  printk("\n error");
skb->dst = &rt->u.dst;
skb->dst->output(skb);
printk("\n pkt send to %s",dest);

u_short cksum(const u_short *buf, int length, u_short csum)
{
int nleft = length;
const u_short *buffer = buf;
int sum = csum;
u_short ret_val = 0;

while(nleft > 1)
{
  sum += *buffer++;
  nleft -= 2;
if(nleft == 1)
{
  sum += htons(*(u_char *)buffer << 8);
sum = (sum >> 16) + (sum & 0xffff);  /* add top 16 to low 16 */ sum +=
(sum >> 16);  /* add carry */

ret_val = ~sum;  /* truncate to 16 bit */
return(ret_val);

At the destination through tcpdump I can c the packet coming but giving
wrong icmp csum error and because of which not getting the reply for
the same.
Can any one guide me in this regards.

Thanks in advance
Bhagyashree

Sent via Deja.com http://www.deja.com/
Before you buy.

2. 2.5/2.6 compatibility

3. ICMP HOST cannot build IP Header address to echo ICMP HOST

4. screwed XF86 4.0.2

5. Urgent: Machine crash, someone DoS attack using ICMP..help needed

6. HELP: AIX COMMAND to MONITOR REAL MEMORY USAGE

7. Non-standard ICMP header file

8. Pikes Peak Linux User's Group

9. ICMP: Could not build IP Header..

10. icmp type 3 fragmentation needed: size of tcp header included

11. where to find header file form.h ?

12. Headers, Headers, whos got the Headers

13. URGENT: W3C form standards for non-wintel platforms