summaryrefslogtreecommitdiff
path: root/accel-pppd/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'accel-pppd/utils.c')
-rw-r--r--accel-pppd/utils.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/accel-pppd/utils.c b/accel-pppd/utils.c
index 81b4c993..3b87ee16 100644
--- a/accel-pppd/utils.c
+++ b/accel-pppd/utils.c
@@ -1,7 +1,9 @@
#include <errno.h>
+#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include <netinet/in.h>
#include "triton.h"
#include "utils.h"
@@ -35,6 +37,31 @@ int __export u_readlong(long int *dst, const char *src,
}
}
+int __export u_parse_ip4addr(const char *src, struct in_addr *addr,
+ const char **err_msg)
+{
+ struct addrinfo hint = {
+ .ai_flags = AI_NUMERICHOST,
+ .ai_family = AF_INET,
+ .ai_socktype = 0,
+ .ai_protocol = 0,
+ };
+ struct addrinfo *ainfo;
+ int err;
+
+ err = getaddrinfo(src, NULL, &hint, &ainfo);
+ if (err) {
+ *err_msg = gai_strerror(err);
+ return err;
+ }
+
+ *addr = ((struct sockaddr_in *)ainfo->ai_addr)->sin_addr;
+
+ freeaddrinfo(ainfo);
+
+ return 0;
+}
+
int __export u_randbuf(void *buf, size_t buf_len, int *err)
{
uint8_t *u8buf = buf;