2001-02-05 22:09:26 +00:00
|
|
|
#include "scan.h"
|
|
|
|
#include "ip4.h"
|
|
|
|
|
2014-03-14 19:42:54 +00:00
|
|
|
size_t scan_ip4(const char *s,char ip[4])
|
2001-02-05 22:09:26 +00:00
|
|
|
{
|
2014-03-14 19:42:54 +00:00
|
|
|
size_t i,len;
|
2001-02-05 22:09:26 +00:00
|
|
|
unsigned long u;
|
|
|
|
|
|
|
|
len = 0;
|
|
|
|
for (i=0; i<4; ++i) {
|
2014-03-14 19:42:54 +00:00
|
|
|
register size_t j;
|
2001-02-05 22:09:26 +00:00
|
|
|
len+=(j=scan_ulong(s,&u))+1;
|
2014-03-14 19:42:54 +00:00
|
|
|
if (!j || u>255) return 0;
|
|
|
|
ip[i]=(char)u; s+=j;
|
2016-04-27 14:07:49 +00:00
|
|
|
if (i<3 && *s!='.') return 0;
|
|
|
|
++s;
|
2001-02-05 22:09:26 +00:00
|
|
|
}
|
|
|
|
return len-1;
|
|
|
|
}
|