2 * Copyright (c) 1990,1997 Regents of The University of Michigan.
3 * All Rights Reserved. See COPYRIGHT.
11 #include <sys/types.h>
12 #include <sys/param.h>
13 #include <sys/socket.h>
14 #include <sys/signal.h>
17 #include <netatalk/endian.h>
18 #include <netatalk/at.h>
19 #include <atalk/nbp.h>
20 #include <atalk/netddp.h>
21 #include <atalk/ddp.h>
26 /* FIXME/SOCKLEN_T: socklen_t is a unix98 feature. */
28 #define SOCKLEN_T unsigned int
31 int nbp_unrgstr( obj, type, zone, addr )
32 const char *obj, *type, *zone;
33 const struct at_addr *addr;
35 struct sockaddr_at to;
37 struct timeval timeout;
45 memset(&to, 0, sizeof(to));
46 if ((s = netddp_open(&to, NULL)) < 0)
50 *data++ = DDPTYPE_NBP;
51 nh.nh_op = NBPOP_UNRGSTR;
54 memcpy( data, &nh, SZ_NBPHDR );
57 memset(data, 0, SZ_NBPTUPLE);
61 if (( cc = strlen( obj )) > NBPSTRLEN ) return( -1 );
63 memcpy( data, obj, cc );
70 if (( cc = strlen( type )) > NBPSTRLEN ) return( -1 );
72 memcpy( data, type, cc );
79 if (( cc = strlen( zone )) > NBPSTRLEN ) return( -1 );
81 memcpy( data, zone, cc );
87 memset( &to, 0, sizeof( struct sockaddr_at ));
88 to.sat_family = AF_APPLETALK;
90 memcpy(&to.sat_addr, addr, sizeof(struct at_addr));
92 to.sat_len = sizeof( struct sockaddr_at );
95 if ( nbp_port == 0 ) {
96 if (( se = getservbyname( "nbp", "ddp" )) == NULL ) {
99 nbp_port = ntohs( se->s_port );
102 to.sat_port = nbp_port;
104 if ( netddp_sendto( s, nbp_send, data - nbp_send, 0,
105 (struct sockaddr *)&to,
106 sizeof( struct sockaddr_at )) < 0 ) {
111 FD_SET( s, &readfd );
114 if (( cc = select( s + 1, &readfd, 0, 0, &timeout )) < 0 ) {
122 namelen = sizeof( struct sockaddr_at );
123 if (( cc = netddp_recvfrom( s, nbp_recv, sizeof( nbp_recv ), 0,
124 (struct sockaddr *)&to, &namelen )) < 0 ) {
130 if ( *data++ != DDPTYPE_NBP ) {
133 memcpy( &nh, data, SZ_NBPHDR );
134 if ( nh.nh_op != NBPOP_OK ) {