1/* 2 * $Id: asp_shutdown.c,v 1.4 2009-10-13 22:55:37 didg Exp $ 3 * 4 * Copyright (c) 1996 Regents of The University of Michigan. 5 * All Rights Reserved. See COPYRIGHT. 6 */ 7 8#ifdef HAVE_CONFIG_H 9#include "config.h" 10#endif /* HAVE_CONFIG_H */ 11 12#include <string.h> 13#include <sys/types.h> 14#include <sys/time.h> 15#include <sys/uio.h> 16#include <netatalk/endian.h> 17#include <netatalk/at.h> 18#include <atalk/atp.h> 19#include <atalk/asp.h> 20 21int asp_shutdown(ASP asp) 22{ 23 struct atp_block atpb; 24 struct iovec iov; 25 char *p; 26 u_int16_t seq; 27 u_int8_t oport; 28 29 30 p = asp->commands; 31 *p++ = ASPFUNC_CLOSE; 32 *p++ = asp->asp_sid; 33 seq = 0; 34 memcpy( p, &seq, sizeof(seq)); 35 p += sizeof(seq); 36 37 oport = asp->asp_sat.sat_port; 38 atpb.atp_saddr = &asp->asp_sat; 39 atpb.atp_saddr->sat_port = asp->asp_wss; 40 atpb.atp_sreqdata = asp->commands; 41 atpb.atp_sreqdlen = p - asp->commands; 42 atpb.atp_sreqto = 2; 43 atpb.atp_sreqtries = 5; 44 45 if ( atp_sreq( asp->asp_atp, &atpb, 1, ATP_XO ) < 0 ) { 46 asp->asp_sat.sat_port = oport; 47 return( -1 ); 48 } 49 50 iov.iov_base = asp->commands; 51 iov.iov_len = ASP_CMDSIZ; 52 atpb.atp_rresiov = &iov; 53 atpb.atp_rresiovcnt = 1; 54 55 if ( atp_rresp( asp->asp_atp, &atpb ) < 0 ) { 56 asp->asp_sat.sat_port = oport; 57 return( -1 ); 58 } 59 asp->asp_sat.sat_port = oport; 60 61 return( 0 ); 62} 63