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