2 * Copyright (c) 1990,1997 Regents of The University of Michigan.
3 * All Rights Reserved. See COPYRIGHT.
9 #include <sys/socket.h>
10 #include <sys/signal.h>
13 #include <netatalk/endian.h>
14 #include <netatalk/at.h>
15 #include <atalk/nbp.h>
16 #include <atalk/netddp.h>
17 #include <atalk/ddp.h>
22 /* FIXME/SOCKLEN_T: socklen_t is a unix98 feature. */
24 #define SOCKLEN_T unsigned int
27 int nbp_unrgstr( obj, type, zone, addr )
28 const char *obj, *type, *zone;
29 const struct at_addr *addr;
31 struct sockaddr_at to;
33 struct timeval timeout;
41 memset(&to, 0, sizeof(to));
42 if ((s = netddp_open(&to, NULL)) < 0)
46 *data++ = DDPTYPE_NBP;
47 nh.nh_op = NBPOP_UNRGSTR;
50 memcpy( data, &nh, SZ_NBPHDR );
53 memset(data, 0, SZ_NBPTUPLE);
57 if (( cc = strlen( obj )) > NBPSTRLEN ) return( -1 );
59 memcpy( data, obj, cc );
66 if (( cc = strlen( type )) > NBPSTRLEN ) return( -1 );
68 memcpy( data, type, cc );
75 if (( cc = strlen( zone )) > NBPSTRLEN ) return( -1 );
77 memcpy( data, zone, cc );
83 memset( &to, 0, sizeof( struct sockaddr_at ));
84 to.sat_family = AF_APPLETALK;
86 memcpy(&to.sat_addr, addr, sizeof(struct at_addr));
88 to.sat_len = sizeof( struct sockaddr_at );
91 if ( nbp_port == 0 ) {
92 if (( se = getservbyname( "nbp", "ddp" )) == NULL ) {
95 nbp_port = ntohs( se->s_port );
98 to.sat_port = nbp_port;
100 if ( netddp_sendto( s, nbp_send, data - nbp_send, 0,
101 (struct sockaddr *)&to,
102 sizeof( struct sockaddr_at )) < 0 ) {
107 FD_SET( s, &readfd );
110 if (( cc = select( s + 1, &readfd, 0, 0, &timeout )) < 0 ) {
118 namelen = sizeof( struct sockaddr_at );
119 if (( cc = netddp_recvfrom( s, nbp_recv, sizeof( nbp_recv ), 0,
120 (struct sockaddr *)&to, &namelen )) < 0 ) {
126 if ( *data++ != DDPTYPE_NBP ) {
129 memcpy( &nh, data, SZ_NBPHDR );
130 if ( nh.nh_op != NBPOP_OK ) {