13#define BITSUBSTITUTION
15static char strnum[FMT_ULONG];
33 const char *letterarray =
"abcdefghijklmnopqrstuvwxyz123456";
36 if (!stralloc_copys(ip4string,
""))
return -1;
37 if (!stralloc_readyplus(ip4string,32))
return -1;
40 for (i = 0; i < 4; i++) {
41 number = (
unsigned char) ip4[i];
42 for (j = 7; j >= 0; j--) {
43 if (number & (1<<j)) {
45 if (!stralloc_catb(ip4string,letterarray + count,1))
return -1;
47 if (!stralloc_cats(ip4string,
"1"))
return -1;
50 if (!stralloc_cats(ip4string,
"0"))
return -1;
54 if (prefix == 0)
return 0;
76 if (!stralloc_copys(ip4addr,
""))
return -1;
77 prefix = ip4string->len - 1;
79 if (prefix <= 0)
return 1;
80 if (prefix <= 1 || prefix > 32)
return 1;
82 for (j = 1; j <= prefix; j++) {
83 if (ip4string->s[j] !=
'0') {
88 if (j % 8 == 0 || j == prefix) {
89 if (!stralloc_catb(ip4addr,strnum,fmt_ulong(strnum,num)))
return -1;
90 if (j < 32)
if (!stralloc_cats(ip4addr,
"."))
return -1;
96 if (!stralloc_cats(ip4addr,
"/"))
return -1;
97 if (!stralloc_catb(ip4addr,strnum,fmt_ulong(strnum,prefix)))
return -1;
98 if (!stralloc_0(ip4addr))
return -1;
int ip4_bitstring(stralloc *ip4string, char *ip, unsigned int prefix)
int bitstring_ip4(stralloc *ip4addr, stralloc *ip4string)