Payload type char * ?

Hi Guys,

Please correct me if I am wrong.
When we send a packet across a network from a station, we send it in the format of ethernet packet yeah?

If we have to make an ARP request from the station then consider this as the format of ARP packet
1
2
3
4
5
6
7
8
struct arp_pkt 
{
  short op; /* op =0 : ARP request; op = 1 : ARP response */
  IPAddr srcip;
  MacAddr srcmac;
  IPAddr dstip;
  MacAddr dstmac;
} ARP_PKT;

and this as ethernet packet format
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
typedef unsigned char MacAddr[6];

/* structure of an ethernet pkt */
typedef struct __etherpkt 
{
  /* destination address in net order */
  MacAddr dst;

  /* source address in net order */
  MacAddr src;

  /************************************/
  /* payload type in host order       */
  /* type = 0 : ARP frame             */
  /* type = 1 : IP  frame             */
  /************************************/
  short  type;
  
  /* size of the data in host order */
  short   size;

  /* actual payload */
  char *  dat;

} EtherPkt;


Now If I am not wrong then during ARP request we will encapsulate the ARP packet into this ethernet packet as it's payload right? If yes, then why we have given the payload type of ethernet packet as char *. Shouldn't it be void * so that we can point it to ARP type?

Please guide me through this guys, this is annoying me since forever.

Thanks in advance

Last edited on
No big deal really.
char* is often used to mean a pointer to a bunch of bytes or a buffer.
void* came along well after C was established. Many implementations use char* for untyped blocks of data. You can do pointer arithmetic on char*, but not on void*.
Thanks @guestgulkan and @kbw.
I finally ended up changing that type to something else.

Thanks once again thou.
Topic archived. No new replies allowed.