/*
+ * $Id: atp_packet.c,v 1.6 2009-10-13 22:55:37 didg Exp $
+ *
* Copyright (c) 1990,1991 Regents of The University of Michigan.
* All Rights Reserved.
*
* netatalk@itd.umich.edu
*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
#include <string.h>
#include <sys/types.h>
#include <sys/time.h>
/* FIXME/SOCKLEN_T: socklen_t is a unix98 feature. */
#ifndef SOCKLEN_T
#define SOCKLEN_T unsigned int
-#endif
+#endif /* ! SOCKLEN_T */
#ifdef EBUG
#include <stdio.h>
-static void print_func( ctrlinfo )
- u_int8_t ctrlinfo;
+static void print_func(u_int8_t ctrlinfo)
{
switch ( ctrlinfo & ATP_FUNCMASK ) {
case ATP_TREQ:
}
}
-static void dump_packet( buf, len )
- char *buf;
- int len;
+static void dump_packet(char *buf, int len)
{
int i;
putchar( '\n' );
}
-void atp_print_addr( s, saddr )
- char *s;
- struct sockaddr_at *saddr;
+void atp_print_addr(char *s, struct sockaddr_at *saddr)
{
printf( "%s ", s );
saddr->sat_family == AF_APPLETALK ? printf( "at." ) :
saddr->sat_port == ATADDR_ANYPORT ? printf( "*" ) :
printf( "%d", saddr->sat_port );
}
-#endif
+#endif /* EBUG */
-void atp_build_req_packet( pktbuf, tid, ctrl, atpb )
- struct atpbuf *pktbuf;
- u_int16_t tid;
- u_int8_t ctrl;
- struct atp_block *atpb;
+void atp_build_req_packet( struct atpbuf *pktbuf,
+ u_int16_t tid,
+ u_int8_t ctrl,
+ struct atp_block *atpb )
{
struct atphdr hdr;
/* set length
*/
- pktbuf->atpbuf_dlen = ATP_HDRSIZE + atpb->atp_sreqdlen;
+ pktbuf->atpbuf_dlen = ATP_HDRSIZE + (size_t) atpb->atp_sreqdlen;
}
-void atp_build_resp_packet( pktbuf, tid, ctrl, atpb, seqnum )
- struct atpbuf *pktbuf;
- u_int16_t tid;
- u_int8_t ctrl;
- struct atp_block *atpb;
- u_int8_t seqnum;
+void atp_build_resp_packet( struct atpbuf *pktbuf,
+ u_int16_t tid,
+ u_int8_t ctrl,
+ struct atp_block *atpb,
+ u_int8_t seqnum )
{
struct atphdr hdr;
/* set length
*/
- pktbuf->atpbuf_dlen = ATP_HDRSIZE + atpb->atp_sresiov[ seqnum ].iov_len;
+ pktbuf->atpbuf_dlen = ATP_HDRSIZE + (size_t) atpb->atp_sresiov[ seqnum ].iov_len;
}
int
-atp_recv_atp( ah, fromaddr, func, tid, rbuf, wait )
- ATP ah;
- struct sockaddr_at *fromaddr;
- u_int8_t *func;
- u_int16_t tid;
- char *rbuf;
- int wait;
+atp_recv_atp( ATP ah,
+ struct sockaddr_at *fromaddr,
+ u_int8_t *func,
+ u_int16_t tid,
+ char *rbuf,
+ int wait )
{
/*
Receive a packet from address fromaddr of the correct function type
*/
#ifdef EBUG
atp_print_bufuse( ah, "recv_atp checking queue" );
-#endif
+#endif /* EBUG */
for ( pq = NULL, cq = ah->atph_queue; cq != NULL;
pq = cq, cq = cq->atpbuf_next ) {
memcpy(&ahdr, cq->atpbuf_info.atpbuf_data + 1,
print_func( rfunc );
atp_print_addr( " from", &cq->atpbuf_addr );
putchar( '\n' );
-#endif
+#endif /* EBUG */
if ((( tid & ahdr.atphd_tid ) == ahdr.atphd_tid ) &&
(( *func & rfunc ) == rfunc )
&& at_addr_eq( fromaddr, &cq->atpbuf_addr )) {
if ( cq != NULL ) {
/* we found one in the queue -- copy to rbuf
*/
- dlen = cq->atpbuf_dlen;
+ dlen = (int) cq->atpbuf_dlen;
*func = rfunc;
memcpy( fromaddr, &cq->atpbuf_addr, sizeof( struct sockaddr_at ));
memcpy( rbuf, cq->atpbuf_info.atpbuf_data, cq->atpbuf_dlen );
print_func( *func );
atp_print_addr( " from", fromaddr );
putchar( '\n' );
-#endif
+#endif /* EBUG */
do {
#ifdef EBUG
fflush( stdout );
-#endif
+#endif /* EBUG */
faddrlen = sizeof( struct sockaddr_at );
memset( &faddr, 0, sizeof( struct sockaddr_at ));
atp_print_addr( " from", &faddr );
putchar( '\n' );
bprint( rbuf, recvlen );
-#endif
+#endif /* EBUG */
if ( rfunc == ATP_TREL ) {
/* remove response from sent list */
for ( pq = NULL, cq = ah->atph_sent; cq != NULL;
if ( cq != NULL ) {
#ifdef EBUG
printf( "<%d> releasing transaction %hu\n", getpid(), ntohs( rtid ));
-#endif
+#endif /* EBUG */
if ( pq == NULL ) {
ah->atph_sent = cq->atpbuf_next;
} else {
/* add packet to incoming queue */
#ifdef EBUG
printf( "<%d> queuing incoming...\n", getpid() );
-#endif
+#endif /* EBUG */
if (( inbuf = atp_alloc_buf()) == NULL ) {
return -1;
}
memcpy( &inbuf->atpbuf_addr, &faddr,
sizeof( struct sockaddr_at ));
inbuf->atpbuf_next = ah->atph_queue;
- inbuf->atpbuf_dlen = recvlen;
+ inbuf->atpbuf_dlen = (size_t) recvlen;
memcpy( inbuf->atpbuf_info.atpbuf_data, rbuf, recvlen );
}
}
}
-int at_addr_eq( paddr, saddr )
- struct sockaddr_at *paddr; /* primary address */
- struct sockaddr_at *saddr; /* secondary address */
+int at_addr_eq(
+ struct sockaddr_at *paddr, /* primary address */
+ struct sockaddr_at *saddr) /* secondary address */
{
/* compare two atalk addresses -- only check the non-zero fields
of paddr against saddr.