#include #include #include /* * Analog IPv6 pre processor * * Copyright (C) 2012, 2018 R.J. van der Putten, Leiden, Holland, * rob at sput dot nl. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ int main(void) { int i, j, k, ip6fl, len; char str[4096]; int qnp[8]; /* Reverses quad nibbles * 1:2:3:4:5:6:7:8 * 8.7.6.5.4.3.2.1.ipvsix * replaces :: with .z. */ bzero(str, 4096); bzero(qnp, sizeof(qnp)); /* Points to ':' positions */ while (fgets(str, 4096, stdin)) { i = 0; ip6fl = 0; /* IPv6 Flag */ len = strlen(str); while (i < len) { if (str[i] == ' ') { if (i > 40) { ip6fl = 0; break; } j = 0; k = 0; while (j < i) { if (k > 7) { ip6fl = 0; break; } if (str[j] == ':') { qnp[k] = j; ip6fl = 1; k++; } j++; } if (ip6fl != 0) { if(i > 0 && str[i - 1] == ':') /* Ends with ':' */ printf("0"); str[i] = 0; k--; while(k > -1) { j = qnp[k]; printf("%s", str + j + 1); str[qnp[k]] = 0; k--; printf("."); if(k > -1 && j - qnp[k] == 1) printf("z"); } if(str[0] == 0) /* Starts with ':' */ printf("0"); else printf("%s", str); printf(".ipvsix %s", str + i + 1); } break; } i++; } if(ip6fl == 0) printf("%s", str); } return(0); }