2 // Copyright (c) 2010-2017 Intel Corporation
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
24 uint8_t prefix; /* always in range [1,32] inclusive */
29 uint8_t prefix; /* always in range [1,128] inclusive */
32 /* Returns number of hosts (assuming that network address and
33 broadcast address are both hosts) within the subnet. */
34 uint32_t ip4_subet_get_n_hosts(const struct ip4_subnet *sn);
36 /* Allows to get a specific host within a subnet. Note that the
37 network address and broadcast address are both considered to
38 "hosts". Setting host_index to 0 returns the network address and
39 setting the host_index to the last host within the subnet returns
40 the broadcast. To get all addresses with the subnet, loop
41 host_index from 0 to ip_subnet_get_n_hosts(). */
42 int ip4_subnet_to_host(const struct ip4_subnet* sn, uint32_t host_index, uint32_t* ret_ip);
44 /* Check if IP address is a network address (i.e. all bits outside the
45 prefix are set to 0). */
46 int ip4_subnet_is_valid(const struct ip4_subnet* sn);
48 #endif /* _IP_SUBNET_H_ */