473,322 Members | 1,806 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

question about inet_ntoa(3)

It returns a char*... but where is the buffer? free() prints a debug
message saying it wasn't allocated when I try to free it. That implies
that there's a buffer somewhere managed by someone else. I'm okay with
that, but it would be a bit weird.

The man pages on OpenBSD 3.4 and MacOS 10.3 don't say anything about
it... and OpenBSD would have a paragraph on the issue if it was a
problem. But I'm still confused, so I'd be a happy man if anyone could
confirm that the buffer isn't my problem.

TIA for any help,
Anthony
Nov 14 '05 #1
3 2545
Anthony Roberts <ac*************************@ucalgary.ca> writes:
It returns a char*... but where is the buffer? free() prints a debug
message saying it wasn't allocated when I try to free it. That implies
that there's a buffer somewhere managed by someone else. I'm okay with
that, but it would be a bit weird.

The man pages on OpenBSD 3.4 and MacOS 10.3 don't say anything about
it... and OpenBSD would have a paragraph on the issue if it was a
problem. But I'm still confused, so I'd be a happy man if anyone could
confirm that the buffer isn't my problem.


The inet_ntoa() function is not defined by the C standard. You'll
probably get better information in comp.unix.programmer.

In general, it's fairly common for functions that return strings to
return a pointer to a static buffer; the buffer is overwritten by
subsequent calls. (This can cause difficulties for multi-threaded
programs, but the C standard doesn't concern itself with
multi-threading.) I don't know whether inet_ntoa() does this.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
Nov 14 '05 #2
Keith Thompson wrote:

The inet_ntoa() function is not defined by the C standard. You'll
probably get better information in comp.unix.programmer.
I will try that.
In general, it's fairly common for functions that return strings to
return a pointer to a static buffer; the buffer is overwritten by
subsequent calls.
ewwww
(This can cause difficulties for multi-threaded
programs, but the C standard doesn't concern itself with
multi-threading.) I don't know whether inet_ntoa() does this.


If that were the case, you'd need to have a mutex to protect it.
Thank you for the fast and helpful response. :)
Nov 14 '05 #3
Anthony Roberts <ac*************************@ucalgary.ca> writes:
Keith Thompson wrote:
The inet_ntoa() function is not defined by the C standard. You'll
probably get better information in comp.unix.programmer.


I will try that.
In general, it's fairly common for functions that return strings to
return a pointer to a static buffer; the buffer is overwritten by
subsequent calls.


ewwww
(This can cause difficulties for multi-threaded
programs, but the C standard doesn't concern itself with
multi-threading.) I don't know whether inet_ntoa() does this.


If that were the case, you'd need to have a mutex to protect it.


It's also common to provide reentrant versions of such functions in
addition to the older non-reentrant versions. The reentrant version
typically has a name ending in "_r", and takes additional arguments
specifying the base address and size of a user-supplied buffer. I
don't know whether there is (or needs to be) such a function for
inet_ntoa(); again comp.unix.programmer is the place to ask about it
if your documentation fails you <OT>man inet_ntoa</OT>.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
Nov 14 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Stevey | last post by:
I have the following XML file... <?xml version="1.0"?> <animals> <animal> <name>Tiger</name> <questions> <question index="0">true</question> <question index="1">true</question> </questions>
7
by: nospam | last post by:
Ok, 3rd or is it the 4th time I have asked this question on Partial Types, so, since it seems to me that Partial Types is still in the design or development stages at Microsoft, I am going to ask...
3
by: Ekqvist Marko | last post by:
Hi, I have one Access database table including questions and answers. Now I need to give answer id automatically to questionID column. But I don't know how it is best (fastest) to do? table...
3
by: Anthony Roberts | last post by:
It returns a char*... but where is the buffer? free() prints a debug message saying it wasn't allocated when I try to free it. That implies that there's a buffer somewhere managed by someone else....
11
by: nishant | last post by:
I've a structure: struct msghdr { //some goes here struct iovec *msg_iov; //some more --- }
1
by: QQ | last post by:
hello I need to listen to two ports and process the received message. Which way to do is better? I have a short program like this but I am not sure whether it is good or not. Or I'd better open...
1
by: bigjl | last post by:
I tried to run "inet_ntoa(*((struct in_addr *)h->h_addr))", but it always says 'inet_ntoa' has not been declared. What head file should i include to make the above code running? The following is the...
5
by: dharmdeep | last post by:
Hi friends, I had implemented client server application in C under VC++ environment. It can handle more than one client. So in this program i want to keep track of clients IP which gets connected...
4
by: Andrew | last post by:
Hi Are these functions (inet_ntop(), inet_pton()) from the socket library supported on Windows. If not is there an equivalent for them using Windows Ive seen mention of people creating...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.