1net(3) Erlang Module Definition net(3)
2
3
4
6 net - Network interface.
7
9 This module provides an API for the network interface.
10
12 address_info() =
13 #{family := socket:domain(),
14 socktype := socket:type(),
15 protocol := socket:protocol(),
16 address := socket:sockaddr()}
17
18 ifaddrs() =
19 #{name := string(),
20 flags := ifaddrs_flags(),
21 addr => socket:sockaddr(),
22 netmask => socket:sockaddr(),
23 broadaddr => socket:sockaddr(),
24 dstaddr => socket:sockaddr()}
25
26 This type defines all addresses (and flags) associated with the
27 interface.
28
29 Note:
30 Not all fields of this map has to be present. The flags field
31 can be used to test for some of the fields. For example broad‐
32 addr will only be present if the broadcast flag is present in
33 flags.
34
35
36 ifaddrs_flag() =
37 up | broadcast | debug | loopback | pointopoint | notrailers |
38 running | noarp | promisc | master | slave | multicast |
39 portsel | automedia | dynamic
40
41 ifaddrs_flags() = [ifaddrs_flag()]
42
43 ifaddrs_filter() =
44 all | default | inet | inet6 | packet |
45 ifaddrs_filter_map() |
46 ifaddrs_filter_fun()
47
48 all:
49 All interfaces
50
51 default:
52 Interfaces with address family inetandinet6
53
54 inet | inet6 | packet:
55 Interfaces with only the specified address family
56
57 ifaddrs_filter_map() =
58 #{family := default | inet | inet6 | packet | all,
59 flags := any | [ifaddrs_flag()]}
60
61 The family field can only have the (above) specified values (and
62 not all the values of socket:domain()).
63
64 The use of the flags field is that any flag provided must exist
65 for the interface.
66
67 For example, if family is set to inet and flags to [broadcast,
68 multicast] only interfaces with address family inet and the
69 flags broadcast and multicast will be listed.
70
71 ifaddrs_filter_fun() = fun((ifaddrs()) -> boolean())
72
73 For each ifaddrs entry, return either true to keep the entry or
74 false to discard the entry.
75
76 For example, to get an interface list which only contains non-
77 loopback inet interfaces:
78
79 net:getifaddrs(fun(#{addr := #{family := inet},
80 flags := Flags}) ->
81 not lists:member(loopback, Flags);
82 (_) ->
83 false
84 end).
85
86
87 name_info() = #{host := string(), service := string()}
88
89 name_info_flags() = [name_info_flag() | name_info_flag_ext()]
90
91 name_info_flag() =
92 namereqd | dgram | nofqdn | numerichost | numericserv
93
94 name_info_flag_ext() = idn
95
96 network_interface_name() = string()
97
98 network_interface_index() = integer() >= 0
99
101 gethostname() -> {ok, HostName} | {error, Reason}
102
103 Types:
104
105 HostName = string()
106 Reason = term()
107
108 Returns the name of the current host.
109
110 getnameinfo(SockAddr) -> {ok, Info} | {error, Reason}
111
112 getnameinfo(SockAddr, Flags) -> {ok, Info} | {error, Reason}
113
114 Types:
115
116 SockAddr = socket:sockaddr()
117 Flags = name_info_flags() | undefined
118 Info = name_info()
119 Reason = term()
120
121 Address-to-name translation in a protocol-independant manner.
122
123 This function is the inverse of getaddrinfo. It converts a
124 socket address to a corresponding host and service.
125
126 getaddrinfo(Host) -> {ok, Info} | {error, Reason}
127
128 getaddrinfo(Host, Service :: undefined) ->
129 {ok, Info} | {error, Reason}
130
131 getaddrinfo(Host :: undefined, Service) ->
132 {ok, Info} | {error, Reason}
133
134 getaddrinfo(Host, Service) -> {ok, Info} | {error, Reason}
135
136 Types:
137
138 Host = Service = string()
139 Info = [address_info()]
140 Reason = term()
141
142 Network address and service translation.
143
144 This function is the inverse of getnameinfo. It converts host
145 and service to a corresponding socket address.
146
147 One of the Host and Service may be undefined but not both.
148
149 getifaddrs() -> {ok, IfAddrs} | {error, Reason}
150
151 getifaddrs(Filter) -> {ok, IfAddrs} | {error, Reason}
152
153 getifaddrs(Namespace) -> {ok, IfAddrs} | {error, Reason}
154
155 getifaddrs(Filter, Namespace) -> {ok, IfAddrs} | {error, Reason}
156
157 Types:
158
159 Filter = ifaddrs_filter()
160 Namespace = file:filename_all()
161 IfAddrs = [ifaddrs()]
162 Reason = term()
163
164 Get interface addresses.
165
166 This function is used to get the machines interface addresses,
167 possibly filtered according to Filter.
168
169 By default, a filter with the content: #{family => default,
170 flags => any} is used. This will return all interfaces with ad‐
171 dresses in the inet and inet6 families.
172
173 if_name2index(Name) -> {ok, Idx} | {error, Reason}
174
175 Types:
176
177 Name = network_interface_name()
178 Idx = network_interface_index()
179 Reason = term()
180
181 Mappings between network interface names and indexes.
182
183 if_index2name(Idx) -> {ok, Name} | {error, Reason}
184
185 Types:
186
187 Idx = network_interface_index()
188 Name = network_interface_name()
189 Reason = term()
190
191 Mappings between network interface index and names.
192
193 if_names() -> {ok, Names} | {error, Reason}
194
195 Types:
196
197 Names = [{Idx, If}]
198 Idx = network_interface_index()
199 If = network_interface_name()
200 Reason = term()
201
202 Get network interface names and indexes.
203
204
205
206Ericsson AB kernel 8.5.4.2 net(3)