2017-11-18 17:09:20 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
2014-02-25 20:37:03 +01:00
|
|
|
|
|
|
|
#include <string.h>
|
2015-11-16 22:09:36 +01:00
|
|
|
#include <sys/socket.h>
|
2014-02-25 20:37:03 +01:00
|
|
|
|
|
|
|
#include "af-list.h"
|
2015-11-30 21:43:37 +01:00
|
|
|
#include "macro.h"
|
2014-02-25 20:37:03 +01:00
|
|
|
|
2017-01-10 08:39:05 +01:00
|
|
|
static const struct af_name* lookup_af(register const char *str, register GPERF_LEN_TYPE len);
|
2014-02-25 20:37:03 +01:00
|
|
|
|
|
|
|
#include "af-from-name.h"
|
2015-11-16 22:09:36 +01:00
|
|
|
#include "af-to-name.h"
|
2014-02-25 20:37:03 +01:00
|
|
|
|
|
|
|
const char *af_to_name(int id) {
|
|
|
|
|
|
|
|
if (id <= 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (id >= (int) ELEMENTSOF(af_names))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return af_names[id];
|
|
|
|
}
|
|
|
|
|
|
|
|
int af_from_name(const char *name) {
|
|
|
|
const struct af_name *sc;
|
|
|
|
|
|
|
|
assert(name);
|
|
|
|
|
|
|
|
sc = lookup_af(name, strlen(name));
|
|
|
|
if (!sc)
|
|
|
|
return AF_UNSPEC;
|
|
|
|
|
|
|
|
return sc->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
int af_max(void) {
|
|
|
|
return ELEMENTSOF(af_names);
|
|
|
|
}
|