diff options
author | Lennart Poettering <lennart@poettering.net> | 2009-04-30 01:33:21 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2009-04-30 01:33:21 +0200 |
commit | 9208b86b5ecf72b69743a09cd0c8a99078c0fc0f (patch) | |
tree | b8396d17aa2b77b99076c5eae7ae739ce0762e24 | |
parent | d5f90575581b90417082d44968f579ea02d3c662 (diff) |
parseaddr: add new call pa_is_ip_address()
-rw-r--r-- | src/pulsecore/parseaddr.c | 15 | ||||
-rw-r--r-- | src/pulsecore/parseaddr.h | 2 |
2 files changed, 17 insertions, 0 deletions
diff --git a/src/pulsecore/parseaddr.c b/src/pulsecore/parseaddr.c index 5b531220..1cd010b7 100644 --- a/src/pulsecore/parseaddr.c +++ b/src/pulsecore/parseaddr.c @@ -25,6 +25,7 @@ #include <string.h> #include <stdlib.h> +#include <arpa/inet.h> #include <pulse/xmalloc.h> #include <pulse/util.h> @@ -131,3 +132,17 @@ int pa_parse_address(const char *name, pa_parsed_address *ret_p) { return 0; } + +pa_bool_t pa_is_ip_address(const char *a) { + char buf[INET6_ADDRSTRLEN]; + + pa_assert(a); + + if (inet_pton(AF_INET6, a, buf) >= 1) + return TRUE; + + if (inet_pton(AF_INET, a, buf) >= 1) + return TRUE; + + return FALSE; +} diff --git a/src/pulsecore/parseaddr.h b/src/pulsecore/parseaddr.h index 5fbcb9a7..0728b5ee 100644 --- a/src/pulsecore/parseaddr.h +++ b/src/pulsecore/parseaddr.h @@ -39,4 +39,6 @@ typedef struct pa_parsed_address { int pa_parse_address(const char *a, pa_parsed_address *ret_p); +pa_bool_t pa_is_ip_address(const char *a); + #endif |