]> arthur.barton.de Git - netatalk.git/blob - libatalk/atp/atp_rreq.c
implemented config.h
[netatalk.git] / libatalk / atp / atp_rreq.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
34 #include <netinet/in.h>
35 #include <netatalk/at.h>
36 #include <netatalk/endian.h>
37 #include <atalk/atp.h>
38
39 #include "atp_internals.h"
40
41
42 /* wait for a tranasaction service request
43 */
44 int atp_rreq( ah, atpb )
45     ATP                 ah;             /* open atp handle */
46     struct atp_block    *atpb;          /* parameter block */
47 {
48     struct atpbuf       *req_buf;       /* for receiving request packet */
49     struct atphdr       req_hdr;        /* request header overlay */
50     struct sockaddr_at  faddr;          /* sender's address */
51     int                 recvlen;        /* length of received packet */
52     u_int16_t           tid;
53     int                 rc;
54     u_int8_t            func;
55
56 #ifdef EBUG
57     atp_print_bufuse( ah, "atp_rreq" );
58 #endif
59
60     while (( rc = atp_rsel( ah, atpb->atp_saddr, ATP_TREQ )) == 0 ) {
61         ;
62     }
63
64     if ( rc != ATP_TREQ ) {
65 #ifdef EBUG
66         printf( "<%d> atp_rreq: atp_rsel returns err %d\n", getpid(), rc );
67 #endif EBUG
68         return( rc );
69     }
70
71     /* allocate a buffer for receiving request
72     */
73     if (( req_buf = atp_alloc_buf()) == NULL ) {
74         return -1;
75     }
76
77     memcpy( &faddr, atpb->atp_saddr, sizeof( struct sockaddr_at ));
78     func = ATP_TREQ;
79     if (( recvlen = atp_recv_atp( ah, &faddr, &func, ATP_TIDANY,
80           req_buf->atpbuf_info.atpbuf_data, 1 )) < 0 ) {
81         atp_free_buf( req_buf );
82         return -1;
83     }
84
85     memcpy( &req_hdr, req_buf->atpbuf_info.atpbuf_data + 1, 
86             sizeof( struct atphdr ));
87     tid = ntohs( req_hdr.atphd_tid );
88
89     ah->atph_rtid = tid;
90     if (( ah->atph_rxo = req_hdr.atphd_ctrlinfo & ATP_XO ) != 0 ) {
91         ah->atph_rreltime = ATP_RELTIME *
92                 ( 1 << ( req_hdr.atphd_ctrlinfo & ATP_TRELMASK ));
93     }
94
95     memcpy( atpb->atp_saddr, &faddr, sizeof( struct sockaddr_at ));
96
97     if ( recvlen - ATP_HDRSIZE > atpb->atp_rreqdlen ) {
98         atp_free_buf( req_buf );
99         errno = EMSGSIZE;
100         return -1;
101     }
102
103     atpb->atp_rreqdlen = recvlen - ATP_HDRSIZE;
104     memcpy( atpb->atp_rreqdata, 
105             req_buf->atpbuf_info.atpbuf_data + ATP_HDRSIZE,
106             recvlen - ATP_HDRSIZE );
107     atpb->atp_bitmap = req_hdr.atphd_bitmap;
108     atp_free_buf( req_buf );
109     return( 0 );
110 }