2 * $Id: nbp_unrgstr.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 */
13 #include <sys/types.h>
14 #include <sys/param.h>
15 #include <sys/socket.h>
16 #include <sys/signal.h>
19 #include <netatalk/endian.h>
20 #include <netatalk/at.h>
21 #include <atalk/nbp.h>
22 #include <atalk/netddp.h>
23 #include <atalk/ddp.h>
27 #endif /* HAVE_NETDB_H */
30 /* FIXME/SOCKLEN_T: socklen_t is a unix98 feature. */
32 #define SOCKLEN_T unsigned int
33 #endif /* ! SOCKLEN_T */
35 int nbp_unrgstr( obj, type, zone, addr )
36 const char *obj, *type, *zone;
37 const struct at_addr *addr;
39 struct sockaddr_at to;
41 struct timeval timeout;
49 memset(&to, 0, sizeof(to));
50 if ((s = netddp_open(&to, NULL)) < 0)
54 *data++ = DDPTYPE_NBP;
55 nh.nh_op = NBPOP_UNRGSTR;
58 memcpy( data, &nh, SZ_NBPHDR );
61 memset(data, 0, SZ_NBPTUPLE);
65 if (( cc = strlen( obj )) > NBPSTRLEN ) return( -1 );
67 memcpy( data, obj, cc );
74 if (( cc = strlen( type )) > NBPSTRLEN ) return( -1 );
76 memcpy( data, type, cc );
83 if (( cc = strlen( zone )) > NBPSTRLEN ) return( -1 );
85 memcpy( data, zone, cc );
91 memset( &to, 0, sizeof( struct sockaddr_at ));
92 to.sat_family = AF_APPLETALK;
94 memcpy(&to.sat_addr, addr, sizeof(struct at_addr));
96 to.sat_len = sizeof( struct sockaddr_at );
99 if ( nbp_port == 0 ) {
100 if (( se = getservbyname( "nbp", "ddp" )) == NULL ) {
103 nbp_port = ntohs( se->s_port );
106 to.sat_port = nbp_port;
108 if ( netddp_sendto( s, nbp_send, data - nbp_send, 0,
109 (struct sockaddr *)&to,
110 sizeof( struct sockaddr_at )) < 0 ) {
115 FD_SET( s, &readfd );
118 if (( cc = select( s + 1, &readfd, 0, 0, &timeout )) < 0 ) {
126 namelen = sizeof( struct sockaddr_at );
127 if (( cc = netddp_recvfrom( s, nbp_recv, sizeof( nbp_recv ), 0,
128 (struct sockaddr *)&to, &namelen )) < 0 ) {
134 if ( *data++ != DDPTYPE_NBP ) {
137 memcpy( &nh, data, SZ_NBPHDR );
138 if ( nh.nh_op != NBPOP_OK ) {