1 /**************************************************************************
3 **************************************************************************/
5 FILE_LICENCE ( GPL2_OR_LATER
);
11 #include <gpxe/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 long strtoul ( const char *p
, char **endp
, int base
) {
37 unsigned long ret
= 0;
40 while ( isspace ( *p
) )
48 if ( ( *p
| 0x20 ) == 'x' ) {
57 if ( charval
>= 'a' ) {
58 charval
= ( charval
- 'a' + 10 );
59 } else if ( charval
>= 'A' ) {
60 charval
= ( charval
- 'A' + 10 );
61 } else if ( charval
<= '9' ) {
62 charval
= ( charval
- '0' );
64 if ( charval
>= ( unsigned int ) base
)
66 ret
= ( ( ret
* base
) + charval
);