xref: /illumos-gate/usr/src/head/ifaddrs.h (revision d48be21240dfd051b689384ce2b23479d757f2d8)
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  * Copyright 2022 Sebastian Wiedenroth
24  */
25 #ifndef _IFADDRS_H
26 #define	_IFADDRS_H
27 
28 #ifdef	__cplusplus
29 extern "C" {
30 #endif
31 
32 #include <sys/types.h>
33 
34 /*
35  * The `getifaddrs' function generates a linked list of these structures.
36  * Each element of the list describes one network interface.
37  */
38 #if defined(_INT64_TYPE)
39 struct ifaddrs {
40 	struct ifaddrs	*ifa_next;	/* Pointer to the next structure. */
41 	char		*ifa_name;	/* Name of this network interface. */
42 	uint64_t	ifa_flags;	/* Flags as from SIOCGLIFFLAGS ioctl. */
43 	struct sockaddr	*ifa_addr;	/* Network address of this interface. */
44 	struct sockaddr	*ifa_netmask;	/* Netmask of this interface. */
45 	union {
46 		/*
47 		 * At most one of the following two is valid.  If the
48 		 * IFF_BROADCAST bit is set in `ifa_flags', then
49 		 * `ifa_broadaddr' is valid.  If the IFF_POINTOPOINT bit is
50 		 * set, then `ifa_dstaddr' is valid. It is never the case that
51 		 * both these bits are set at once.
52 		 */
53 		struct sockaddr	*ifu_broadaddr;
54 		struct sockaddr	*ifu_dstaddr;
55 	} ifa_ifu;
56 	void		*ifa_data; /* Address-specific data (may be unused). */
57 /*
58  * This may have been defined in <net/if.h>.
59  */
60 #ifndef ifa_broadaddr
61 #define	ifa_broadaddr	ifa_ifu.ifu_broadaddr	/* broadcast address */
62 #endif
63 #ifndef ifa_dstaddr
64 #define	ifa_dstaddr	ifa_ifu.ifu_dstaddr	/* other end of p-to-p link */
65 #endif
66 };
67 #endif
68 
69 #ifdef __PRAGMA_REDEFINE_EXTNAME
70 #pragma redefine_extname getifaddrs __getifaddrs
71 #else
72 extern int __getifaddrs(struct ifaddrs **);
73 #define	getifaddrs __getifaddrs
74 #endif
75 
76 /*
77  * Create a linked list of `struct ifaddrs' structures, one for each
78  * network interface on the host machine.  If successful, store the
79  * list in *ifap and return 0.  On errors, return -1 and set `errno'.
80  *
81  * The storage returned in *ifap is allocated dynamically and can
82  * only be properly freed by passing it to `freeifaddrs'.
83  */
84 extern int getifaddrs(struct ifaddrs **);
85 
86 /* Reclaim the storage allocated by a previous `getifaddrs' call. */
87 extern void freeifaddrs(struct ifaddrs *);
88 
89 
90 #ifdef	__cplusplus
91 }
92 #endif
93 
94 #endif	/* _IFADDRS_H */
95