1 .\" $NetBSD: sockaddr_snprintf.3,v 1.7 2009/04/11 16:13:49 joerg 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
113 The numeric value of the family of the address is printed.
115 The length of the socket address is printed.
122 the numeric value of the port portion of the address is printed.
128 this is the name of the service associated with the port number, if
130 For all other address families, it is the same as the
136 addresses, the interface name portion is printed.
140 addresses, the flowinfo portion of the address is printed numerically.
144 addresses, the netrange portion of the address is printed as:
145 .Dq phase:[firstnet,lastnet]
149 addresses, the scope portion of the address is printed numerically.
153 and the format character, and the selected format does not apply to
154 the given address family, the
156 string is elided and no output results.
160 .Fn sockaddr_snprintf
161 function returns the number of characters that are required to format the
164 given the format string
166 excluding the terminating NUL.
167 The returned string in
169 is always NUL-terminated.
170 If the address family is not supported,
171 .Fn sockaddr_snprintf
181 .Fn sockaddr_snprintf
184 conversion failed, and
186 is set to the error value from
191 is too small to hold the formatted output,
192 .Fn sockaddr_snprintf
193 will still return the buffer, containing a truncated string.
201 .Fn sockaddr_snprintf
206 .Fn sockaddr_snprintf
207 interface is experimental and might change in the future.
209 There is no way to specify different formatting styles for particular
211 For example it would be useful to print
218 This function is supposed to be quick, but
220 might use system calls to convert the scope number to an interface
225 format characters call
227 which may block for a noticeable period of time.
229 Not all formatting characters are supported by all address families and
232 is not very convenient.
235 character can suppress this, but other formatting (e.g., spacing or
236 punctuation) will remain.