[En-Nut-Discussion] Bug in app httpserv

Harald Kipp harald.kipp at egnite.de
Mon Aug 4 18:01:40 CEST 2003


Thanks, Tyou.

I splitted the single fprintf_P() into two, which seems to be
the most simple solution IMHO.

That kind of error happens often with functions returning
a pointer to a local buffer. But that's UNIX like C from
old days. I'd suggest creating a new function instead of
redefining a well known problem (see strtok_r).

Harald

At 03:39 03.08.2003 +0900, you wrote:
>file app/httpserv.c function ShowSockets:
>          fprintf_P(stream, tfmt,
>                     ts,
>                     inet_ntoa(ts->so_local_addr),
>                     ntohs(ts->so_local_port),
>                     inet_ntoa(ts->so_remote_addr),
>                     ntohs(ts->so_remote_port));
>
>not works well...change it like this:
>
>         {
>             char ip_str[16];
>             strcpy(ip_str, (char*)inet_ntoa(ts->so_local_addr));
>
>             fprintf_P(stream, tfmt,
>                     ts,
>                     ip_str,
>                     ntohs(ts->so_local_port),
>                     inet_ntoa(ts->so_remote_addr),
>                     ntohs(ts->so_remote_port));
>         }
>
>or change function inet_ntoa
>
>u_char *inet_ntoa(u_long addr)
>{
>     static u_char str[4][16];
>     static u_char rnd = 0;
>     u_char inv[3];
>     u_char *rp;
>     u_char *ap;
>     u_char rem;
>     u_char n;
>     u_char i;
>
>
>     if (++rnd == 4)
>         rnd = 0;
>     rp = str[rnd];
>     ap = (u_char *) & addr;
>     for (n = 0; n < 4; n++) {
>         i = 0;
>         do {
>             rem = *ap % (u_char) 10;
>             *ap /= (u_char) 10;
>             inv[i++] = '0' + rem;
>         } while (*ap);
>         while (i--)
>             *rp++ = inv[i];
>         *rp++ = '.';
>         ap++;
>     }
>     *--rp = 0;
>     return str[rnd];
>}




More information about the En-Nut-Discussion mailing list