2 #include <netatalk/at.h>
3 #include <netatalk/endian.h>
4 #include <atalk/util.h>
8 * Check whether "cp" is a valid ascii representation
9 * of an AppleTalk address and convert to a binary address.
10 * Examples of accepted forms are (in decimal, net of 4321,
18 * If hex is used, and the first digit is one of A-F, the leading
19 * 0x is redundant. Returns 1 if the address is valid, 0 if not.
21 * Unlike Internet addresses, AppleTalk addresses can have leading
22 * 0's. This means that we can't support octal addressing.
25 int atalk_aton( cp, addr )
29 u_int32_t val, base, n;
33 if ( *cp == '0' && ( *++cp == 'x' || *cp == 'X' )) {
36 if ( !isdigit( *cp ) && isxdigit( *cp )) {
41 while (( c = *cp ) != '\0') {
42 if ( isascii( c ) && isdigit( c )) {
43 val = (val * base) + (c - '0');
48 if ( base == 16 && isascii( c ) && isxdigit( c )) {
49 val = ( val << 4 ) + ( c + 10 - ( islower( c ) ? 'a' : 'A' ));
56 if ( c != '.' && c != '\0' ) {
77 if ( addr->s_net > 255 ) {
81 addr->s_net += addr->s_node;
109 addr->s_net = htons( addr->s_net );