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>
31 #include <netatalk/at.h>
32 #include <netatalk/endian.h>
34 #include <atalk/netddp.h>
35 #include <atalk/atp.h>
36 #include <atalk/util.h>
38 #include "atp_internals.h"
40 /* send a transaction response
42 int atp_sresp( ah, atpb )
43 ATP ah; /* open atp handle */
44 struct atp_block *atpb; /* parameter block */
48 struct atpbuf *resp_buf;
49 struct atpbuf *save_buf;
52 atp_print_bufuse( ah, "atp_sresp" );
57 for ( i = atpb->atp_sresiovcnt - 1; i >= 0; --i ) {
58 if ( atpb->atp_sresiov[ i ].iov_len > ATP_MAXDATA )
61 if ( i >= 0 || atpb->atp_sresiovcnt < 1 || atpb->atp_sresiovcnt > 8 ) {
66 /* allocate a new buffer for reponse packet construction
68 if (( resp_buf = atp_alloc_buf()) == NULL ) {
72 /* send all the response packets
73 * also need to attach list to ah for dup. detection (if XO)
76 printf( "<%d> preparing to send %s response tid=%hu ", getpid(),
77 ah->atph_rxo ? "XO" : "", ah->atph_rtid );
78 atp_print_addr( " to", atpb->atp_saddr );
82 if (( save_buf = atp_alloc_buf()) == NULL ) {
86 save_buf->atpbuf_info.atpbuf_xo.atpxo_packet[ i++ ] = NULL );
88 for ( i = 0; i < atpb->atp_sresiovcnt; ++i ) {
93 if ( i == atpb->atp_sresiovcnt-1 ) {
96 atp_build_resp_packet( resp_buf, ah->atph_rtid, ctrlinfo, atpb, i );
99 save_buf->atpbuf_info.atpbuf_xo.atpxo_packet[i] = resp_buf;
102 if (( random() % 3 ) != 2 ) {
105 printf( "<%d> sending packet tid=%hu serial no.=%d\n", getpid(),
107 bprint( resp_buf->atpbuf_info.atpbuf_data, resp_buf->atpbuf_dlen );
109 if ( netddp_sendto( ah->atph_socket, resp_buf->atpbuf_info.atpbuf_data,
110 resp_buf->atpbuf_dlen, 0, (struct sockaddr *) atpb->atp_saddr,
111 sizeof( struct sockaddr_at )) != resp_buf->atpbuf_dlen ) {
112 if ( ah->atph_rxo ) {
113 for ( ; i >= 0; --i ) {
114 atp_free_buf( save_buf->atpbuf_info.atpbuf_xo.atpxo_packet[ i ] );
116 atp_free_buf( save_buf );
121 } else printf( "<%d> atp_sresp: dropped serial no. %d\n", getpid(), i );
123 /* allocate a buffer for next packet (if XO mode)
125 if ( ah->atph_rxo && ( resp_buf = atp_alloc_buf()) == NULL ) {
129 atp_free_buf( resp_buf );
130 if ( ah->atph_rxo ) {
131 /* record timestamp, tid, release time, and destination address
133 gettimeofday( &save_buf->atpbuf_info.atpbuf_xo.atpxo_tv,
134 (struct timezone *) 0 );
135 save_buf->atpbuf_info.atpbuf_xo.atpxo_tid = ah->atph_rtid;
136 save_buf->atpbuf_info.atpbuf_xo.atpxo_reltime = ah->atph_rreltime;
137 memcpy( &save_buf->atpbuf_addr, atpb->atp_saddr,
138 sizeof( struct sockaddr_at ));
140 /* add to list of packets we have sent
142 save_buf->atpbuf_next = ah->atph_sent;
143 ah->atph_sent = save_buf;
145 printf( "<%d> saved XO response\n", getpid());