Tuan Hoang wrote:

> Hi,
>
> I'm trying to build my own ICMP message (not hacking)
> for some testing in my lab.  Normally when I generate custom UDP
> datagrams, I do a sendto() with a raw socket (w/ IP_HDRINCL).
> I just fill in a sockaddr_in struct and pass it to sendto().
>
> My question is that if I use a sockaddr struct for ICMP messages,
> what do I fill in for the sa_data field?

I suggest you use the same sockaddr_in struct instead of sockaddr for more
clarity. In the first place, these two structs are barely the same(in
size). You just
need to type cast between the other to obtain the desired struct

If you really want to use sockaddr, note first that sa_data field is 14
bytes length.
By mapping sockaddr to sockaddr_in, the first two bytes correspond to
sin_port
field of sockaddr_in. The next 4 bytes correponds to the sin_addr and the
rest
you may leave it as is. For you ICMP message, i think you need to fill in
the
4 bytes(corresponds to sin_addr) with the value of the destination address.

I might be wrong, but this is my way:

       char *ptr  = SockaddrVar.sa_data;
      *(( in_addr_t*)(ptr+2)) = inet_addr(Destination address);


bunal!

Ronnel




 ---

 Ronnel P. Maglasang
 Software Design Eng'ng Department   voice : 340-0451
 NEC Technologies Phils., Inc.       fax   : 340-0457
 PEZA, Lapulapu City                 e-mail:
[EMAIL PROTECTED]
 Philippines

 KNOWLEDGE IS CONTAGIOUS... PASS IT ON...


-
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to [EMAIL PROTECTED]

Reply via email to