diff options
| author | Guillaume Nault <g.nault@alphalink.fr> | 2018-11-30 17:36:16 +0100 |
|---|---|---|
| committer | Dmitry Kozlov <xeb@mail.ru> | 2018-12-04 06:26:37 +0300 |
| commit | 68475cd0e1bfb30f8391e04ad2ec1770482ff74c (patch) | |
| tree | b390f0aa2da2f8b2187fbde681be52224ce6c63d /accel-pppd/utils.h | |
| parent | 896b7ae69c33721d70837202257d3674d22fe465 (diff) | |
| download | accel-ppp-68475cd0e1bfb30f8391e04ad2ec1770482ff74c.tar.gz accel-ppp-68475cd0e1bfb30f8391e04ad2ec1770482ff74c.zip | |
utils: add string parsing helpers
Define parsers for IPv6 addresses and CIDR notations, unsigned
integers, separators (variable number of space characters) and end of
strings (variable number of spaces followed by '\0').
All of these functions work on constant string and return the number
bytes parsed. If the input string doesn't have the expected format,
these functions return 0 (no forward progress).
Also implement a convenient wrapper around inet_ntop() that can be used
easily in printf-like functions.
Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
Diffstat (limited to 'accel-pppd/utils.h')
| -rw-r--r-- | accel-pppd/utils.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/accel-pppd/utils.h b/accel-pppd/utils.h index 8758264..d3e0608 100644 --- a/accel-pppd/utils.h +++ b/accel-pppd/utils.h @@ -2,11 +2,25 @@ #define __UTILS_H #include <netinet/in.h> +#include <stdint.h> + +char *u_ip6str(const struct in6_addr *addr, char *buf); void u_inet_ntoa(in_addr_t, char *str); int u_readlong(long int *dst, const char *src, long int min, long int max); + +size_t u_parse_spaces(const char *str); +size_t u_parse_endstr(const char *str); + +size_t u_parse_u8(const char *str, uint8_t *val); +size_t u_parse_u16(const char *str, uint16_t *val); +size_t u_parse_u32(const char *str, uint32_t *val); + int u_parse_ip4addr(const char *src, struct in_addr *addr, const char **err_msg); +size_t u_parse_ip6addr(const char *str, struct in6_addr *addr); +size_t u_parse_ip6cidr(const char *str, struct in6_addr *netp, uint8_t *plen); + int u_randbuf(void *buf, size_t buf_len, int *err); #endif |
