--- bin/aecho/aecho.c.orig Sun Oct 20 07:13:18 1996 +++ bin/aecho/aecho.c Wed Nov 10 13:57:25 1999 @@ -29,10 +29,13 @@ #include #include #include -#include +#include #include #include +#include +#include +#include #include #include @@ -44,7 +47,28 @@ struct sockaddr_at target; int s, nsent = 0, nrecv = 0; -long totalms = 0, minms = -1, maxms = -1; +time_t totalms = 0, minms = -1, maxms = -1; +static unsigned int count = 0; +void usage(); +int atalk_aton(); + +#if !defined( ibm032 ) && !defined( _IBMR2 ) + void +#endif ibm032 _IBMR2 +finish() +{ + if ( nsent > 0 ) { + printf( "\n----%d.%d AEP Statistics----\n", + ntohs( target.sat_addr.s_net ), target.sat_addr.s_node ); + printf( "%d packets sent, %d packets received, %d%% packet loss\n", + nsent, nrecv, (( nsent - nrecv ) * 100 ) / nsent ); + if ( nrecv > 0 ) { + printf( "round-trip (ms) min/avg/max = %d/%d/%d\n", + minms, totalms / nrecv, maxms ); + } + } + exit( 0 ); +} #if !defined( ibm032 ) && !defined( _IBMR2 ) void @@ -58,7 +82,7 @@ p = buf; *p++ = DDPTYPE_AEP; *p++ = AEPOP_REQUEST; - bcopy( &seq, p, sizeof( unsigned int )); + memcpy( p, &seq, sizeof( unsigned int )); p += sizeof( unsigned int ); seq++; @@ -66,7 +90,7 @@ perror( "gettimeofday" ); exit( 1 ); } - bcopy( &tv, p, sizeof( struct timeval )); + memcpy( p, &tv, sizeof( struct timeval )); p += sizeof( struct timeval ); if ( sendto( s, buf, p - buf, 0, (struct sockaddr *) &target, @@ -75,26 +99,10 @@ exit( 1 ); } nsent++; + if (count && nsent > count) finish(); } -#if !defined( ibm032 ) && !defined( _IBMR2 ) - void -#endif ibm032 _IBMR2 -done() -{ - if ( nsent > 0 ) { - printf( "\n----%d.%d AEP Statistics----\n", - ntohs( target.sat_addr.s_net ), target.sat_addr.s_node ); - printf( "%d packets sent, %d packets received, %d%% packet loss\n", - nsent, nrecv, (( nsent - nrecv ) * 100 ) / nsent ); - if ( nrecv > 0 ) { - printf( "round-trip (ms) min/avg/max = %d/%d/%d\n", - minms, totalms / nrecv, maxms ); - } - } - exit( 0 ); -} - +int main( ac, av ) int ac; char **av; @@ -106,14 +114,29 @@ struct timeval tv, atv; struct nbpnve nn; char *obj = NULL, *type = "Workstation", *zone = "*"; - int satlen, cc; - unsigned int seq; - long ms; + int cc; + unsigned int satlen, seq; + time_t ms; char buf[ 1024 ], *p; unsigned char port; - extern int errno; + extern char *optarg; + extern int optind; - if ( ac != 2 ) usage( av[ 0 ] ); + while (( cc = getopt( ac, av, "c:" )) != EOF ) { + switch ( cc ) { + case 'c' : + count = atoi( optarg ); + break; + + default : + usage( av[ 0 ] ); + exit( 1 ); + } + } + if ( ac - optind != 1 ) { + usage( av[ 0 ] ); + exit( 1 ); + } /* * Save the port, since nbp_lookup calls getservbyname() to get the @@ -125,21 +148,21 @@ } port = ntohs( se->s_port ); - bzero( &target, sizeof( struct sockaddr_at )); + memset( &target, 0, sizeof( struct sockaddr_at )); #ifdef BSD4_4 target.sat_len = sizeof( struct sockaddr_at ); #endif BSD4_4 target.sat_family = AF_APPLETALK; - if ( !atalk_aton( av[ 1 ], &target.sat_addr )) { - if ( nbp_name( av[ 1 ], &obj, &type, &zone ) || !obj ) { - fprintf( stderr, "Bad name: %s\n", av[ 1 ] ); + if ( !atalk_aton( av[ optind ], &target.sat_addr )) { + if ( nbp_name( av[ optind ], &obj, &type, &zone ) || !obj ) { + fprintf( stderr, "Bad name: %s\n", av[ optind ] ); exit( 1 ); } if ( nbp_lookup( obj, type, zone, &nn, 1 ) <= 0 ) { - fprintf( stderr, "Can't find: %s\n", av[ 1 ] ); + fprintf( stderr, "Can't find: %s\n", av[ optind ] ); exit( 1 ); } - bcopy( &nn.nn_sat, &target, sizeof( struct sockaddr_at )); + memcpy( &target, &nn.nn_sat, sizeof( struct sockaddr_at )); } target.sat_port = port; @@ -157,7 +180,7 @@ exit( 1 ); } - sv.sa_handler = done; + sv.sa_handler = finish; sigemptyset( &sv.sa_mask ); sigaddset( &sv.sa_mask, SIGALRM ); sv.sa_flags = SA_RESTART; @@ -197,9 +220,9 @@ perror( "gettimeofday" ); exit( 1 ); } - bcopy( p, &seq, sizeof( unsigned int )); + memcpy( &seq, p, sizeof( unsigned int )); p += sizeof( unsigned int ); - bcopy( p, &atv, sizeof( struct timeval )); + memcpy( &atv, p, sizeof( struct timeval )); nrecv++; ms = ( tv.tv_sec - atv.tv_sec ) * 1000 + ( tv.tv_usec - atv.tv_usec ) / 1000; @@ -213,11 +236,14 @@ printf( "%d bytes from %u.%u: aep_seq=%d. time=%d. ms\n", cc, ntohs( sat.sat_addr.s_net ), sat.sat_addr.s_node, seq, ms ); + if (count && seq + 1 >= count) finish(); } } +void usage( av0 ) + char *av0; { - fprintf( stderr, "Usage:\t%s ( addr | nbpname )\n", av0 ); + fprintf( stderr, "Usage:\t%s [-c count ] ( addr | nbpname )\n", av0 ); exit( 1 ); }