6 #include <netatalk/at.h>
7 #include <netatalk/endian.h>
8 #include <atalk/util.h>
12 * Check whether "cp" is a valid ascii representation
13 * of an AppleTalk address and convert to a binary address.
14 * Examples of accepted forms are (in decimal, net of 4321,
22 * If hex is used, and the first digit is one of A-F, the leading
23 * 0x is redundant. Returns 1 if the address is valid, 0 if not.
25 * Unlike Internet addresses, AppleTalk addresses can have leading
26 * 0's. This means that we can't support octal addressing.
29 int atalk_aton(char *cp, struct at_addr *addr)
31 u_int32_t val, base, n;
35 if ( *cp == '0' && ( *++cp == 'x' || *cp == 'X' )) {
38 if ( !isdigit( *cp ) && isxdigit( *cp )) {
43 while (( c = *cp ) != '\0') {
44 if ( isascii( c ) && isdigit( c )) {
45 val = (val * base) + (c - '0');
50 if ( base == 16 && isascii( c ) && isxdigit( c )) {
51 val = ( val << 4 ) + ( c + 10 - ( islower( c ) ? 'a' : 'A' ));
58 if ( c != '.' && c != '\0' ) {
79 if ( addr->s_net > 255 ) {
83 addr->s_net += addr->s_node;
111 addr->s_net = htons( addr->s_net );