2 * $Id: nbp_unrgstr.c,v 1.6 2009-10-14 02:24:05 didg 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(const char *obj,const char *type,const char *zone, 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, NULL, NULL, &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 ) {