Discussion:
sockaddr printing functions
(too old to reply)
Christos Zoulas
2014-12-01 16:04:38 UTC
Permalink
Hi,

We have a hodgepodge set of functions that print sockaddr_* and I wanted
to try to clean that up:

1. consistent api
2. don't use static storage
3. testable from userland (with unit tests added)

For each socket type we have:

int xx_print(char *buf, size_t len, const struct xxaddr *);

and:
int sxx_snprintf(char *buf, size_t len, void *sa, const char *fmt, ...);

for xx [ "in" "in6" "at" "un" "dl" ]
[the dl portion is slightly different, and the un portion I have
not included in the patch]

There are also constants that describe the max string length that xx_print
needs:
INET_ADDRSTRLEN, INET6_ADDRSTRLEN (existing)
ATALK_ADDRSTRLEN, LINK_ADDRSTRNEL (new)
UNIX_ADDRSTRLEN (should we add this?)

The code is in:

http://www.netbsd.org/~christos/net.tar.gz

Comments?

christos

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Alistair Crooks
2014-12-01 19:12:30 UTC
Permalink
Post by Christos Zoulas
Hi,
We have a hodgepodge set of functions that print sockaddr_* and I wanted
Nice, thanks!
Post by Christos Zoulas
1. consistent api
2. don't use static storage
3. testable from userland (with unit tests added)
int xx_print(char *buf, size_t len, const struct xxaddr *);
int sxx_snprintf(char *buf, size_t len, void *sa, const char *fmt, ...);
for xx [ "in" "in6" "at" "un" "dl" ]
[the dl portion is slightly different, and the un portion I have
not included in the patch]
A few questions:

1. the xx_print calls sxx_snprintf internally with a local (stack)
buffer, and then prints that out?

2. why have multiple sxx_snprintf functions, and then pass a void *sa in to
each? Is it one function with a void *sa, or many functions for each struct type?

3. why the format string?

4. return values are same as standard printf and snprintf?
Post by Christos Zoulas
There are also constants that describe the max string length that xx_print
INET_ADDRSTRLEN, INET6_ADDRSTRLEN (existing)
ATALK_ADDRSTRLEN, LINK_ADDRSTRNEL (new)
LINK_ADDRSTRLEN?
Post by Christos Zoulas
UNIX_ADDRSTRLEN (should we add this?)
http://www.netbsd.org/~christos/net.tar.gz
Thanks,
Al

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Loading...