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