From: "M.Baris Demiray" <baris@labristeknoloji.com>
To: mikael-aronsson <mikael-aronsson@telia.com>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: fprintf() and duplicate IP addresses
Date: Thu, 02 Jun 2005 09:11:27 +0000 [thread overview]
Message-ID: <429ECD3F.2070508@labristeknoloji.com> (raw)
In-Reply-To: <004101c565ad$7946fc50$b54be051@w128mtec>
[-- Attachment #1: Type: text/plain, Size: 1309 bytes --]
Hello again,
Thanks for the comments Mikael and Jarmo. As you said, the problem was
caused by the usage of static buffers in inet_ntoa() and fprintf() was
innocent at all. Since only the char * values are saved in fprintf(),
every inet_ntoa() overwrites the previous' values.
This was also written in man page (argh!):
"The string is returned in a statically allocated buffer, which
subsequent calls will overwrite."
I think I didn't searched enough to see that this is a common problem.
Everything is more clear now, thanks.
mikael-aronsson wrote:
> That's correct, most implementations use a static buffer, even though
> most modern applications has a separate buffer for each thread.
>
> Mikael
> [...]
>> I have nothing to back my suspection with. But probably inet_ntoa(...)
>> uses an internal buffer.
>>
>> printf( ) solves variables from the right, _before_ adding the result
>> to the output (only the "pointer" to char* is saved), you only get the
>> result from the first one (as they "point" to same memory).
>>
>> // Jarmo
--
"You have to understand, most of these people are not ready to be
unplugged. And many of them are no inert, so hopelessly dependent
on the system, that they will fight to protect it."
Morpheus
[-- Attachment #2: baris.vcf --]
[-- Type: text/x-vcard, Size: 342 bytes --]
begin:vcard
fn:M.Baris Demiray
n:Demiray;M.Baris
org:Labris Teknoloji
adr:;;Teknokent Silikon Bina No:24 ODTU;Ankara;;06531;Turkey
email;internet:baris@labristeknoloji.com
title:Yazilim Gelistirme Uzmani
tel;work:+903122101490
tel;fax:+903122101492
x-mozilla-html:FALSE
url:http://www.labristeknoloji.com
version:2.1
end:vcard
prev parent reply other threads:[~2005-06-02 9:11 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-05-31 2:19 fprintf() and duplicate IP addresses M.Baris Demiray
2005-05-31 6:28 ` SVisor
2005-05-31 6:53 ` mikael-aronsson
2005-06-02 9:11 ` M.Baris Demiray [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=429ECD3F.2070508@labristeknoloji.com \
--to=baris@labristeknoloji.com \
--cc=linux-c-programming@vger.kernel.org \
--cc=mikael-aronsson@telia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).