summaryrefslogtreecommitdiff
path: root/src/libstddjb/ip46_scanlist.c
blob: 6462da7c3e0ef40cb09b2894175444a77e62aa6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/* ISC license. */

#include <skalibs/ip46.h>

#include <skalibs/bytestr.h>
#include <skalibs/fmtscan.h>

unsigned int ip46full_scanlist (ip46full_t *out, unsigned int max, char const *s, unsigned int *num)
{
  unsigned int n = 0, w = 0 ;
  for (; s[w] && (n < max) ; n++)
  {
    ip46full_t z ;
    register unsigned int i = ip6_scan(s + w, z.ip) ;
    if (i) z.is6 = 1 ;
    else
    {
      i = ip4_scan(s + w, z.ip) ;
      if (!i) break ;
      z.is6 = 0 ;
    }
    out[n] = z ;
    w += i ;
    while (byte_chr(",; \t\r\n", 6, s[w]) < 6) w++ ;
  }
  *num = n ;
  return w ;
}