summaryrefslogtreecommitdiff
path: root/src/libstddjb/ip4_fmt.c
blob: 9804b38aee38ae4060a60cfb9454d9b78db88ad2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* ISC license. */

#include <sys/types.h>
#include <skalibs/uint32.h>
#include <skalibs/fmtscan.h>

size_t ip4_fmt (char *s, char const *ip)
{
  size_t len = 0 ;
  unsigned int j = 0 ;
  for (; j < 4 ; j++)
  {
    size_t i = uint32_fmt(s, (unsigned char)ip[j]) ;
    len += i ;
    if (s) s += i ;
    if (j == 3) break ;
    if (s) *s++ = '.' ;
    ++len ;
  }
  return len ;
}