aboutsummaryrefslogtreecommitdiff
path: root/ip6_fmt.c
diff options
context:
space:
mode:
authorHenryk Plötz <henryk@ploetzli.ch>2014-10-03 20:04:14 +0200
committerHenryk Plötz <henryk@ploetzli.ch>2014-10-03 20:04:14 +0200
commitc44d8b51ffb5a413f8bbdbd9991bbc573853e397 (patch)
treee7f2e644de620879f610c909c405cbc4e44d6062 /ip6_fmt.c
parent0e5b2871ca6456b01d4bf037a6e68badf1ff1a41 (diff)
downloadtinydnssec-c44d8b51ffb5a413f8bbdbd9991bbc573853e397.tar.gz
tinydnssec-c44d8b51ffb5a413f8bbdbd9991bbc573853e397.tar.bz2
Apply patch djbdns-1.05-test27.diff.bz2
Source was http://www.fefe.de/dns/djbdns-1.05-test27.diff.bz2, SHA1 f0380ec1866f49c0bcf6369a923ac0a4a5095da8
Diffstat (limited to 'ip6_fmt.c')
-rw-r--r--ip6_fmt.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/ip6_fmt.c b/ip6_fmt.c
new file mode 100644
index 0000000..ce2115a
--- /dev/null
+++ b/ip6_fmt.c
@@ -0,0 +1,60 @@
+#include "fmt.h"
+#include "byte.h"
+#include "ip4.h"
+#include "ip6.h"
+#include <stdio.h>
+
+extern char tohex(char num);
+
+unsigned int ip6_fmt(char *s,const char ip[16])
+{
+ unsigned int len;
+ unsigned int i;
+ unsigned int temp;
+ unsigned int compressing;
+ unsigned int compressed;
+ int j;
+
+ len = 0; compressing = 0; compressed = 0;
+ for (j=0; j<16; j+=2) {
+ if (j==12 && ip6_isv4mapped(ip)) {
+ temp=ip4_fmt(s,ip+12);
+ len+=temp;
+ break;
+ }
+ temp = ((unsigned long) (unsigned char) ip[j] << 8) +
+ (unsigned long) (unsigned char) ip[j+1];
+ if (temp == 0 && !compressed) {
+ if (!compressing) {
+ compressing=1;
+ if (j==0) {
+ if (s) *s++=':'; ++len;
+ }
+ }
+ } else {
+ if (compressing) {
+ compressing=0; ++compressed;
+ if (s) *s++=':'; ++len;
+ }
+ i = fmt_xlong(s,temp); len += i; if (s) s += i;
+ if (j<14) {
+ if (s) *s++ = ':';
+ ++len;
+ }
+ }
+ }
+ if (compressing) { *s++=':'; ++len; }
+
+/* if (s) *s=0; */
+ return len;
+}
+
+unsigned int ip6_fmt_flat(char *s,const char ip[16])
+{
+ int i;
+ for (i=0; i<16; i++) {
+ *s++=tohex((unsigned char)ip[i] >> 4);
+ *s++=tohex((unsigned char)ip[i] & 15);
+ }
+ return 32;
+}