1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in 12 * the documentation and/or other materials provided with the 13 * distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 #pragma once 30 31 /** 32 * @file ifaddrs.h 33 * @brief Access to network interface addresses. 34 */ 35 36 #include <sys/cdefs.h> 37 #include <netinet/in.h> 38 #include <sys/socket.h> 39 40 __BEGIN_DECLS 41 42 /** 43 * Returned by getifaddrs() and freed by freeifaddrs(). 44 */ 45 struct ifaddrs { 46 /** Pointer to the next element in the linked list. */ 47 struct ifaddrs* _Nullable ifa_next; 48 49 /** Interface name. */ 50 char* _Nullable ifa_name; 51 /** Interface flags (like `SIOCGIFFLAGS`). */ 52 unsigned int ifa_flags; 53 /** Interface address. */ 54 struct sockaddr* _Nullable ifa_addr; 55 /** Interface netmask. */ 56 struct sockaddr* _Nullable ifa_netmask; 57 58 union { 59 /** Interface broadcast address (if IFF_BROADCAST is set). */ 60 struct sockaddr* _Nullable ifu_broadaddr; 61 /** Interface destination address (if IFF_POINTOPOINT is set). */ 62 struct sockaddr* _Nullable ifu_dstaddr; 63 } ifa_ifu; 64 65 /** Unused. */ 66 void* _Nullable ifa_data; 67 }; 68 69 /** Synonym for `ifa_ifu.ifu_broadaddr` in `struct ifaddrs`. */ 70 #define ifa_broadaddr ifa_ifu.ifu_broadaddr 71 /** Synonym for `ifa_ifu.ifu_dstaddr` in `struct ifaddrs`. */ 72 #define ifa_dstaddr ifa_ifu.ifu_dstaddr 73 74 /** 75 * [getifaddrs(3)](http://man7.org/linux/man-pages/man3/getifaddrs.3.html) creates a linked list 76 * of `struct ifaddrs`. The list must be freed by freeifaddrs(). 77 * 78 * Returns 0 and stores the list in `*__list_ptr` on success, 79 * and returns -1 and sets `errno` on failure. 80 * 81 * Available since API level 24. 82 */ 83 int getifaddrs(struct ifaddrs* _Nullable * _Nonnull __list_ptr) __INTRODUCED_IN(24); 84 85 /** 86 * [freeifaddrs(3)](http://man7.org/linux/man-pages/man3/freeifaddrs.3.html) frees a linked list 87 * of `struct ifaddrs` returned by getifaddrs(). 88 * 89 * Available since API level 24. 90 */ 91 void freeifaddrs(struct ifaddrs* _Nullable __ptr) __INTRODUCED_IN(24); 92 93 __END_DECLS 94