2 * $Id: nbp_util.c,v 1.3.2.1 2002-02-08 00:04:49 srittau 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( data, nn, len )
45 memcpy( &nt, data, SZ_NBPTUPLE);
53 nn->nn_sat.sat_len = sizeof( struct sockaddr_at );
55 nn->nn_sat.sat_family = AF_APPLETALK;
56 nn->nn_sat.sat_addr.s_net = nt.nt_net;
57 nn->nn_sat.sat_addr.s_node = nt.nt_node;
58 nn->nn_sat.sat_port = nt.nt_port;
60 nn->nn_objlen = *data++;
61 len -= nn->nn_objlen + 1;
65 if ( nn->nn_objlen > NBPSTRLEN ) {
68 memcpy( nn->nn_obj, data, nn->nn_objlen );
69 data += nn->nn_objlen;
71 nn->nn_typelen = *data++;
72 len -= nn->nn_typelen + 1;
76 if ( nn->nn_typelen > NBPSTRLEN ) {
79 memcpy( nn->nn_type, data, nn->nn_typelen );
81 data += nn->nn_typelen;
82 nn->nn_zonelen = *data++;
83 len -= nn->nn_zonelen + 1;
87 if ( nn->nn_zonelen > NBPSTRLEN ) {
90 memcpy( nn->nn_zone, data, nn->nn_zonelen );
95 #define NBPM_OBJ (1<<1)
96 #define NBPM_TYPE (1<<2)
97 #define NBPM_ZONE (1<<3)
99 int nbp_match( n1, n2, flags )
100 struct nbpnve *n1, *n2;
105 if ( flags & NBPMATCH_NOZONE ) {
109 if ( !( flags & NBPMATCH_NOGLOB )) {
110 if ( n1->nn_objlen == 1 && n1->nn_obj[0] == '=' ) {
113 if ( n1->nn_typelen == 1 && n1->nn_type[0] == '=' ) {
118 if ( !( match & NBPM_OBJ )) {
119 if ( n1->nn_objlen != n2->nn_objlen ||
120 strndiacasecmp( n1->nn_obj, n2->nn_obj, n1->nn_objlen )) {
124 if ( !( match & NBPM_TYPE )) {
125 if ( n1->nn_typelen != n2->nn_typelen ||
126 strndiacasecmp( n1->nn_type, n2->nn_type, n1->nn_typelen )) {
130 if ( !( match & NBPM_ZONE )) {
131 if ( n1->nn_zonelen != n2->nn_zonelen ||
132 strndiacasecmp( n1->nn_zone, n2->nn_zone, n1->nn_zonelen )) {
140 int nbp_name( name, objp, typep, zonep )
142 char **objp, **typep, **zonep;
144 static char buf[ 32 + 1 + 32 + 1 + 32 + 1 ];
148 if ( strlen( name ) + 1 > sizeof( buf )) {
153 if (( p = strrchr( buf, '@' )) != NULL ) {
157 if (( p = strrchr( buf, ':' )) != NULL ) {
161 if ( *buf != '\0' ) {