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>
35 #include <netatalk/at.h>
36 #include <netatalk/endian.h>
38 #include <atalk/netddp.h>
39 #include <atalk/atp.h>
40 #include <atalk/util.h>
42 #include "atp_internals.h"
44 /* send a transaction response
46 int atp_sresp( ah, atpb )
47 ATP ah; /* open atp handle */
48 struct atp_block *atpb; /* parameter block */
52 struct atpbuf *resp_buf;
53 struct atpbuf *save_buf;
56 atp_print_bufuse( ah, "atp_sresp" );
61 for ( i = atpb->atp_sresiovcnt - 1; i >= 0; --i ) {
62 if ( atpb->atp_sresiov[ i ].iov_len > ATP_MAXDATA )
65 if ( i >= 0 || atpb->atp_sresiovcnt < 1 || atpb->atp_sresiovcnt > 8 ) {
70 /* allocate a new buffer for reponse packet construction
72 if (( resp_buf = atp_alloc_buf()) == NULL ) {
76 /* send all the response packets
77 * also need to attach list to ah for dup. detection (if XO)
80 printf( "<%d> preparing to send %s response tid=%hu ", getpid(),
81 ah->atph_rxo ? "XO" : "", ah->atph_rtid );
82 atp_print_addr( " to", atpb->atp_saddr );
86 if (( save_buf = atp_alloc_buf()) == NULL ) {
90 save_buf->atpbuf_info.atpbuf_xo.atpxo_packet[ i++ ] = NULL );
92 for ( i = 0; i < atpb->atp_sresiovcnt; ++i ) {
97 if ( i == atpb->atp_sresiovcnt-1 ) {
100 atp_build_resp_packet( resp_buf, ah->atph_rtid, ctrlinfo, atpb, i );
102 if ( ah->atph_rxo ) {
103 save_buf->atpbuf_info.atpbuf_xo.atpxo_packet[i] = resp_buf;
106 if (( random() % 3 ) != 2 ) {
109 printf( "<%d> sending packet tid=%hu serial no.=%d\n", getpid(),
111 bprint( resp_buf->atpbuf_info.atpbuf_data, resp_buf->atpbuf_dlen );
113 if ( netddp_sendto( ah->atph_socket, resp_buf->atpbuf_info.atpbuf_data,
114 resp_buf->atpbuf_dlen, 0, (struct sockaddr *) atpb->atp_saddr,
115 sizeof( struct sockaddr_at )) != resp_buf->atpbuf_dlen ) {
116 if ( ah->atph_rxo ) {
117 for ( ; i >= 0; --i ) {
118 atp_free_buf( save_buf->atpbuf_info.atpbuf_xo.atpxo_packet[ i ] );
120 atp_free_buf( save_buf );
125 } else printf( "<%d> atp_sresp: dropped serial no. %d\n", getpid(), i );
127 /* allocate a buffer for next packet (if XO mode)
129 if ( ah->atph_rxo && ( resp_buf = atp_alloc_buf()) == NULL ) {
133 atp_free_buf( resp_buf );
134 if ( ah->atph_rxo ) {
135 /* record timestamp, tid, release time, and destination address
137 gettimeofday( &save_buf->atpbuf_info.atpbuf_xo.atpxo_tv,
138 (struct timezone *) 0 );
139 save_buf->atpbuf_info.atpbuf_xo.atpxo_tid = ah->atph_rtid;
140 save_buf->atpbuf_info.atpbuf_xo.atpxo_reltime = ah->atph_rreltime;
141 memcpy( &save_buf->atpbuf_addr, atpb->atp_saddr,
142 sizeof( struct sockaddr_at ));
144 /* add to list of packets we have sent
146 save_buf->atpbuf_next = ah->atph_sent;
147 ah->atph_sent = save_buf;
149 printf( "<%d> saved XO response\n", getpid());