network programming - Crafting an ICMP packet inside a Linux kernel Module -


i'm tring experiment icmp protocol , have created kernel-module linux analyses icmp packet ( processes packet if if icmp code field magic number ) . test module , have create icmp packet , send host analysing module running . in fact nice if implement kernel (as module ) . looking packetcrafter in kernel , googled found lot of articles explaining lifetime of packet , rather tutorials of creating . user space packetcrafters last resort, highly flexible i'll able set icmp code etc . , i'm not wary of kernel panics :-) !!!!! packet crafting ideas welcome .

sir, advice against using kernel module build icmp packets.

you can use user-space raw-sockets craft icmp packets, build ip-header byte byte. can flexible can using that.

please, take @ this

ip = (struct iphdr*) packet;     icmp = (struct icmphdr*) (packet + sizeof(struct iphdr));      /*        *  here ip packet set except checksum      */     ip->ihl         = 5;     ip->version         = 4;     ip->tos         = 0;     ip->tot_len         = sizeof(struct iphdr) + sizeof(struct icmphdr);     ip->id          = htons(random());     ip->ttl         = 255;     ip->protocol        = ipproto_icmp;     ip->saddr           = inet_addr(src_addr);     ip->daddr           = inet_addr(dst_addr);       if ((sockfd = socket(af_inet, sock_raw, ipproto_icmp)) == -1)     {     perror("socket");     exit(exit_failure);     }      /*       *  ip_hdrincl must set on socket      *  kernel not attempt automatically add      *  default ip header packet      */      setsockopt(sockfd, ipproto_ip, ip_hdrincl, &optval, sizeof(int));      /*      *  here icmp packet created      *  ip checksum generated      */     icmp->type          = icmp_echo;     icmp->code          = 0;     icmp->un.echo.id        = 0;     icmp->un.echo.sequence  = 0;     icmp->checksum      = 0;     icmp-> checksum     = in_cksum((unsigned short *)icmp, sizeof(struct icmphdr));      ip->check           = in_cksum((unsigned short *)ip, sizeof(struct iphdr)); 

if part of code looks flexible enough, read raw sockets :d maybe they're easiest , safest answer need.

please check following links further info
http://courses.cs.vt.edu/~cs4254/fall04/slides/raw_6.pdf
http://www.cs.binghamton.edu/~steflik/cs455/rawip.txt
http://cboard.cprogramming.com/networking-device-communication/107801-linux-raw-socket-programming.html nice topic, pretty useful imo


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -