On Tue, Mar 1, 2011 at 15:37, Nelson A. de Oliveira <[email protected]> wrote:
> Hi again!
>
> On Tue, Mar 1, 2011 at 2:13 PM, Nelson A. de Oliveira <[email protected]>
> wrote:
>> Note the garbage in the source address. Maybe this could give us some
>> hint about the problem?
>
> OK, it seems to be what I was thinking that it's :-)
> It gets the IP address in src/Util_NetBSD.cc line 33, where it greps for
> "inet "
>
> But see, with LC_ALL=C:
>
> $ ifconfig eth0 | fgrep inet
> inet addr:200.145.221.37 Bcast:200.145.221.255 Mask:255.255.255.0
> inet6 addr: fe80::240:a7ff:fe15:39a9/64 Scope:Link
>
> While with pt_BR:
>
> $ ifconfig eth0 | fgrep inet
> inet end.: 200.145.221.37 Bcast:200.145.221.255 Masc:255.255.255.0
> endereço inet6: fe80::240:a7ff:fe15:39a9/64 Escopo:Link
>
> See that with pt_BR there is a space before the IP number, while with
> LC_ALL there isn't.
> Wrong number of fields (4 fields with LC_ALL=C versus 5 fields in
> pt_BR) is causing this issue.
>
> Maybe it's a bug in the translation that has included this space, but
> paris-traceroute should be more robust about cases like this (maybe
> using inet_ntoa() or something else that returns the IP number in
> C/C++, instead relying the work to a script).
>
> Best regards,
> Nelson
Hi again,
I was having exactly the same thoughts :)
A ugly hack to get the right source IP would be to use something similar to :
void GetPrimaryIp(char* buffer, size_t buflen)
{
assert(buflen >= 16);
int sock = socket(AF_INET, SOCK_DGRAM, 0);
assert(sock != -1);
const char* kGoogleDnsIp = "8.8.8.8";
uint16_t kDnsPort = 53;
struct sockaddr_in serv;
memset(&serv, 0, sizeof(serv));
serv.sin_family = AF_INET;
serv.sin_addr.s_addr = inet_addr(kGoogleDnsIp);
serv.sin_port = htons(kDnsPort);
int err = connect(sock, (const sockaddr*) &serv, sizeof(serv));
assert(err != -1);
sockaddr_in name;
socklen_t namelen = sizeof(name);
err = getsockname(sock, (sockaddr*) &name, &namelen);
assert(err != -1);
const char* p = inet_ntop(AF_INET, &name.sin_addr, buffer, buflen);
assert(p);
close(sock);
}
I'll have a closer look and see how to integrate this (and let know
upstream then :p)
Cheers !
--
Herve Rousseau
--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]