<dh*******@gmail.comwrote in message
news:11**********************@m7g2000cwm.googlegro ups.com...
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 to the
server and the client which gets disconnected. for this i am using
int_ntoa() function. but the problem which i am facing is that the
client which gets connected at last overwrites the o/p of inet_ntoa()
o/p comes as
Client 127.0.0.1 connected at : Wed Nov 08 17:27:08 2006
Client 198.68.18.4 connected at : Wed Nov 08 17:28:08 2006
Client 198.68.18.4 disconnected at : Wed Nov 08 17:29:53 2006
Client 198.68.18.4 disconnected at : Wed Nov 08 17:29:59 2006
The I addres get overwridden. How can I correct it.
<OT>
My response assumes the inet_ntoa() is the BSD/POSIX one; if that's
true, you're probably better off in comp.unix.programmer.
This is from the man page on inet_ntoa() on my system:
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 subse-
quent calls will overwrite.
I don't have the appropriate spec handy for citation, but IIRC this is
the defined behavior for this function; there is no way to "fix" it
because it is behaving correctly according to the spec.
What you need to fix is _your_ code. If you are going to call
inet_ntoa() several times in a row, you will need to copy the string
that it returns into a distinct buffer of your own before proceeding.
If you call inet_ntoa() from multiple threads, you're eventually going
to get garbage because the function is not reentrant.
</OT>
You might as well use sprintf() and produce the string yourself; it's
only a single line of code, and it's fairly straightforward to write.
S
--
Stephen Sprunk "God does not play dice." --Albert Einstein
CCIE #3723 "God is an inveterate gambler, and He throws the
K5SSS dice at every possible opportunity." --Stephen Hawking
--
Posted via a free Usenet account from
http://www.teranews.com