2 * $Id: nbp_util.c,v 1.5 2009-10-13 22:55:37 didg Exp $
4 * Copyright (c) 1990,1997 Regents of The University of Michigan.
5 * All Rights Reserved. See COPYRIGHT.
10 #endif /* HAVE_CONFIG_H */
15 #include <sys/types.h>
16 #include <sys/param.h>
17 #include <sys/socket.h>
20 #include <netatalk/endian.h>
21 #include <netatalk/at.h>
23 #include <atalk/nbp.h>
24 #include <atalk/ddp.h>
25 #include <atalk/util.h>
29 #endif /* HAVE_NETDB_H */
33 char nbp_send[ 1024 ];
34 char nbp_recv[ 1024 ];
36 unsigned char nbp_id = 0;
38 int nbp_parse(char *data, struct nbpnve *nn, int len)
42 memcpy( &nt, data, SZ_NBPTUPLE);
50 nn->nn_sat.sat_len = sizeof( struct sockaddr_at );
52 nn->nn_sat.sat_family = AF_APPLETALK;
53 nn->nn_sat.sat_addr.s_net = nt.nt_net;
54 nn->nn_sat.sat_addr.s_node = nt.nt_node;
55 nn->nn_sat.sat_port = nt.nt_port;
57 nn->nn_objlen = *data++;
58 len -= nn->nn_objlen + 1;
62 if ( nn->nn_objlen > NBPSTRLEN ) {
65 memcpy( nn->nn_obj, data, nn->nn_objlen );
66 data += nn->nn_objlen;
68 nn->nn_typelen = *data++;
69 len -= nn->nn_typelen + 1;
73 if ( nn->nn_typelen > NBPSTRLEN ) {
76 memcpy( nn->nn_type, data, nn->nn_typelen );
78 data += nn->nn_typelen;
79 nn->nn_zonelen = *data++;
80 len -= nn->nn_zonelen + 1;
84 if ( nn->nn_zonelen > NBPSTRLEN ) {
87 memcpy( nn->nn_zone, data, nn->nn_zonelen );
92 #define NBPM_OBJ (1<<1)
93 #define NBPM_TYPE (1<<2)
94 #define NBPM_ZONE (1<<3)
96 int nbp_match(struct nbpnve *n1, struct nbpnve *n2, int flags)
100 if ( flags & NBPMATCH_NOZONE ) {
104 if ( !( flags & NBPMATCH_NOGLOB )) {
105 if ( n1->nn_objlen == 1 && n1->nn_obj[0] == '=' ) {
108 if ( n1->nn_typelen == 1 && n1->nn_type[0] == '=' ) {
113 if ( !( match & NBPM_OBJ )) {
114 if ( n1->nn_objlen != n2->nn_objlen ||
115 strndiacasecmp( n1->nn_obj, n2->nn_obj, n1->nn_objlen )) {
119 if ( !( match & NBPM_TYPE )) {
120 if ( n1->nn_typelen != n2->nn_typelen ||
121 strndiacasecmp( n1->nn_type, n2->nn_type, n1->nn_typelen )) {
125 if ( !( match & NBPM_ZONE )) {
126 if ( n1->nn_zonelen != n2->nn_zonelen ||
127 strndiacasecmp( n1->nn_zone, n2->nn_zone, n1->nn_zonelen )) {
135 int nbp_name(const char *name, char **objp,char **typep,char **zonep)
137 static char buf[ 32 + 1 + 32 + 1 + 32 + 1 ];
141 if ( strlen( name ) + 1 > sizeof( buf )) {
146 if (( p = strrchr( buf, '@' )) != NULL ) {
150 if (( p = strrchr( buf, ':' )) != NULL ) {
154 if ( *buf != '\0' ) {