1*4bc2832dSnaddy.\" $OpenBSD: getifaddrs.3,v 1.23 2022/03/29 18:15:52 naddy Exp $ 28b86f44bSitojun.\" BSDI getifaddrs.3,v 2.5 2000/02/23 14:51:59 dab Exp 3da8e6ed8Sitojun.\" 4da8e6ed8Sitojun.\" Copyright (c) 1995, 1999 5da8e6ed8Sitojun.\" Berkeley Software Design, Inc. All rights reserved. 6da8e6ed8Sitojun.\" 7da8e6ed8Sitojun.\" Redistribution and use in source and binary forms, with or without 8da8e6ed8Sitojun.\" modification, are permitted provided that the following conditions 9da8e6ed8Sitojun.\" are met: 10da8e6ed8Sitojun.\" 1. Redistributions of source code must retain the above copyright 11da8e6ed8Sitojun.\" notice, this list of conditions and the following disclaimer. 12da8e6ed8Sitojun.\" 13da8e6ed8Sitojun.\" THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND 14da8e6ed8Sitojun.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15da8e6ed8Sitojun.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16da8e6ed8Sitojun.\" ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE 17da8e6ed8Sitojun.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18da8e6ed8Sitojun.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19da8e6ed8Sitojun.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20da8e6ed8Sitojun.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21da8e6ed8Sitojun.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22da8e6ed8Sitojun.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23da8e6ed8Sitojun.\" SUCH DAMAGE. 24*4bc2832dSnaddy.Dd $Mdocdate: March 29 2022 $ 25da8e6ed8Sitojun.Dt GETIFADDRS 3 268618a6e3Snordin.Os 27da8e6ed8Sitojun.Sh NAME 2865612907Sschwarze.Nm getifaddrs , 2965612907Sschwarze.Nm freeifaddrs 30da8e6ed8Sitojun.Nd get interface addresses 31da8e6ed8Sitojun.Sh SYNOPSIS 3264d4e987Stedu.In sys/types.h 3364d4e987Stedu.In sys/socket.h 3464d4e987Stedu.In ifaddrs.h 35da8e6ed8Sitojun.Ft int 36da8e6ed8Sitojun.Fn getifaddrs "struct ifaddrs **ifap" 378b86f44bSitojun.Ft void 38636ea60aSmillert.Fn freeifaddrs "struct ifaddrs *ifap" 39da8e6ed8Sitojun.Sh DESCRIPTION 40da8e6ed8SitojunThe 41da8e6ed8Sitojun.Fn getifaddrs 42da8e6ed8Sitojunfunction stores a reference to a linked list of the network interfaces 43da8e6ed8Sitojunon the local machine in the memory referenced by 44da8e6ed8Sitojun.Fa ifap . 45da8e6ed8SitojunThe list consists of 46ee10762eSschwarze.Vt ifaddrs 47da8e6ed8Sitojunstructures, as defined in the include file 48369bef3aSschwarze.In ifaddrs.h . 49da8e6ed8SitojunThe 50ee10762eSschwarze.Vt ifaddrs 51da8e6ed8Sitojunstructure contains at least the following entries: 52da8e6ed8Sitojun.Bd -literal 53da8e6ed8Sitojun struct ifaddrs *ifa_next; /* Pointer to next struct */ 54da8e6ed8Sitojun char *ifa_name; /* Interface name */ 55da8e6ed8Sitojun u_int ifa_flags; /* Interface flags */ 56da8e6ed8Sitojun struct sockaddr *ifa_addr; /* Interface address */ 57da8e6ed8Sitojun struct sockaddr *ifa_netmask; /* Interface netmask */ 58da8e6ed8Sitojun struct sockaddr *ifa_broadaddr; /* Interface broadcast address */ 59da8e6ed8Sitojun struct sockaddr *ifa_dstaddr; /* P2P interface destination */ 60da8e6ed8Sitojun void *ifa_data; /* Address specific data */ 61da8e6ed8Sitojun.Ed 625a14067eSjaredy.Bl -tag -width ifa_broadaddr 6320472ffbSaaron.It Fa ifa_next 6420472ffbSaaronContains a pointer to the next structure on the list. 6520472ffbSaaronThis field is set to 66da8e6ed8Sitojun.Dv NULL 675a14067eSjaredyin the last structure on the list. 6820472ffbSaaron.It Fa ifa_name 6920472ffbSaaronContains the interface name. 7020472ffbSaaron.It Fa ifa_flags 7120472ffbSaaronContains the interface flags, as set by 7220472ffbSaaron.Xr ifconfig 8 . 7320472ffbSaaron.It Fa ifa_addr 7420472ffbSaaronReferences either the address of the interface or the link level 7520472ffbSaaronaddress of the interface, if one exists, otherwise it is 7620472ffbSaaron.Dv NULL . 77da8e6ed8Sitojun(The 7820472ffbSaaron.Fa sa_family 79da8e6ed8Sitojunfield of the 8020472ffbSaaron.Fa ifa_addr 81da8e6ed8Sitojunfield should be consulted to determine the format of the 8220472ffbSaaron.Fa ifa_addr 83da8e6ed8Sitojunaddress.) 8420472ffbSaaron.It Fa ifa_netmask 8520472ffbSaaronReferences the netmask associated with 8620472ffbSaaron.Fa ifa_addr , 8720472ffbSaaronif one is set, otherwise it is 8820472ffbSaaron.Dv NULL . 8920472ffbSaaron.It Fa ifa_broadaddr 9020472ffbSaaronThis field, which should only be referenced for non-P2P interfaces, 91da8e6ed8Sitojunreferences the broadcast address associated with 9220472ffbSaaron.Fa ifa_addr , 9320472ffbSaaronif one exists, otherwise it is 9420472ffbSaaron.Dv NULL . 9520472ffbSaaron.It Fa ifa_dstaddr 965269b272SkrwThis field, which should only be referenced for P2P interfaces, 975269b272Skrwreferences the destination address on a P2P interface, 9820472ffbSaaronif one exists, otherwise it is 9920472ffbSaaron.Dv NULL . 10020472ffbSaaron.It Fa ifa_data 10110cc2884SaaronReferences address family specific data. 10210cc2884SaaronFor 103da8e6ed8Sitojun.Dv AF_LINK 104da8e6ed8Sitojunaddresses it contains a pointer to the 105ee10762eSschwarze.Vt struct if_data 10620472ffbSaaron(as defined in include file 107369bef3aSschwarze.In net/if.h ) 108da8e6ed8Sitojunwhich contains various interface attributes and statistics. 1099d123722SjmcFor all other address families, 1109d123722Sjmc.Fa ifa_data 1119d123722Sjmcis 1129d123722Sjmc.Dv NULL . 11320472ffbSaaron.El 114da8e6ed8Sitojun.Pp 115da8e6ed8SitojunThe data returned by 116da8e6ed8Sitojun.Fn getifaddrs 117da8e6ed8Sitojunis dynamically allocated and should be freed using 1188b86f44bSitojun.Fn freeifaddrs 119da8e6ed8Sitojunwhen no longer needed. 120da8e6ed8Sitojun.Sh RETURN VALUES 121ee10762eSschwarze.Rv -std 122da8e6ed8Sitojun.Sh ERRORS 123da8e6ed8SitojunThe 124da8e6ed8Sitojun.Fn getifaddrs 125*4bc2832dSnaddyfunction may fail and set 126da8e6ed8Sitojun.Va errno 127da8e6ed8Sitojunfor any of the errors specified for the library routines 128da8e6ed8Sitojun.Xr ioctl 2 , 129da8e6ed8Sitojun.Xr socket 2 , 13020472ffbSaaron.Xr malloc 3 , 131da8e6ed8Sitojunor 132aaeccf36Sderaadt.Xr sysctl 2 . 133da8e6ed8Sitojun.Sh SEE ALSO 134da8e6ed8Sitojun.Xr ioctl 2 , 135da8e6ed8Sitojun.Xr socket 2 , 136aaeccf36Sderaadt.Xr sysctl 2 , 13722cd8fe1Sjmc.Xr netintro 4 , 138da8e6ed8Sitojun.Xr ifconfig 8 139da8e6ed8Sitojun.Sh HISTORY 140da8e6ed8SitojunThe 14120472ffbSaaron.Fn getifaddrs 1424973f6c2Sjmcfunction first appeared in BSDI 1434973f6c2Sjmc.Bsx . 1445a14067eSjaredyThe function has been available on 145350763acSitojun.Ox 146350763acSitojunsince 14720472ffbSaaron.Ox 2.7 . 148f9bdf54dSjmc.Sh BUGS 149f9bdf54dSjmcIf both 150369bef3aSschwarze.In net/if.h 151f9bdf54dSjmcand 152369bef3aSschwarze.In ifaddrs.h 153f9bdf54dSjmcare being included, 154369bef3aSschwarze.In net/if.h 155f9bdf54dSjmc.Em must 156f9bdf54dSjmcbe included before 157369bef3aSschwarze.In ifaddrs.h . 158