~ubuntu-branches/ubuntu/precise/netatalk/precise

« back to all changes in this revision

Viewing changes to libatalk/asp/asp_cmdreply.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Rittau
  • Date: 2004-01-19 12:43:49 UTC
  • Revision ID: james.westby@ubuntu.com-20040119124349-es563jbp0hk0ae51
Tags: upstream-1.6.4
ImportĀ upstreamĀ versionĀ 1.6.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Id: asp_cmdreply.c,v 1.4 2001/06/29 14:14:46 rufustfirefly Exp $
 
3
 *
 
4
 * Copyright (c) 1990,1991 Regents of The University of Michigan.
 
5
 * All Rights Reserved.
 
6
 *
 
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.
 
16
 *
 
17
 *      Research Systems Unix Group
 
18
 *      The University of Michigan
 
19
 *      c/o Mike Clark
 
20
 *      535 W. William Street
 
21
 *      Ann Arbor, Michigan
 
22
 *      +1-313-763-0525
 
23
 *      netatalk@itd.umich.edu
 
24
 */
 
25
 
 
26
#ifdef HAVE_CONFIG_H
 
27
#include "config.h"
 
28
#endif /* HAVE_CONFIG_H */
 
29
 
 
30
#include <string.h>
 
31
#include <sys/types.h>
 
32
#include <sys/uio.h>
 
33
#include <sys/socket.h>
 
34
 
 
35
#include <atalk/atp.h>
 
36
#include <atalk/asp.h>
 
37
 
 
38
#if defined(BSD) || defined(BSD4_3)
 
39
#define memmove(a, b, n)   bcopy((b), (a), (n))
 
40
#endif /* BSD || BSD4_3 */
 
41
 
 
42
int asp_cmdreply( asp, result)
 
43
    ASP         asp;
 
44
    int         result;
 
45
{
 
46
    struct iovec        iov[ ASP_MAXPACKETS ];
 
47
    struct atp_block    atpb;
 
48
    int                 iovcnt, buflen;
 
49
    char                *buf;
 
50
 
 
51
    /* unpack data into a format that atp likes. it needs to get
 
52
     * 4-byte headers prepended before each ASP_CMDSIZ chunk. */
 
53
    buf = (char *) asp->data;
 
54
    buflen = asp->datalen;
 
55
    asp->write_count += buflen;
 
56
    result = htonl(result);
 
57
 
 
58
    iovcnt = 0;
 
59
    do {
 
60
        iov[ iovcnt ].iov_base = buf;
 
61
        memmove(buf + ASP_HDRSIZ, buf, buflen);
 
62
 
 
63
        if ( iovcnt == 0 ) {
 
64
            memcpy( iov[ iovcnt ].iov_base, &result, ASP_HDRSIZ );
 
65
        } else {
 
66
            memset( iov[ iovcnt ].iov_base, 0, ASP_HDRSIZ );
 
67
        }
 
68
 
 
69
        if ( buflen > ASP_CMDSIZ ) {
 
70
          buf += ASP_CMDMAXSIZ;
 
71
          buflen -= ASP_CMDSIZ;
 
72
          iov[ iovcnt ].iov_len = ASP_CMDMAXSIZ;
 
73
        } else {
 
74
          iov[ iovcnt ].iov_len = buflen + ASP_HDRSIZ;
 
75
          buflen = 0;
 
76
        }
 
77
        iovcnt++;
 
78
    } while ( buflen > 0 );
 
79
 
 
80
    atpb.atp_saddr = &asp->asp_sat;
 
81
    atpb.atp_sresiov = iov;
 
82
    atpb.atp_sresiovcnt = iovcnt;
 
83
    if ( atp_sresp( asp->asp_atp, &atpb ) < 0 ) {
 
84
        return( -1 );
 
85
    }
 
86
    asp->asp_seq++;
 
87
 
 
88
    return( 0 );
 
89
}