2 * $Id: atp_rreq.c,v 1.3 2001-06-29 14:14:46 rufustfirefly Exp $
4 * Copyright (c) 1990,1991 Regents of The University of Michigan.
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.
17 * Research Systems Unix Group
18 * The University of Michigan
20 * 535 W. William Street
23 * netatalk@itd.umich.edu
28 #endif /* HAVE_CONFIG_H */
32 #include <sys/types.h>
36 #include <netinet/in.h>
37 #include <netatalk/at.h>
38 #include <netatalk/endian.h>
39 #include <atalk/atp.h>
41 #include "atp_internals.h"
44 /* wait for a tranasaction service request
46 int atp_rreq( ah, atpb )
47 ATP ah; /* open atp handle */
48 struct atp_block *atpb; /* parameter block */
50 struct atpbuf *req_buf; /* for receiving request packet */
51 struct atphdr req_hdr; /* request header overlay */
52 struct sockaddr_at faddr; /* sender's address */
53 int recvlen; /* length of received packet */
59 atp_print_bufuse( ah, "atp_rreq" );
62 while (( rc = atp_rsel( ah, atpb->atp_saddr, ATP_TREQ )) == 0 ) {
66 if ( rc != ATP_TREQ ) {
68 printf( "<%d> atp_rreq: atp_rsel returns err %d\n", getpid(), rc );
73 /* allocate a buffer for receiving request
75 if (( req_buf = atp_alloc_buf()) == NULL ) {
79 memcpy( &faddr, atpb->atp_saddr, sizeof( struct sockaddr_at ));
81 if (( recvlen = atp_recv_atp( ah, &faddr, &func, ATP_TIDANY,
82 req_buf->atpbuf_info.atpbuf_data, 1 )) < 0 ) {
83 atp_free_buf( req_buf );
87 memcpy( &req_hdr, req_buf->atpbuf_info.atpbuf_data + 1,
88 sizeof( struct atphdr ));
89 tid = ntohs( req_hdr.atphd_tid );
92 if (( ah->atph_rxo = req_hdr.atphd_ctrlinfo & ATP_XO ) != 0 ) {
93 ah->atph_rreltime = ATP_RELTIME *
94 ( 1 << ( req_hdr.atphd_ctrlinfo & ATP_TRELMASK ));
97 memcpy( atpb->atp_saddr, &faddr, sizeof( struct sockaddr_at ));
99 if ( recvlen - ATP_HDRSIZE > atpb->atp_rreqdlen ) {
100 atp_free_buf( req_buf );
105 atpb->atp_rreqdlen = recvlen - ATP_HDRSIZE;
106 memcpy( atpb->atp_rreqdata,
107 req_buf->atpbuf_info.atpbuf_data + ATP_HDRSIZE,
108 recvlen - ATP_HDRSIZE );
109 atpb->atp_bitmap = req_hdr.atphd_bitmap;
110 atp_free_buf( req_buf );