Thread: Question On how to Fill icmp_data

  1. #1
    C/C++Newbie Antigloss's Avatar
    Join Date
    May 2005
    Posts
    216

    Question On how to Fill icmp_data

    The following code is from UNP

    Code:
    1 #include     "ping.h"
    
    2 void
    3 send_v4 (void)
    4 {
    5     int     len;
    6     struct icmp *icmp;
    
    7     icmp = (struct icmp *) sendbuf;
    8     icmp->icmp_type = ICMP_ECHO;
    9     icmp->icmp_code = 0;
    10     icmp->icmp_id = pid;
    11     icmp->icmp_seq = nsent++;
    12     memset (icmp->icmp_data, 0xa5, datalen); /* fill with pattern */
    13     Gettimeofday ((struct timeval *) icmp->icmp_data, NULL);
    
    14     len = 8 + datalen;           /* checksum ICMP header and data */
    15     icmp->icmp_cksum = 0;
    16     icmp->icmp_cksum = in_cksum ((u_short *) icmp, len);
    
    17     Sendto (sockfd, sendbuf, len, 0, pr->sasend, pr->salen);
    18 }
    At line 12, why 0xa5 is used to fill icmp_data? Any good reason for doing so? Can I use something else to fill icmp_data

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    You can fill it with anything you like, it's just payload to pad out the length of the message.

    Various tools use the known content of such padding to identify the sender.

    A5 is just one of those alternating 0,1 patterns at the bit level.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    C/C++Newbie Antigloss's Avatar
    Join Date
    May 2005
    Posts
    216
    What if I don't fill it with anything? That is, I don't write the following code
    Code:
    12     memset (icmp->icmp_data, 0xa5, datalen); /* fill with pattern */

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Antigloss View Post
    What if I don't fill it with anything?
    Then you end up sending whatever bytes happened to be sitting around in sendbuf. Maybe it matters, maybe it doesn't. In this case, it probably doesn't. But why not initialize it? It's painless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 12-22-2004, 07:29 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM