net/ipv6: Return string pointer when splitting IPv6 interface.
Right now 'ipv6_addr_split_iface' assumes that the interface specifier will always be a number (based on GNRC way of identifying interfaces), but this may not be always the case.In order to be able to use the Network Interface API, interfaces should be referred by their name. This changes 'ipv6_addr_split_iface' so it returns a pointer to the string that specifies the interface.
This commit is contained in:
parent
27e8caf3f3
commit
4d4f6ae1d6
@ -729,6 +729,20 @@ char *ipv6_addr_to_str(char *result, const ipv6_addr_t *addr, uint8_t result_len
|
|||||||
*/
|
*/
|
||||||
ipv6_addr_t *ipv6_addr_from_str(ipv6_addr_t *result, const char *addr);
|
ipv6_addr_t *ipv6_addr_from_str(ipv6_addr_t *result, const char *addr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief split IPv6 address string representation and return remaining string
|
||||||
|
*
|
||||||
|
* Will change @p separator position in @p addr_str to '\0'
|
||||||
|
*
|
||||||
|
* @param[in,out] addr_str Address to split
|
||||||
|
* @param[in] separator Separator char to use
|
||||||
|
*
|
||||||
|
* @return string following the first occurrence of @p separator in
|
||||||
|
* @p addr_str.
|
||||||
|
* @return NULL if @p separator was not found.
|
||||||
|
*/
|
||||||
|
char *ipv6_addr_split_str(char *addr_str, char separator);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief split IPv6 address string representation
|
* @brief split IPv6 address string representation
|
||||||
*
|
*
|
||||||
@ -741,7 +755,7 @@ ipv6_addr_t *ipv6_addr_from_str(ipv6_addr_t *result, const char *addr);
|
|||||||
* @return atoi(string after split)
|
* @return atoi(string after split)
|
||||||
* @return @p _default if no string after @p seperator
|
* @return @p _default if no string after @p seperator
|
||||||
*/
|
*/
|
||||||
int ipv6_addr_split(char *addr_str, char seperator, int _default);
|
int ipv6_addr_split_int(char *addr_str, char seperator, int _default);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief split IPv6 prefix string representation
|
* @brief split IPv6 prefix string representation
|
||||||
@ -753,7 +767,7 @@ int ipv6_addr_split(char *addr_str, char seperator, int _default);
|
|||||||
*/
|
*/
|
||||||
static inline int ipv6_addr_split_prefix(char *addr_str)
|
static inline int ipv6_addr_split_prefix(char *addr_str)
|
||||||
{
|
{
|
||||||
return ipv6_addr_split(addr_str, '/', 128);
|
return ipv6_addr_split_int(addr_str, '/', 128);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -762,11 +776,12 @@ static inline int ipv6_addr_split_prefix(char *addr_str)
|
|||||||
* E.g., "fe80::1%5" returns "5", changes @p addr_str to "fe80::1"
|
* E.g., "fe80::1%5" returns "5", changes @p addr_str to "fe80::1"
|
||||||
*
|
*
|
||||||
* @param[in,out] addr_str Address to split
|
* @param[in,out] addr_str Address to split
|
||||||
* @return interface number or -1 if none specified
|
* @return string containing the interface specifier.
|
||||||
|
* @return NULL if no interface was specified.
|
||||||
*/
|
*/
|
||||||
static inline int ipv6_addr_split_iface(char *addr_str)
|
static inline char *ipv6_addr_split_iface(char *addr_str)
|
||||||
{
|
{
|
||||||
return ipv6_addr_split(addr_str, '%', -1);
|
return ipv6_addr_split_str(addr_str, '%');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -123,20 +123,23 @@ void ipv6_addr_init_iid(ipv6_addr_t *out, const uint8_t *iid, uint8_t bits)
|
|||||||
memcpy(&(out->u8[pos]), iid, bytes);
|
memcpy(&(out->u8[pos]), iid, bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ipv6_addr_split(char *addr_str, char seperator, int _default)
|
char *ipv6_addr_split_str(char *addr_str, char seperator)
|
||||||
{
|
{
|
||||||
char *sep = addr_str;
|
char *sep = addr_str;
|
||||||
while(*++sep) {
|
while (*(++sep)) {
|
||||||
if (*sep == seperator) {
|
if (*sep == seperator) {
|
||||||
*sep++ = '\0';
|
*sep++ = '\0';
|
||||||
if (*sep) {
|
|
||||||
_default = atoi(sep);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return _default;
|
return *sep ? sep : NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ipv6_addr_split_int(char *addr_str, char separator, int _default)
|
||||||
|
{
|
||||||
|
char *val = ipv6_addr_split_str(addr_str, separator);
|
||||||
|
return val ? atoi(val) : _default;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ipv6_addr_print(const ipv6_addr_t *addr)
|
void ipv6_addr_print(const ipv6_addr_t *addr)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user