]> arthur.barton.de Git - netatalk.git/blob - libatalk/asp/asp_getreq.c
implemented config.h
[netatalk.git] / libatalk / asp / asp_getreq.c
1 /*
2  * Copyright (c) 1990,1991 Regents of The University of Michigan.
3  * All Rights Reserved.
4  *
5  * Permission to use, copy, modify, and distribute this software and
6  * its documentation for any purpose and without fee is hereby granted,
7  * provided that the above copyright notice appears in all copies and
8  * that both that copyright notice and this permission notice appear
9  * in supporting documentation, and that the name of The University
10  * of Michigan not be used in advertising or publicity pertaining to
11  * distribution of the software without specific, written prior
12  * permission. This software is supplied as is without expressed or
13  * implied warranties of any kind.
14  *
15  *      Research Systems Unix Group
16  *      The University of Michigan
17  *      c/o Mike Clark
18  *      535 W. William Street
19  *      Ann Arbor, Michigan
20  *      +1-313-763-0525
21  *      netatalk@itd.umich.edu
22  *
23  */
24
25 #ifdef HAVE_CONFIG_H
26 #include "config.h"
27 #endif
28
29 #include <string.h>
30 #include <sys/types.h>
31 #include <sys/time.h>
32 #include <sys/uio.h>
33 #include <netatalk/endian.h>
34 #include <netatalk/at.h>
35 #include <atalk/atp.h>
36 #include <atalk/asp.h>
37
38 int asp_getrequest(ASP asp)
39 {
40     struct atp_block    atpb;
41     u_int16_t           seq;
42
43     asp->asp_sat.sat_port = ATADDR_ANYPORT;
44     atpb.atp_saddr = &asp->asp_sat;
45     atpb.atp_rreqdata = asp->cmdbuf;
46     atpb.atp_rreqdlen = sizeof(asp->cmdbuf);
47
48     if ( atp_rreq( asp->asp_atp, &atpb ) < 0 ) {
49         return( -1 );
50     }
51
52     asp->cmdlen = atpb.atp_rreqdlen - 4;
53     asp->read_count += asp->cmdlen;
54     memcpy( &seq, asp->cmdbuf + 2, sizeof(seq));
55     seq = ntohs( seq );
56
57     if ((asp->cmdbuf[0] != ASPFUNC_CLOSE) && (seq != asp->asp_seq)) {
58         return( -2 );
59     }
60     if ( asp->cmdbuf[1] != asp->asp_sid ) {
61         return( -3 );
62     }
63
64     return( asp->cmdbuf[0] ); /* the command */
65 }