]> arthur.barton.de Git - netatalk.git/blobdiff - libatalk/atp/atp_packet.c
Remove bdb env on exit
[netatalk.git] / libatalk / atp / atp_packet.c
index 6e029227cdc64a425772828373d5b77d73d55431..a7fae01b565ab59f6960386a7e62285b3c786621 100644 (file)
@@ -1,4 +1,6 @@
 /*
+ * $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:
@@ -67,9 +72,7 @@ static void print_func( ctrlinfo )
     }
 }
 
-static void dump_packet( buf, len )
-    char       *buf;
-    int                len;
+static void dump_packet(char *buf, int len)
 {
     int                i;
 
@@ -79,9 +82,7 @@ static void dump_packet( buf, len )
     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." ) :
@@ -93,14 +94,13 @@ void atp_print_addr( s, saddr )
     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;
 
@@ -116,15 +116,14 @@ void atp_build_req_packet( pktbuf, tid, ctrl, atpb )
 
     /* 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;
 
@@ -141,18 +140,17 @@ void atp_build_resp_packet( pktbuf, tid, ctrl, atpb, seqnum )
 
     /* 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
@@ -180,7 +178,7 @@ atp_recv_atp( ah, fromaddr, func, tid, rbuf, wait )
     */
 #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, 
@@ -192,7 +190,7 @@ atp_recv_atp( ah, fromaddr, func, tid, rbuf, wait )
        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 )) {
@@ -202,7 +200,7 @@ atp_recv_atp( ah, fromaddr, func, tid, rbuf, wait )
     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 );
@@ -227,12 +225,12 @@ atp_recv_atp( ah, fromaddr, func, tid, rbuf, wait )
     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 ));
 
@@ -253,7 +251,7 @@ atp_recv_atp( ah, fromaddr, func, tid, rbuf, wait )
            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;
@@ -265,7 +263,7 @@ atp_recv_atp( ah, fromaddr, func, tid, rbuf, wait )
                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 {
@@ -291,14 +289,14 @@ atp_recv_atp( ah, fromaddr, func, tid, rbuf, wait )
                /* 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 );
            }
        }
@@ -312,9 +310,9 @@ atp_recv_atp( ah, fromaddr, func, tid, rbuf, wait )
 }
 
 
-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.