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