[En-Nut-Discussion] How to get client's IP address in http server application?

Harald Kipp harald.kipp at egnite.de
Mon Dec 2 17:14:57 CET 2002


Norio,

Oops! I've been programming in C so long and I passed
this error too often.

The problem is not specific to Nut/OS and would also
occur on any other OS. inet_ntoa uses a static buffer
for storing the result. If you call a function with
two parameters using the return value of inet_ntoa,
then the second one overrides the first result.

This must fail:

printf("%s %s", inet_ntoa(ip1), inet_ntoa(ip2));

This works:

printf("%s", inet_ntoa(ip1));
printf(" %s", inet_ntoa(ip2));

Basemon does it right, hhtpd does it wrong.

Harald




More information about the En-Nut-Discussion mailing list