1 /*******************************************************************************
2 
3     Binding for Mac OSX's <ifaddr.h>, expose network interface addresses
4 
5     The following functions are present as of Mac OSX 10.15:
6     - getifaddrs(3):   get interface addresses
7     - freeifaddrs(3):  deallocates the return value of `getifaddrs`
8     - getifmaddrs(3):  get multicast group membership
9     - freeifmaddrs(3): deallocates the return value of `getifmaddrs`
10 
11     Copyright:  Copyright © 2020, The D Language Foundation
12     License:    $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
13     Authors:    Daniel Graczer
14 
15 *******************************************************************************/
16 
17 module core.sys.darwin.ifaddrs;
18 
19 version (OSX)
20     version = Darwin;
21 else version (iOS)
22     version = Darwin;
23 else version (TVOS)
24     version = Darwin;
25 else version (WatchOS)
26     version = Darwin;
27 
28 version (Darwin):
29 extern (C):
30 nothrow:
31 @nogc:
32 @system:
33 
34 import core.sys.posix.sys.socket;
35 
36 ///
37 struct ifaddrs
38 {
39     /// Next item in the list
40     ifaddrs* ifa_next;
41     /// Name of the interface
42     char* ifa_name;
43     /// Flags from SIOCGIFFLAGS
44     uint ifa_flags;
45     /// Address of interface
46     sockaddr* ifa_addr;
47     /// Netmask of interface
48     sockaddr* ifa_netmask;
49     /// Point-to-point destination addresss
50     sockaddr* if_dstaddr;
51     /// Address specific data
52     void* ifa_data;
53 }
54 
55 /// Returns: linked list of ifaddrs structures describing interfaces
56 int getifaddrs(ifaddrs**);
57 /// Frees the linked list returned by getifaddrs
58 void freeifaddrs(ifaddrs*);
59 
60 ///
61 struct ifmaddrs
62 {
63     /// Pointer to next struct
64     ifmaddrs* ifma_next;
65     /// Interface name (AF_LINK)
66     sockaddr* ifma_name;
67     /// Multicast address
68     sockaddr* ifma_addr;
69     /// Link-layer translation, if any
70     sockaddr* ifma_lladdr;
71 }
72 
73 /// Stores a reference to a linked list of the multicast memberships
74 /// on the local machine in the memory referenced by ifmaddrs
75 int getifmaddrs(ifmaddrs**);
76 /// Frees the list allocated by getifmaddrs
77 void freeifmaddrs(ifmaddrs*);
78