From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <96076331021185.tru64-unix-managers.marc@archive.invalid> From: Pat Wilson Date: Thu, 04 Apr 1996 18:44:26 +0000 To: tru64-unix-managers Subject: SUMMARY: inet_ntoa_r? X-MARC-Message: https://marc.info/?l=tru64-unix-managers&m=96076331021185 Many thanks to Tom Blinn, who sent the following answer to my question: Pat ------- Forwarded Message From: "Dr. Tom Blinn, 603-881-0646" X-Mts: smtp > I've got a developer looking for information about "inet_ntoa_r" (the > re-entrant version of inet_ntoa) on DU 3.2A. Apparently there's a > reference to it in /lib/libc_r.a, but it can't be found, and there aren't > any header files with mention it. Are we missing something? I'm not surprised. There doesn't seem to be a reference page either. So it is not a documented, supported interface. Being that as it may, here's the definition from the getnetent.c module, which no doubt becomes part of libc_r.a: /* * Internal functions */ #ifdef _THREAD_SAFE static void inet_ntoa_r(struct in_addr in, char *buf) { register char *p; p = (char *)∈ #define UC(b) (((int)b)&0xff) sprintf(buf, "%d.%d.%d.%d", UC(p[0]), UC(p[1]), UC(p[2]), UC(p[3])); } #endif /* _THREAD_SAFE */ Note that this is in a section labelled "Internal functions". And the way that it differs from inet_ntoa is that you provide it a buffer and it puts the results into your buffer (which, presumably, your thread allocated). The "non-thread-safe" version puts the generated string into a buffer that is inside itself, and returns a pointer to the buffer, and of course, if you then call it again (from another thread) before you copy the string out of the buffer (or do whatever else you needed to do with it), the string gets overwritten. char * inet_ntoa(in) struct in_addr in; { static char b[18]; register char *p; p = (char *)∈ #define UC(b) (((int)b)&0xff) sprintf(b, "%d.%d.%d.%d", UC(p[0]), UC(p[1]), UC(p[2]), UC(p[3])); return (b); } Given this knowledge of the code, you can now write your own inet_ntoa_r that will work, or you can just call the real one (if you link against the libc_r.a library). Tom Dr. Thomas P. Blinn, UNIX Software Group, Digital Equipment Corporation 110 Spit Brook Road, MS ZKO3-2/U20 Nashua, New Hampshire 03062-2698 Technology Partnership Engineering Phone: (603) 881-0646 Internet: tpb@zk3.dec.com Digital's Easynet: alpha::tpb Worry kills more people than work because more people worry than work. My favorite palindrome is: Satan, oscillate my metallic sonatas. -- Phil Agre, pagre@ucsd.edu Opinions expressed herein are my own, and do not necessarily represent those of my employer or anyone else, living or dead, real or imagined. ------- End of Forwarded Message