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