add generic lookup of af_name mappings

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
This commit is contained in:
John Johansen 2014-08-23 23:57:55 -07:00
parent f5704761b5
commit bccca11bf6
2 changed files with 21 additions and 0 deletions

View file

@ -305,6 +305,25 @@ static const char *network_families[] = {
#include "af_names.h"
};
int net_find_af_val(const char *af)
{
int i;
for (i = 0; network_families[i]; i++) {
if (strcmp(network_families[i], af) == 0)
return i;
}
return -1;
}
const char *net_find_af_name(unsigned int af)
{
if (af < 0 || af > get_af_max())
return NULL;
return network_families[af];
}
void __debug_network(unsigned int *array, const char *name)
{
unsigned int count = sizeof(sock_types)/sizeof(sock_types[0]);

View file

@ -77,5 +77,7 @@ struct network {
int net_find_type_val(const char *type);
const char *net_find_type_name(int type);
int net_find_af_val(const char *af);
const char *net_find_af_name(unsigned int af);
#endif /* __AA_NETWORK_H */