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