public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* Extending vfprintf and family
@ 2014-08-14 18:39 Philip Prindeville
  2014-08-14 18:45 ` Russ Allbery
  0 siblings, 1 reply; 7+ messages in thread
From: Philip Prindeville @ 2014-08-14 18:39 UTC (permalink / raw)
  To: libc-alpha

Hi.

I work a lot with routing, protocols, and firewalls so I’m constantly having to dump packets for tracing, logging, auditing, etc.

Common types I need to format are:

* IPv4 dotted quads
* MAC addresses (not just Ethernet/Wifi)
* IPv6 addresses
* uint16_t and uint32_t in network (BigEndian) byte order
* n-byte hex dump (BigEndian) of an arbitrary blob
* safe n-byte string formatting (printable characters get printed, others [including NUL] get escaped into \xHH or \OOO)

It’s a bit tedious (not to mention inefficient) to have to call inet_ntop() to format a machine address into a readable format (via a temporary buffer), then interpolate that string into a logging message via syslog() or snprintf(), etc.  What would be really great would be adding extensions (which can be turned off or on, depending on whether strict compliance with C99, ANSI C, etc is required) as format specifiers.

When I was at Cisco in the IOS group, there was a way to register on-the-fly additional format specifiers that *printf() could then leverage; some of the formatting helpers were quite sophisticated, understanding ASN.1 or X.509 certs, etc.  Not sure we need to be that complex, though I wouldn’t reject it if it were offered, either.

One would be able to specify both precision and width, e.g. “I have a 20 byte safe string I want to format, but not into more than 32 columns” so that if there was a lot of escaping and the string overflowed the 32-byte output count, it would be truncated.

Does anyone else see the value in doing this?

Thanks,

-Philip

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-08-19 18:34 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-14 18:39 Extending vfprintf and family Philip Prindeville
2014-08-14 18:45 ` Russ Allbery
2014-08-14 19:08   ` Rich Felker
2014-08-19  1:23   ` Philip Prindeville
2014-08-19  1:40     ` Ryan Arnold
2014-08-19  5:48       ` Philip Prindeville
2014-08-19 18:34       ` Philip Prindeville

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 read-only IMAP folder(s) and NNTP newsgroup(s).