Commit 45c90d19 authored by Eric W. Biederman's avatar Eric W. Biederman Committed by Stephen Hemminger

add address family to/from string helper functions.

Add the functions family_name and read_family to convert an address
family to a string and to convernt a string to an address family.
Signed-off-by: default avatar"Eric W. Biederman" <ebiederm@xmission.com>
parent 0b218ab1
...@@ -109,6 +109,9 @@ extern const char *format_host(int af, int len, const void *addr, ...@@ -109,6 +109,9 @@ extern const char *format_host(int af, int len, const void *addr,
extern const char *rt_addr_n2a(int af, int len, const void *addr, extern const char *rt_addr_n2a(int af, int len, const void *addr,
char *buf, int buflen); char *buf, int buflen);
extern int read_family(const char *name);
extern const char *family_name(int family);
void missarg(const char *) __attribute__((noreturn)); void missarg(const char *) __attribute__((noreturn));
void invarg(const char *, const char *) __attribute__((noreturn)); void invarg(const char *, const char *) __attribute__((noreturn));
void duparg(const char *, const char *) __attribute__((noreturn)); void duparg(const char *, const char *) __attribute__((noreturn));
......
...@@ -190,21 +190,11 @@ int main(int argc, char **argv) ...@@ -190,21 +190,11 @@ int main(int argc, char **argv)
argv++; argv++;
if (argc <= 1) if (argc <= 1)
usage(); usage();
if (strcmp(argv[1], "inet") == 0) if (strcmp(argv[1], "help") == 0)
preferred_family = AF_INET;
else if (strcmp(argv[1], "inet6") == 0)
preferred_family = AF_INET6;
else if (strcmp(argv[1], "dnet") == 0)
preferred_family = AF_DECnet;
else if (strcmp(argv[1], "link") == 0)
preferred_family = AF_PACKET;
else if (strcmp(argv[1], "ipx") == 0)
preferred_family = AF_IPX;
else if (strcmp(argv[1], "bridge") == 0)
preferred_family = AF_BRIDGE;
else if (strcmp(argv[1], "help") == 0)
usage(); usage();
else else
preferred_family = read_family(argv[1]);
if (preferred_family == AF_UNSPEC)
invarg("invalid protocol family", argv[1]); invarg("invalid protocol family", argv[1]);
} else if (strcmp(opt, "-4") == 0) { } else if (strcmp(opt, "-4") == 0) {
preferred_family = AF_INET; preferred_family = AF_INET;
......
...@@ -666,6 +666,41 @@ const char *rt_addr_n2a(int af, int len, const void *addr, char *buf, int buflen ...@@ -666,6 +666,41 @@ const char *rt_addr_n2a(int af, int len, const void *addr, char *buf, int buflen
} }
} }
int read_family(const char *name)
{
int family = AF_UNSPEC;
if (strcmp(name, "inet") == 0)
family = AF_INET;
else if (strcmp(name, "inet6") == 0)
family = AF_INET6;
else if (strcmp(name, "dnet") == 0)
family = AF_DECnet;
else if (strcmp(name, "link") == 0)
family = AF_PACKET;
else if (strcmp(name, "ipx") == 0)
family = AF_IPX;
else if (strcmp(name, "bridge") == 0)
family = AF_BRIDGE;
return family;
}
const char *family_name(int family)
{
if (family == AF_INET)
return "inet";
if (family == AF_INET6)
return "inet6";
if (family == AF_DECnet)
return "dnet";
if (family == AF_PACKET)
return "link";
if (family == AF_IPX)
return "ipx";
if (family == AF_BRIDGE)
return "bridge";
return "???";
}
#ifdef RESOLVE_HOSTNAMES #ifdef RESOLVE_HOSTNAMES
struct namerec struct namerec
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment