Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8048741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:34:25+00:00 2026-06-05T06:34:25+00:00

I’m tring to experiment with the ICMP protocol and have created a kernel-module for

  • 0

I’m tring to experiment with the ICMP protocol and have created a kernel-module for linux that analyses ICMP packet ( Processes the packet only if if the ICMP code field is a magic number ) . Now to test this module , i have to create a an ICMP packet and send it to the host where this analysing module is running . In fact it would be nice if i could implement it the kernel itself (as a module ) . I am looking for something like a packetcrafter in kernel , I googled it found a lot of articles explaining the lifetime of a packet , rather than tutorials of creating it . User space packetcrafters would be my last resort, that too those which are highly flexible like where i’ll be able to set ICMP code etc . And I’m not wary of kernel panics 🙂 !!!!! Any packet crafting ideas are welcome .

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T06:34:27+00:00Added an answer on June 5, 2026 at 6:34 am

    Sir, I strongly advice you against using the kernel module to build ICMP packets.

    You can use user-space raw-sockets to craft ICMP packets, even build the IP-header itself byte by byte.
    So you can get as flexible as it can get using that.

    Please, take a look at this

    ip = (struct iphdr*) packet;
        icmp = (struct icmphdr*) (packet + sizeof(struct iphdr));
    
        /*  
         *  here the ip packet is set up 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 be set on the socket so that
         *  the kernel does not attempt to automatically add
         *  a default ip header to the packet
         */
    
        setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, &optval, sizeof(int));
    
        /*
         *  here the icmp packet is created
         *  also the ip checksum is 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 this part of code looks flexible enough, then read about raw sockets 😀 maybe they’re the easiest and safest answer to your need.

    Please check the following links for 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 a very nice topic, pretty useful imo

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.