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

  • SEARCH
  • Home
  • 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 8883569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:50:42+00:00 2026-06-14T20:50:42+00:00

This is an assignment, it has to be with raw sockets. I need to

  • 0

This is an assignment, it has to be with raw sockets. I need to program a simple icmp ping.
I used this as a base http://www.pdbuchan.com/rawsock/icmp4.c . At line 127 is wlan0, Im using eth0. In line 290 I coded this:

struct sockaddr_in rec;
  
unsigned char * pkt = (unsigned char *) malloc (IP_MAXPACKET * sizeof (unsigned char));

if (recvfrom (sd, (void*)pkt, IP4_HDRLEN + ICMP_HDRLEN+datalen , 0, NULL, (socklen_t*)sizeof (struct sockaddr)) < 0)  {
  perror ("recvfrom() failed ");
  exit (EXIT_FAILURE);
}
struct ip *ip = (struct ip *)pkt;
struct icmphdr *icmp = (struct icmphdr *)(pkt + IP4_HDRLEN);

printf("%s %s %d\n",(char*)inet_ntoa(*(struct in_addr*)&ip->ip_dst),
        (char*)inet_ntoa(*(struct in_addr*)&ip->ip_src),
        icmp->type);
free (pkt);

The problem is that ip_dst and ip_src are being shown as my machines’s IP, and icmp type as 0 and not 8. Wireshark shows both icmp reply and request.
Probably my recvfrom is wrong, but I heard something about linux own TCP/IP might be handling the packets. If that’s true, what is the workaround for that?

edit: I checked this raw socket listener but it did not solve my problem.

  • 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-14T20:50:43+00:00Added an answer on June 14, 2026 at 8:50 pm

    I don’t think you can get a reply when using IPPROTO_RAW.

    You have to use

    socket (AF_INET, SOCK_RAW, IPPROTO_ICMP);
    

    With IPPROTO_ICMP you must only send an ICMP packet, not the whole IP packet.

    When receiving however you’ll get the whole IP packet and have to extract the ICMP reply. Note that you will get a copy of all ICMP packets sent to the host so you must filter them.

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

Sidebar

Related Questions

UPDATED: SEE BELOW I've been porting the code for this assignment: http://www.stanford.edu/class/cs221/progAssignments/PA1/search.html (the entire
I am making this assignment in my program and I am getting the warning
I've been working on this assignment, where I need to read in records and
This particular assignment has to do with removing substrings from strings; I am trying
So the teacher has posed this assignment: You have been hired by the United
I am doing this assignment, make a program that solves sudoku. I have a
This portion of my current assignment has me completely stumped: I am trying to
My class assignment is to write a program that has the user input a
My professor has given me this assignment. Implement a generic function called Max, which
For this assignment I had to create my own string class. I initially wrote

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.