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