]> arthur.barton.de Git - netatalk.git/blob - libatalk/atp/atp_rresp.c
implemented config.h
[netatalk.git] / libatalk / atp / atp_rresp.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 <stdlib.h>
29 #include <string.h>
30 #include <sys/types.h>
31 #include <sys/time.h>
32 #include <errno.h>
33 #include <sys/uio.h>
34
35 #include <netatalk/at.h>
36 #include <atalk/atp.h>
37 #include <atalk/util.h>
38
39 #ifdef EBUG
40 #include <stdio.h>
41 #endif
42
43 #include "atp_internals.h"
44
45 int
46 atp_rresp( ah, atpb )
47     ATP                 ah;             /* open atp handle */
48     struct atp_block    *atpb;          /* parameter block */
49 {
50     int         len, i, rc;
51
52 #ifdef EBUG
53     atp_print_bufuse( ah, "atp_rresp" );
54 #endif
55     /* check parameters
56     */
57     if ( atpb->atp_rresiovcnt <= 0 || atpb->atp_rresiovcnt > 8 ) {
58         errno = EINVAL;
59         return( -1 );
60     }
61
62     while (( rc = atp_rsel( ah, atpb->atp_saddr, ATP_TRESP )) == 0 ) {
63         ;
64     }
65
66     if ( rc != ATP_TRESP ) {
67         return( rc );
68     }
69
70     for ( i = 0; i < 8; ++i ) {
71         if ( ah->atph_resppkt[ i ] == NULL ) {
72             break;
73         }
74         len = ah->atph_resppkt[ i ]->atpbuf_dlen - ATP_HDRSIZE;
75         if ( i > atpb->atp_rresiovcnt - 1 ||
76                 len > atpb->atp_rresiov[ i ].iov_len ) {
77             errno = EMSGSIZE;
78             return( -1 );
79         }
80 #ifdef EBUG
81         fprintf( stderr, "atp_rresp copying %d bytes packet %d\n",
82                 len, i );
83         bprint( (char *)ah->atph_resppkt[ i ]->atpbuf_info.atpbuf_data,
84                 len + ATP_HDRSIZE );
85 #endif
86         memcpy(atpb->atp_rresiov[ i ].iov_base,
87                ah->atph_resppkt[ i ]->atpbuf_info.atpbuf_data + ATP_HDRSIZE,
88                len );
89         atpb->atp_rresiov[ i ].iov_len = len;
90         atp_free_buf( ah->atph_resppkt[ i ] );
91         ah->atph_resppkt[ i ] = NULL;
92     }
93     atpb->atp_rresiovcnt = i;
94
95     return( 0 );
96 }