ucspi-ssl  0.99e
TLS encryption for IPv6 communication
ip6_expandaddr.c
Go to the documentation of this file.
1 #include "byte.h"
2 #include "stralloc.h"
3 #include "str.h"
4 #include "ip6.h"
5 #include "hexconversion.h"
6 
15 unsigned int ip6_expandaddr(char *src,stralloc *destination)
16 {
17  stralloc addresstemp = {0};
18  char ip6[16] = {0};
19  char hexvalue[3] = {0, 0, 0};
20  int i;
21 
22 
23  if (!stralloc_copys(&addresstemp,src)) return -1;
24  if (!stralloc_0(&addresstemp)) return -1;
25 
26  if (ip6_scan(addresstemp.s,ip6) == 0) return 0;
27 
28  if (!stralloc_copys(destination,"")) return -1;
29 
30  for (i=0; i<16; i++) {
31  bytetohex((unsigned char)ip6[i],hexvalue);
32  stralloc_catb(destination,hexvalue,2);
33  if (!((i+1)%2) && (i+1)<16)
34  if (!stralloc_cats(destination,":")) return -1; /*Append ':' after every two bytes.*/
35  }
36 
37  return 1;
38 }
int stralloc_cats(stralloc *, const char *)
Definition: stralloc_cats.c:7
#define stralloc_0(sa)
Definition: stralloc.h:21
void bytetohex(unsigned char decimal, char hex[3])
Definition: hexconversion.c:8
unsigned int ip6_scan(const char *src, char *ip)
int stralloc_catb(stralloc *, const char *, unsigned int)
Definition: stralloc_catb.c:6
int stralloc_copys(stralloc *, const char *)
Definition: stralloc_opys.c:7
unsigned int ip6_expandaddr(char *src, stralloc *destination)