The OpenD Programming Language

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 
33 import core.sys.posix.sys.socket;
34 
35 ///
36 struct ifaddrs
37 {
38     /// Next item in the list
39     ifaddrs* ifa_next;
40     /// Name of the interface
41     char* ifa_name;
42     /// Flags from SIOCGIFFLAGS
43     uint ifa_flags;
44     /// Address of interface
45     sockaddr* ifa_addr;
46     /// Netmask of interface
47     sockaddr* ifa_netmask;
48     /// Point-to-point destination addresss
49     sockaddr* if_dstaddr;
50     /// Address specific data
51     void* ifa_data;
52 }
53 
54 /// Returns: linked list of ifaddrs structures describing interfaces
55 int getifaddrs(ifaddrs**);
56 /// Frees the linked list returned by getifaddrs
57 void freeifaddrs(ifaddrs*);
58 
59 ///
60 struct ifmaddrs
61 {
62     /// Pointer to next struct
63     ifmaddrs* ifma_next;
64     /// Interface name (AF_LINK)
65     sockaddr* ifma_name;
66     /// Multicast address
67     sockaddr* ifma_addr;
68     /// Link-layer translation, if any
69     sockaddr* ifma_lladdr;
70 }
71 
72 /// Stores a reference to a linked list of the multicast memberships
73 /// on the local machine in the memory referenced by ifmaddrs
74 int getifmaddrs(ifmaddrs**);
75 /// Frees the list allocated by getifmaddrs
76 void freeifmaddrs(ifmaddrs*);