Add a small example.

This commit is contained in:
christos 2013-04-07 22:54:26 +00:00
parent d5063e771b
commit d17f9381dd
1 changed files with 32 additions and 2 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: getifaddrs.3,v 1.12 2010/03/22 19:30:54 joerg Exp $
.\" $NetBSD: getifaddrs.3,v 1.13 2013/04/07 22:54:26 christos Exp $
.\" BSDI getifaddrs.3,v 2.5 2000/02/23 14:51:59 dab Exp
.\"
.\" Copyright (c) 1995, 1999
@ -21,7 +21,7 @@
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.Dd April 21, 2009
.Dd April 7, 2013
.Dt GETIFADDRS 3
.Os
.Sh NAME
@ -133,6 +133,36 @@ Upon successful completion, a value of 0 is returned.
Otherwise, a value of -1 is returned and
.Va errno
is set to indicate the error.
.Sh EXAMPLES
The following example program prints a list of all addresses configured
on the system.
.Bd -literal -offset indent
#include \*[Lt]sys/types.h\*[Gt]
#include \*[Lt]sys/socket.h\*[Gt]
#include \*[Lt]stdio.h\*[Gt]
#include \*[Lt]ifaddrs.h\*[Gt]
#include \*[Lt]util.h\*[Gt]
#include \*[Lt]err.h\*[Gt]
#include \*[Lt]stdlib.h\*[Gt]
int
main(int argc, char *argv[])
{
struct ifaddrs *ifa, *a;
if (getifaddrs(\*[Am]ifa) == -1)
err(EXIT_FAILURE, "getifaddrs");
for (a = ifa; a; a = a->ifa_next) {
char buf[1024];
sockaddr_snprintf(buf, sizeof(buf), "%f %a",
a->ifa_addr);
printf("%s %x %s\\n", a->ifa_name, a->ifa_flags, buf);
}
freeifaddrs(ifa);
return EXIT_SUCCESS;
}
.Ed
.Sh ERRORS
The
.Fn getifaddrs