produces a strange output. ip->daddr and ip->saddr are different, but after
appling the method inet_ntoa the results are identical. Here is a sample
output of my xterm (communication between my wlan card and my wlan router):
I really do not understand how this can happen. I've already read some man
pages and read the apropriate kernel header's source. I would be very
thankful if anybody could help. It's driving me crazy and I don't know
what's going on.
Giovanni
Guest
Posts: n/a
03-21-2006, 03:17 PM
Paul wrote:
> I really do not understand how this can happen. I've already read some man
> pages and read the apropriate kernel header's source. I would be very
> thankful if anybody could help. It's driving me crazy and I don't know
> what's going on.
You did not read the right man pages :-(
inet_ntoa() documentation states:
The inet_ntoa() function converts the Internet host address 'in' given
in network byte order to a string in standard numbers-and-dots
notation. The string is returned in a statically allocated buffer,
which subsequent calls will overwrite.
Ciao
Giovanni
--
A computer is like an air conditioner,
it stops working when you open Windows.
Registered Linux user #337974 <http://counter.li.org/>
Paul
Guest
Posts: n/a
03-21-2006, 04:02 PM
> The inet_ntoa() function converts the Internet host address 'in' given
> in network byte order to a string in standard numbers-and-dots
> notation. The string is returned in a statically allocated buffer,
> which subsequent calls will overwrite.
Acutally I do not understand how this solves my problem. I read this man
page and I understand, that a given address in nethwork byte order of
format struct in_addr is transformed into a dot-number string. Could you
please be a little bit more precisly ? Thanks.
Giovanni
Guest
Posts: n/a
03-21-2006, 04:34 PM
Paul wrote:
>> The inet_ntoa() function converts the Internet host address 'in' given
>> in network byte order to a string in standard numbers-and-dots
>> notation. The string is returned in a statically allocated buffer,
>> which subsequent calls will overwrite.
>
> Acutally I do not understand how this solves my problem. I read this man
> page and I understand, that a given address in nethwork byte order of
> format struct in_addr is transformed into a dot-number string. Could you
> please be a little bit more precisly ? Thanks.
>
>
In a single statement like:
printf("Source: inet_ntoa( %d ) -> %s\nDest: inet_ntoa( %d ) -> %s\n",
ip->saddr, inet_ntoa(*(struct in_addr*)&ip->saddr ), ip->daddr,
inet_ntoa(*(struct in_addr*) &ip->daddr ));
you call inet_ntoa() twice. The first call fills the buffer with the
string corresponding to the 'ip->daddr' end returns the pointer to the
buffer. The second call fills the *same* buffer (it is a static buffer)
with the string corresponding to the 'ip->saddr' and returns the pointer
to the buffer. Unfortunately this destroys the results of the previous
call before it is used.
Try with two different statements:
printf("Source: inet_ntoa( %d ) -> %s\n",
ip->saddr, inet_ntoa(*(struct in_addr*)&ip->saddr));
printf("Dest: inet_ntoa( %d ) -> %s\n",
ip->daddr, inet_ntoa(*(struct in_addr*) &ip->daddr));
or better replace also the format specifier %d with %08x which gives a
better view for adresses.
Ciao
Giovanni
--
A computer is like an air conditioner,
it stops working when you open Windows.
Registered Linux user #337974 <http://counter.li.org/>
Paul
Guest
Posts: n/a
03-21-2006, 05:24 PM
Oh man, thank you really much ! Now I understand what is meant by a static
buffer. And the program works fine. Thanks for help!