net: if: Start index numbering from 1

In order to follow the BSD socket numbering of the network
interfaces, start numbering from 1. The index 0 is reserved
to mean any interface in BSD socket code.

Fixes #13084

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
Jukka Rissanen 2019-02-14 11:37:23 +02:00 committed by Anas Nashif
parent f626c3ccbe
commit 3206568e43
2 changed files with 14 additions and 8 deletions

View File

@ -1632,7 +1632,7 @@ bool net_if_need_calc_tx_checksum(struct net_if *iface);
*
* @return Pointer to interface or NULL if not found.
*/
struct net_if *net_if_get_by_index(u8_t index);
struct net_if *net_if_get_by_index(int index);
/**
* @brief Get interface index according to pointer
@ -1641,7 +1641,7 @@ struct net_if *net_if_get_by_index(u8_t index);
*
* @return Interface index
*/
u8_t net_if_get_by_iface(struct net_if *iface);
int net_if_get_by_iface(struct net_if *iface);
/**
* @typedef net_if_cb_t

View File

@ -2818,21 +2818,27 @@ bool net_if_need_calc_rx_checksum(struct net_if *iface)
return need_calc_checksum(iface, ETHERNET_HW_RX_CHKSUM_OFFLOAD);
}
struct net_if *net_if_get_by_index(u8_t index)
struct net_if *net_if_get_by_index(int index)
{
if (&__net_if_start[index] >= __net_if_end) {
if (index <= 0) {
return NULL;
}
if (&__net_if_start[index - 1] >= __net_if_end) {
NET_DBG("Index %d is too large", index);
return NULL;
}
return &__net_if_start[index];
return &__net_if_start[index - 1];
}
u8_t net_if_get_by_iface(struct net_if *iface)
int net_if_get_by_iface(struct net_if *iface)
{
NET_ASSERT(iface >= __net_if_start && iface < __net_if_end);
if (!(iface >= __net_if_start && iface < __net_if_end)) {
return -1;
}
return iface - __net_if_start;
return (iface - __net_if_start) + 1;
}
void net_if_foreach(net_if_cb_t cb, void *user_data)