8 #include <netatalk/at.h>
9 #include <netatalk/endian.h>
10 #include <atalk/util.h>
14 * Check whether "cp" is a valid ascii representation
15 * of an AppleTalk address and convert to a binary address.
16 * Examples of accepted forms are (in decimal, net of 4321,
24 * If hex is used, and the first digit is one of A-F, the leading
25 * 0x is redundant. Returns 1 if the address is valid, 0 if not.
27 * Unlike Internet addresses, AppleTalk addresses can have leading
28 * 0's. This means that we can't support octal addressing.
31 int atalk_aton(char *cp, struct at_addr *addr)
33 u_int32_t val, base, n;
37 if ( *cp == '0' && ( *++cp == 'x' || *cp == 'X' )) {
40 if ( !isdigit( *cp ) && isxdigit( *cp )) {
45 while (( c = *cp ) != '\0') {
46 if ( isascii( c ) && isdigit( c )) {
47 val = (val * base) + (c - '0');
52 if ( base == 16 && isascii( c ) && isxdigit( c )) {
53 val = ( val << 4 ) + ( c + 10 - ( islower( c ) ? 'a' : 'A' ));
60 if ( c != '.' && c != '\0' ) {
81 if ( addr->s_net > 255 ) {
85 addr->s_net += addr->s_node;
113 addr->s_net = htons( addr->s_net );