/*
- * $Id: aecho.c,v 1.6 2003-06-06 19:35:15 srittau Exp $
+ * $Id: aecho.c,v 1.9 2009-10-14 01:38:28 didg Exp $
*
* Copyright (c) 1990,1991 Regents of The University of Michigan.
* All Rights Reserved.
#define SOCKLEN_T unsigned int
#endif /* ! SOCKLEN_T */
-struct sockaddr_at target;
-int s, nsent = 0, nrecv = 0;
-time_t totalms = 0, minms = -1, maxms = -1;
-static unsigned int pings = 0;
+static struct sockaddr_at target;
+static int sock;
+static unsigned int nsent = 0, nrecv = 0;
+static time_t totalms = 0, minms = -1, maxms = -1;
+static unsigned int pings = 0;
-void usage(char *);
+static void usage(char *);
-void done()
+static void done(int sig _U_)
{
- if ( nsent > 0 ) {
+ if ( nsent) {
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 ) {
+ if ( nrecv ) {
printf( "round-trip (ms) min/avg/max = %ld/%ld/%ld\n",
minms, totalms / nrecv, maxms );
}
exit( 0 );
}
-void aep_send()
+static void aep_send(int sig _U_)
{
struct timeval tv;
char *p, buf[ 1024 ];
memcpy( p, &tv, sizeof( struct timeval ));
p += sizeof( struct timeval );
- if ( netddp_sendto( s, buf, p - buf, 0, (struct sockaddr *) &target,
+ if ( netddp_sendto( sock, buf, p - buf, 0, (struct sockaddr *) &target,
sizeof( struct sockaddr_at )) < 0 ) {
perror( "sendto" );
exit( 1 );
}
nsent++;
- if (pings && nsent > pings) done();
+ if (pings && nsent > pings) done(0);
}
-int main( ac, av )
- int ac;
- char **av;
+int main(int ac, char **av)
{
struct servent *se;
struct sigaction sv;
}
target.sat_port = port;
- if ((s = netddp_open(saddr.sat_addr.s_net || saddr.sat_addr.s_node ?
+ if ((sock = netddp_open(saddr.sat_addr.s_net || saddr.sat_addr.s_node ?
&saddr : NULL, NULL)) < 0) {
perror("ddp_open");
exit(1);
for (;;) {
satlen = sizeof( struct sockaddr_at );
- if (( cc = netddp_recvfrom( s, buf, sizeof( buf ), 0,
+ if (( cc = netddp_recvfrom( sock, buf, sizeof( buf ), 0,
(struct sockaddr *) &sat,
&satlen )) < 0 ) {
if ( errno == EINTR ) {
printf( "%d bytes from %u.%u: aep_seq=%d. time=%ld. ms\n",
cc, ntohs( sat.sat_addr.s_net ), sat.sat_addr.s_node,
seq, ms );
- if (pings && seq + 1 >= pings) done();
+ if (pings && seq + 1 >= pings) done(0);
}
}
-void usage( char * av0 )
+static void usage( char * av0 )
{
fprintf( stderr, "usage:\t%s [-A source address ] [-c count] ( addr | nbpname )\n", av0 );
exit( 1 );