2 * $Id: nbp_util.c,v 1.3 2001-06-29 14:14:46 rufustfirefly Exp $
4 * Copyright (c) 1990,1997 Regents of The University of Michigan.
5 * All Rights Reserved. See COPYRIGHT.
10 #endif /* HAVE_CONFIG_H */
15 #endif /* HAVE_NETDB_H */
16 #include <sys/types.h>
17 #include <sys/param.h>
18 #include <sys/socket.h>
19 #include <sys/signal.h>
22 #include <netatalk/endian.h>
23 #include <netatalk/at.h>
25 #include <atalk/nbp.h>
26 #include <atalk/ddp.h>
27 #include <atalk/util.h>
31 char nbp_send[ 1024 ];
32 char nbp_recv[ 1024 ];
34 unsigned char nbp_id = 0;
36 int nbp_parse( data, nn, len )
43 memcpy( &nt, data, SZ_NBPTUPLE);
51 nn->nn_sat.sat_len = sizeof( struct sockaddr_at );
53 nn->nn_sat.sat_family = AF_APPLETALK;
54 nn->nn_sat.sat_addr.s_net = nt.nt_net;
55 nn->nn_sat.sat_addr.s_node = nt.nt_node;
56 nn->nn_sat.sat_port = nt.nt_port;
58 nn->nn_objlen = *data++;
59 len -= nn->nn_objlen + 1;
63 if ( nn->nn_objlen > NBPSTRLEN ) {
66 memcpy( nn->nn_obj, data, nn->nn_objlen );
67 data += nn->nn_objlen;
69 nn->nn_typelen = *data++;
70 len -= nn->nn_typelen + 1;
74 if ( nn->nn_typelen > NBPSTRLEN ) {
77 memcpy( nn->nn_type, data, nn->nn_typelen );
79 data += nn->nn_typelen;
80 nn->nn_zonelen = *data++;
81 len -= nn->nn_zonelen + 1;
85 if ( nn->nn_zonelen > NBPSTRLEN ) {
88 memcpy( nn->nn_zone, data, nn->nn_zonelen );
93 #define NBPM_OBJ (1<<1)
94 #define NBPM_TYPE (1<<2)
95 #define NBPM_ZONE (1<<3)
97 int nbp_match( n1, n2, flags )
98 struct nbpnve *n1, *n2;
103 if ( flags & NBPMATCH_NOZONE ) {
107 if ( !( flags & NBPMATCH_NOGLOB )) {
108 if ( n1->nn_objlen == 1 && n1->nn_obj[0] == '=' ) {
111 if ( n1->nn_typelen == 1 && n1->nn_type[0] == '=' ) {
116 if ( !( match & NBPM_OBJ )) {
117 if ( n1->nn_objlen != n2->nn_objlen ||
118 strndiacasecmp( n1->nn_obj, n2->nn_obj, n1->nn_objlen )) {
122 if ( !( match & NBPM_TYPE )) {
123 if ( n1->nn_typelen != n2->nn_typelen ||
124 strndiacasecmp( n1->nn_type, n2->nn_type, n1->nn_typelen )) {
128 if ( !( match & NBPM_ZONE )) {
129 if ( n1->nn_zonelen != n2->nn_zonelen ||
130 strndiacasecmp( n1->nn_zone, n2->nn_zone, n1->nn_zonelen )) {
138 int nbp_name( name, objp, typep, zonep )
140 char **objp, **typep, **zonep;
142 static char buf[ 32 + 1 + 32 + 1 + 32 + 1 ];
146 if ( strlen( name ) + 1 > sizeof( buf )) {
151 if (( p = strrchr( buf, '@' )) != NULL ) {
155 if (( p = strrchr( buf, ':' )) != NULL ) {
159 if ( *buf != '\0' ) {