]> arthur.barton.de Git - netatalk.git/blob - libatalk/asp/asp_cmdreply.c
implemented config.h
[netatalk.git] / libatalk / asp / asp_cmdreply.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 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include <string.h>
29 #include <sys/types.h>
30 #include <sys/uio.h>
31 #include <atalk/atp.h>
32 #include <atalk/asp.h>
33
34 #if defined(BSD) || defined(BSD4_3)
35 #define memmove(a, b, n)   bcopy((b), (a), (n))
36 #endif
37
38 int asp_cmdreply( asp, result)
39     ASP         asp;
40     int         result;
41 {
42     struct iovec        iov[ ASP_MAXPACKETS ];
43     struct atp_block    atpb;
44     int                 iovcnt, buflen;
45     char                *buf;
46
47     /* unpack data into a format that atp likes. it needs to get
48      * 4-byte headers prepended before each ASP_CMDSIZ chunk. */
49     buf = (char *) asp->data;
50     buflen = asp->datalen;
51     asp->write_count += buflen;
52     result = htonl(result);
53
54     iovcnt = 0;
55     do {
56         iov[ iovcnt ].iov_base = buf;
57         memmove(buf + ASP_HDRSIZ, buf, buflen);
58
59         if ( iovcnt == 0 ) {
60             memcpy( iov[ iovcnt ].iov_base, &result, ASP_HDRSIZ );
61         } else {
62             memset( iov[ iovcnt ].iov_base, 0, ASP_HDRSIZ );
63         }
64
65         if ( buflen > ASP_CMDSIZ ) {
66           buf += ASP_CMDMAXSIZ;
67           buflen -= ASP_CMDSIZ;
68           iov[ iovcnt ].iov_len = ASP_CMDMAXSIZ;
69         } else {
70           iov[ iovcnt ].iov_len = buflen + ASP_HDRSIZ;
71           buflen = 0;
72         }
73         iovcnt++;
74     } while ( buflen > 0 );
75
76     atpb.atp_saddr = &asp->asp_sat;
77     atpb.atp_sresiov = iov;
78     atpb.atp_sresiovcnt = iovcnt;
79     if ( atp_sresp( asp->asp_atp, &atpb ) < 0 ) {
80         return( -1 );
81     }
82     asp->asp_seq++;
83
84     return( 0 );
85 }