2 * Copyright (c) 1990,1991 Regents of The University of Michigan.
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.
15 * Research Systems Unix Group
16 * The University of Michigan
18 * 535 W. William Street
21 * netatalk@itd.umich.edu
30 #include <sys/types.h>
34 #include <netinet/in.h>
35 #include <netatalk/at.h>
36 #include <netatalk/endian.h>
37 #include <atalk/atp.h>
39 #include "atp_internals.h"
42 /* wait for a tranasaction service request
44 int atp_rreq( ah, atpb )
45 ATP ah; /* open atp handle */
46 struct atp_block *atpb; /* parameter block */
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 */
57 atp_print_bufuse( ah, "atp_rreq" );
60 while (( rc = atp_rsel( ah, atpb->atp_saddr, ATP_TREQ )) == 0 ) {
64 if ( rc != ATP_TREQ ) {
66 printf( "<%d> atp_rreq: atp_rsel returns err %d\n", getpid(), rc );
71 /* allocate a buffer for receiving request
73 if (( req_buf = atp_alloc_buf()) == NULL ) {
77 memcpy( &faddr, atpb->atp_saddr, sizeof( struct sockaddr_at ));
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 );
85 memcpy( &req_hdr, req_buf->atpbuf_info.atpbuf_data + 1,
86 sizeof( struct atphdr ));
87 tid = ntohs( req_hdr.atphd_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 ));
95 memcpy( atpb->atp_saddr, &faddr, sizeof( struct sockaddr_at ));
97 if ( recvlen - ATP_HDRSIZE > atpb->atp_rreqdlen ) {
98 atp_free_buf( req_buf );
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 );