1 .\" $NetBSD: sockaddr_snprintf.3,v 1.8 2013/06/07 17:23:26 christos Exp $
3 .\" Copyright (c) 2004 The NetBSD Foundation, Inc.
4 .\" All rights reserved.
6 .\" This code is derived from software contributed to The NetBSD Foundation
7 .\" by Christos Zoulas.
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in the
16 .\" documentation and/or other materials provided with the distribution.
18 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 .\" POSSIBILITY OF SUCH DAMAGE.
31 .Dt SOCKADDR_SNPRINTF 3
35 .Nd formatting function for socket address structures
41 .Fn sockaddr_snprintf "char *buf" "size_t buflen" "const char *fmt" "const struct sockaddr *sa"
45 function formats a socket address into a form suitable for printing.
47 This function is convenient because it is protocol independent, i.e. one does
48 not need to know the address family of the sockaddr in order to print it.
51 like format string specifies how the address is going to be printed.
52 Some formatting characters are only supported by some address families.
53 If a certain formatting character is not supported, then the string
57 The resulting formatted string is placed into
61 characters are placed in
64 The following formatting characters are supported (immediately
70 The node address portion of the socket address is printed numerically.
73 the address is printed as:
77 the address is printed as:
85 the address is printed as:
90 the address is printed as:
94 the address is printed as:
98 but the interface portion is skipped (see below).
103 The symbolic name of the address is printed.
108 this is the hostname associated with the address.
109 For all other address families, it is the same as the
114 For all addresses, print all their fields as
115 .Dq field_name=value .
117 The numeric value of the family of the address is printed.
119 The length of the socket address is printed.
126 the numeric value of the port portion of the address is printed.
132 this is the name of the service associated with the port number, if
134 For all other address families, it is the same as the
140 addresses, the interface name portion is printed.
144 addresses, the flowinfo portion of the address is printed numerically.
148 addresses, the netrange portion of the address is printed as:
149 .Dq phase:[firstnet,lastnet]
153 addresses, the scope portion of the address is printed numerically.
157 and the format character, and the selected format does not apply to
158 the given address family, the
160 string is elided and no output results.
164 .Fn sockaddr_snprintf
165 function returns the number of characters that are required to format the
168 given the format string
170 excluding the terminating NUL.
171 The returned string in
173 is always NUL-terminated.
174 If the address family is not supported,
175 .Fn sockaddr_snprintf
185 .Fn sockaddr_snprintf
188 conversion failed, and
190 is set to the error value from
195 is too small to hold the formatted output,
196 .Fn sockaddr_snprintf
197 will still return the buffer, containing a truncated string.
205 .Fn sockaddr_snprintf
210 .Fn sockaddr_snprintf
211 interface is experimental and might change in the future.
213 There is no way to specify different formatting styles for particular
215 For example it would be useful to print
222 This function is supposed to be quick, but
224 might use system calls to convert the scope number to an interface
229 format characters call
231 which may block for a noticeable period of time.
233 Not all formatting characters are supported by all address families and
236 is not very convenient.
239 character can suppress this, but other formatting (e.g., spacing or
240 punctuation) will remain.