summaryrefslogtreecommitdiff
path: root/src/ot_ip.h
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2026-11-02 20:50:24 +0100
committerDirk Engling <erdgeist@erdgeist.org>2026-11-02 21:14:02 +0100
commitad541c67761b8aa6da1566802c347cac4018d0c2 (patch)
treea9166fa9d349911d69a6948e53b05344dcc348a0 /src/ot_ip.h
parentc679ff8a3b1418a5960cc49ba6458a0007df54fa (diff)
Move the build sources into src/
Diffstat (limited to 'src/ot_ip.h')
-rw-r--r--src/ot_ip.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/ot_ip.h b/src/ot_ip.h
new file mode 100644
index 0000000..533403e
--- /dev/null
+++ b/src/ot_ip.h
@@ -0,0 +1,31 @@
1/* This software was written by Dirk Engling <erdgeist@erdgeist.org>
2 It is considered beerware. Prost. Skol. Cheers or whatever. */
3
4#ifndef OT_IP_H__
5#define OT_IP_H__
6
7#include <stddef.h>
8#include <string.h>
9
10#include "trackerlogic.h"
11
12/* opentracker holds every address as sixteen bytes, writing IPv4 as the v4
13 mapped form of RFC 4291 section 2.5.5.2. */
14extern const char ip_v4mapped_prefix[12];
15
16static inline int ip_is_v4mapped(const void *ip) { return !memcmp(ip, ip_v4mapped_prefix, sizeof(ip_v4mapped_prefix)); }
17
18/* Read an address and return how many characters it took, or zero if src
19 does not start with one. A plain IPv4 address is accepted and stored in
20 its v4 mapped form.
21
22 The count lets the caller carry on where the address ended, which is how
23 "address:port" and "address/bits" are read. */
24size_t ip_parse(const char *src, ot_ip6 ip);
25
26/* Write an address and return how many characters it took. Nothing is
27 terminated, so a caller may keep appending. A v4 mapped address is written
28 as the plain dotted quad rather than "::ffff:1.2.3.4". */
29size_t ip_format(char *dest, const ot_ip6 ip);
30
31#endif