linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: SVisor <svisor@lycos.com>
To: linux-c-programming@vger.kernel.org
Subject: Re: fprintf() and duplicate IP addresses
Date: Tue, 31 May 2005 08:28:06 +0200	[thread overview]
Message-ID: <d7h00u$q8r$1@sea.gmane.org> (raw)
In-Reply-To: <429BC997.6000909@labristeknoloji.com>

M.Baris Demiray wrote:

...
> addresses, if I use a single fprintf() they're printed as duplicates.
...
> fprintf(stdout, "%s:%d -> %s:%d  ", \
>         inet_ntoa(*(struct in_addr *)&ip_header->ip_src.s_addr), \
>         ntohs(tcp_header->source), \
>         inet_ntoa(*(struct in_addr *)&ip_header->ip_dst.s_addr), \
>         ntohs(tcp_header->dest));

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


  reply	other threads:[~2005-05-31  6:28 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 [this message]
2005-05-31  6:53   ` mikael-aronsson
2005-06-02  9:11     ` M.Baris Demiray

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='d7h00u$q8r$1@sea.gmane.org' \
    --to=svisor@lycos.com \
    --cc=linux-c-programming@vger.kernel.org \
    /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).