2 * $Id: asp_cmdreply.c,v 1.5 2009-10-13 22:55:37 didg Exp $
4 * Copyright (c) 1990,1991 Regents of The University of Michigan.
7 * Permission to use, copy, modify, and distribute this software and
8 * its documentation for any purpose and without fee is hereby granted,
9 * provided that the above copyright notice appears in all copies and
10 * that both that copyright notice and this permission notice appear
11 * in supporting documentation, and that the name of The University
12 * of Michigan not be used in advertising or publicity pertaining to
13 * distribution of the software without specific, written prior
14 * permission. This software is supplied as is without expressed or
15 * implied warranties of any kind.
17 * Research Systems Unix Group
18 * The University of Michigan
20 * 535 W. William Street
23 * netatalk@itd.umich.edu
28 #endif /* HAVE_CONFIG_H */
31 #include <sys/types.h>
33 #include <sys/socket.h>
35 #include <atalk/atp.h>
36 #include <atalk/asp.h>
38 #if defined(BSD) || defined(BSD4_3)
39 #define memmove(a, b, n) bcopy((b), (a), (n))
40 #endif /* BSD || BSD4_3 */
42 int asp_cmdreply(ASP asp, int result)
44 struct iovec iov[ ASP_MAXPACKETS ];
45 struct atp_block atpb;
49 /* unpack data into a format that atp likes. it needs to get
50 * 4-byte headers prepended before each ASP_CMDSIZ chunk. */
51 buf = (char *) asp->data;
52 buflen = asp->datalen;
53 asp->write_count += buflen;
54 result = htonl(result);
58 iov[ iovcnt ].iov_base = buf;
59 memmove(buf + ASP_HDRSIZ, buf, buflen);
62 memcpy( iov[ iovcnt ].iov_base, &result, ASP_HDRSIZ );
64 memset( iov[ iovcnt ].iov_base, 0, ASP_HDRSIZ );
67 if ( buflen > ASP_CMDSIZ ) {
70 iov[ iovcnt ].iov_len = ASP_CMDMAXSIZ;
72 iov[ iovcnt ].iov_len = buflen + ASP_HDRSIZ;
76 } while ( buflen > 0 );
78 atpb.atp_saddr = &asp->asp_sat;
79 atpb.atp_sresiov = iov;
80 atpb.atp_sresiovcnt = iovcnt;
81 if ( atp_sresp( asp->asp_atp, &atpb ) < 0 ) {