xref: /illumos-gate/usr/src/head/ifaddrs.h (revision 87c723434df4be9c0f7ef119567cb6e2da776a36)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24 #ifndef _IFADDRS_H
25 #define	_IFADDRS_H
26 
27 #ifdef	__cplusplus
28 extern "C" {
29 #endif
30 
31 #include <sys/types.h>
32 
33 /*
34  * The `getifaddrs' function generates a linked list of these structures.
35  * Each element of the list describes one network interface.
36  */
37 #if defined(_INT64_TYPE)
38 struct ifaddrs {
39 	struct ifaddrs	*ifa_next;	/* Pointer to the next structure. */
40 	char		*ifa_name;	/* Name of this network interface. */
41 	uint64_t	ifa_flags;	/* Flags as from SIOCGLIFFLAGS ioctl. */
42 	struct sockaddr	*ifa_addr;	/* Network address of this interface. */
43 	struct sockaddr	*ifa_netmask;	/* Netmask of this interface. */
44 	union {
45 		/*
46 		 * At most one of the following two is valid.  If the
47 		 * IFF_BROADCAST bit is set in `ifa_flags', then
48 		 * `ifa_broadaddr' is valid.  If the IFF_POINTOPOINT bit is
49 		 * set, then `ifa_dstaddr' is valid. It is never the case that
50 		 * both these bits are set at once.
51 		 */
52 		struct sockaddr	*ifu_broadaddr;
53 		struct sockaddr	*ifu_dstaddr;
54 	} ifa_ifu;
55 	void		*ifa_data; /* Address-specific data (may be unused). */
56 /*
57  * This may have been defined in <net/if.h>.
58  */
59 #ifndef ifa_broadaddr
60 #define	ifa_broadaddr	ifa_ifu.ifu_broadaddr	/* broadcast address */
61 #endif
62 #ifndef ifa_dstaddr
63 #define	ifa_dstaddr	ifa_ifu.ifu_dstaddr	/* other end of p-to-p link */
64 #endif
65 };
66 #endif
67 
68 /*
69  * Create a linked list of `struct ifaddrs' structures, one for each
70  * network interface on the host machine.  If successful, store the
71  * list in *ifap and return 0.  On errors, return -1 and set `errno'.
72  *
73  * The storage returned in *ifap is allocated dynamically and can
74  * only be properly freed by passing it to `freeifaddrs'.
75  */
76 extern int getifaddrs(struct ifaddrs **);
77 
78 /* Reclaim the storage allocated by a previous `getifaddrs' call. */
79 extern void freeifaddrs(struct ifaddrs *);
80 
81 
82 #ifdef	__cplusplus
83 }
84 #endif
85 
86 #endif	/* _IFADDRS_H */
87