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
26 #include <sys/types.h>
30 #include <netinet/in.h>
31 #include <netatalk/at.h>
32 #include <netatalk/endian.h>
33 #include <atalk/atp.h>
35 #include "atp_internals.h"
38 /* wait for a tranasaction service request
40 int atp_rreq( ah, atpb )
41 ATP ah; /* open atp handle */
42 struct atp_block *atpb; /* parameter block */
44 struct atpbuf *req_buf; /* for receiving request packet */
45 struct atphdr req_hdr; /* request header overlay */
46 struct sockaddr_at faddr; /* sender's address */
47 int recvlen; /* length of received packet */
53 atp_print_bufuse( ah, "atp_rreq" );
56 while (( rc = atp_rsel( ah, atpb->atp_saddr, ATP_TREQ )) == 0 ) {
60 if ( rc != ATP_TREQ ) {
62 printf( "<%d> atp_rreq: atp_rsel returns err %d\n", getpid(), rc );
67 /* allocate a buffer for receiving request
69 if (( req_buf = atp_alloc_buf()) == NULL ) {
73 memcpy( &faddr, atpb->atp_saddr, sizeof( struct sockaddr_at ));
75 if (( recvlen = atp_recv_atp( ah, &faddr, &func, ATP_TIDANY,
76 req_buf->atpbuf_info.atpbuf_data, 1 )) < 0 ) {
77 atp_free_buf( req_buf );
81 memcpy( &req_hdr, req_buf->atpbuf_info.atpbuf_data + 1,
82 sizeof( struct atphdr ));
83 tid = ntohs( req_hdr.atphd_tid );
86 if (( ah->atph_rxo = req_hdr.atphd_ctrlinfo & ATP_XO ) != 0 ) {
87 ah->atph_rreltime = ATP_RELTIME *
88 ( 1 << ( req_hdr.atphd_ctrlinfo & ATP_TRELMASK ));
91 memcpy( atpb->atp_saddr, &faddr, sizeof( struct sockaddr_at ));
93 if ( recvlen - ATP_HDRSIZE > atpb->atp_rreqdlen ) {
94 atp_free_buf( req_buf );
99 atpb->atp_rreqdlen = recvlen - ATP_HDRSIZE;
100 memcpy( atpb->atp_rreqdata,
101 req_buf->atpbuf_info.atpbuf_data + ATP_HDRSIZE,
102 recvlen - ATP_HDRSIZE );
103 atpb->atp_bitmap = req_hdr.atphd_bitmap;
104 atp_free_buf( req_buf );