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