Bug 64291

Summary: inet_ntoa static buffer - man page ammendment
Product: Documentation Reporter: Lee Brotherston <lee>
Component: Books & ArticlesAssignee: freebsd-doc (Nobody) <doc>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Latest   
Hardware: Any   
OS: Any   

Description Lee Brotherston 2004-03-15 10:00:35 UTC
The man page for inet_ntoa does not mention that is uses a static buffer.  It is perhaps worth mentioning this as further calls to inet_ntoa will overwrite the previous response.

Perhaps this should be obvious, however I just fell foul of this and thought clarification on the man page might be useful.

Fix: 

Ammendment to the man page.  If it helps I found this version on a linux machines manpage:

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.
How-To-Repeat: The following section of code (where ip_hdr is a struct *ip) will log both addresses to be the same when they are not.  Presumably because both inet_ntoa's are evaluated before the log function is run.  As a result the first result has been lost.

log(LOG_INFO, "%s -> %s", inet_ntoa(ip_hdr->ip_src), inet_ntoa(ip_hdr->ip_dst));
Comment 1 colin.percival 2004-03-23 09:47:10 UTC
  Under BUGS, inet_ntoa(3) says:
"The string returned by inet_ntoa() resides in a static memory area."

  Is this insufficient?  If so, what should it say?

Colin Percival
Comment 2 Colin Percival freebsd_committer freebsd_triage 2004-03-23 12:19:42 UTC
State Changed
From-To: open->closed

Submitter agrees that the existing documentation (in BUGS) is sufficient.