1 /**************************************************************************
3 **************************************************************************/
5 FILE_LICENCE ( GPL2_OR_LATER );
11 #include <ipxe/timer.h>
13 /**************************************************************************
14 INET_ATON - Convert an ascii x.x.x.x to binary form
15 **************************************************************************/
16 int inet_aton ( const char *cp, struct in_addr *inp ) {
18 const char *digits_start;
22 for(j = 0; j <= 3; j++) {
24 val = strtoul(p, ( char ** ) &p, 10);
25 if ((p == digits_start) || (val > 255)) return 0;
26 if ( ( j < 3 ) && ( *(p++) != '.' ) ) return 0;
30 inp->s_addr = htonl(ip);
36 unsigned int strtoul_charval ( unsigned int charval ) {
38 if ( charval >= 'a' ) {
39 charval = ( charval - 'a' + 10 );
40 } else if ( charval >= 'A' ) {
41 charval = ( charval - 'A' + 10 );
42 } else if ( charval <= '9' ) {
43 charval = ( charval - '0' );
49 unsigned long strtoul ( const char *p, char **endp, int base ) {
50 unsigned long ret = 0;
54 while ( isspace ( *p ) )
62 base = strtoul_base ( &p, base );
65 charval = strtoul_charval ( *p );
66 if ( charval >= ( unsigned int ) base )
68 ret = ( ( ret * base ) + charval );