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 <sys/socket.h>
36 #include <netatalk/at.h>
37 #include <netatalk/endian.h>
39 #include <atalk/netddp.h>
40 #include <atalk/atp.h>
41 #include <atalk/util.h>
43 #include "atp_internals.h"
45 /* send a transaction response
47 int atp_sresp( ah, atpb )
48 ATP ah; /* open atp handle */
49 struct atp_block *atpb; /* parameter block */
53 struct atpbuf *resp_buf;
54 struct atpbuf *save_buf;
57 atp_print_bufuse( ah, "atp_sresp" );
62 for ( i = atpb->atp_sresiovcnt - 1; i >= 0; --i ) {
63 if ( atpb->atp_sresiov[ i ].iov_len > ATP_MAXDATA )
66 if ( i >= 0 || atpb->atp_sresiovcnt < 1 || atpb->atp_sresiovcnt > 8 ) {
71 /* allocate a new buffer for reponse packet construction
73 if (( resp_buf = atp_alloc_buf()) == NULL ) {
77 /* send all the response packets
78 * also need to attach list to ah for dup. detection (if XO)
81 printf( "<%d> preparing to send %s response tid=%hu ", getpid(),
82 ah->atph_rxo ? "XO" : "", ah->atph_rtid );
83 atp_print_addr( " to", atpb->atp_saddr );
87 if (( save_buf = atp_alloc_buf()) == NULL ) {
91 save_buf->atpbuf_info.atpbuf_xo.atpxo_packet[ i++ ] = NULL );
93 for ( i = 0; i < atpb->atp_sresiovcnt; ++i ) {
98 if ( i == atpb->atp_sresiovcnt-1 ) {
101 atp_build_resp_packet( resp_buf, ah->atph_rtid, ctrlinfo, atpb, i );
103 if ( ah->atph_rxo ) {
104 save_buf->atpbuf_info.atpbuf_xo.atpxo_packet[i] = resp_buf;
107 if (( random() % 3 ) != 2 ) {
110 printf( "<%d> sending packet tid=%hu serial no.=%d\n", getpid(),
112 bprint( resp_buf->atpbuf_info.atpbuf_data, resp_buf->atpbuf_dlen );
114 if ( netddp_sendto( ah->atph_socket, resp_buf->atpbuf_info.atpbuf_data,
115 resp_buf->atpbuf_dlen, 0, (struct sockaddr *) atpb->atp_saddr,
116 sizeof( struct sockaddr_at )) != resp_buf->atpbuf_dlen ) {
117 if ( ah->atph_rxo ) {
118 for ( ; i >= 0; --i ) {
119 atp_free_buf( save_buf->atpbuf_info.atpbuf_xo.atpxo_packet[ i ] );
121 atp_free_buf( save_buf );
126 } else printf( "<%d> atp_sresp: dropped serial no. %d\n", getpid(), i );
128 /* allocate a buffer for next packet (if XO mode)
130 if ( ah->atph_rxo && ( resp_buf = atp_alloc_buf()) == NULL ) {
134 atp_free_buf( resp_buf );
135 if ( ah->atph_rxo ) {
136 /* record timestamp, tid, release time, and destination address
138 gettimeofday( &save_buf->atpbuf_info.atpbuf_xo.atpxo_tv,
139 (struct timezone *) 0 );
140 save_buf->atpbuf_info.atpbuf_xo.atpxo_tid = ah->atph_rtid;
141 save_buf->atpbuf_info.atpbuf_xo.atpxo_reltime = ah->atph_rreltime;
142 memcpy( &save_buf->atpbuf_addr, atpb->atp_saddr,
143 sizeof( struct sockaddr_at ));
145 /* add to list of packets we have sent
147 save_buf->atpbuf_next = ah->atph_sent;
148 ah->atph_sent = save_buf;
150 printf( "<%d> saved XO response\n", getpid());