2 * $Id: nbp_unrgstr.c,v 1.4 2002-01-17 06:12:02 srittau Exp $
4 * Copyright (c) 1990,1997 Regents of The University of Michigan.
5 * All Rights Reserved. See COPYRIGHT.
10 #endif /* HAVE_CONFIG_H */
16 #include <sys/types.h>
17 #include <sys/param.h>
18 #include <sys/socket.h>
21 #include <netatalk/endian.h>
22 #include <netatalk/at.h>
23 #include <atalk/nbp.h>
24 #include <atalk/netddp.h>
25 #include <atalk/ddp.h>
29 #endif /* HAVE_NETDB_H */
32 /* FIXME/SOCKLEN_T: socklen_t is a unix98 feature. */
34 #define SOCKLEN_T unsigned int
35 #endif /* ! SOCKLEN_T */
37 int nbp_unrgstr( obj, type, zone, addr )
38 const char *obj, *type, *zone;
39 const struct at_addr *addr;
41 struct sockaddr_at to;
43 struct timeval timeout;
51 memset(&to, 0, sizeof(to));
52 if ((s = netddp_open(&to, NULL)) < 0)
56 *data++ = DDPTYPE_NBP;
57 nh.nh_op = NBPOP_UNRGSTR;
60 memcpy( data, &nh, SZ_NBPHDR );
63 memset(data, 0, SZ_NBPTUPLE);
67 if (( cc = strlen( obj )) > NBPSTRLEN ) return( -1 );
69 memcpy( data, obj, cc );
76 if (( cc = strlen( type )) > NBPSTRLEN ) return( -1 );
78 memcpy( data, type, cc );
85 if (( cc = strlen( zone )) > NBPSTRLEN ) return( -1 );
87 memcpy( data, zone, cc );
93 memset( &to, 0, sizeof( struct sockaddr_at ));
94 to.sat_family = AF_APPLETALK;
96 memcpy(&to.sat_addr, addr, sizeof(struct at_addr));
98 to.sat_len = sizeof( struct sockaddr_at );
101 if ( nbp_port == 0 ) {
102 if (( se = getservbyname( "nbp", "ddp" )) == NULL ) {
105 nbp_port = ntohs( se->s_port );
108 to.sat_port = nbp_port;
110 if ( netddp_sendto( s, nbp_send, data - nbp_send, 0,
111 (struct sockaddr *)&to,
112 sizeof( struct sockaddr_at )) < 0 ) {
117 FD_SET( s, &readfd );
120 if (( cc = select( s + 1, &readfd, 0, 0, &timeout )) < 0 ) {
128 namelen = sizeof( struct sockaddr_at );
129 if (( cc = netddp_recvfrom( s, nbp_recv, sizeof( nbp_recv ), 0,
130 (struct sockaddr *)&to, &namelen )) < 0 ) {
136 if ( *data++ != DDPTYPE_NBP ) {
139 memcpy( &nh, data, SZ_NBPHDR );
140 if ( nh.nh_op != NBPOP_OK ) {