/*
* main-dccput.c : main routine for DCC file put.
*
* $Id: main-dccput.c,v 1.1 2000/12/30 16:31:42 simm Exp $
*/
#include "pure.h"
#define BUFSIZE (1024)
int error_exit( int retval, dcc_file* file, net_peer* peer, char* message )
{
if ( file ) if ( file->handle ) close( file->handle );
if ( peer ) if ( peer->handle ) close( peer->handle );
printf( "[ERROR] %s\n", message );
exit( retval );
}
int main( int ac, char** av )
{
net_peer peer;
dcc_file file;
char buf[BUFSIZE];
/* initialize handle */
file.handle = 0;
peer.handle = 0;
/* parse args */
if ( ac == 1 ) {
printf( "[USAGE] %s filename [peer host] [begin port] [end port]\n", av[0] );
return 1;
}
file.name = av[1];
peer.name = ( ac > 2 ) ? av[2] : NULL;
peer.bport = ( ac > 3 ) ? atoi( av[3] ) : 0;
peer.eport = ( ac > 4 ) ? atoi( av[4] ) : 0;
/* open file */
if ( pure_open_putfile( &file ) )
error_exit( 2, &file, &peer, "cannot open file." );
/* listen to client */
if ( pure_server_wait( &peer, file.size ) < 0 )
error_exit( 3, &file, &peer, "cannot make network connection." );
/* read offset */
if ( ! fgets( buf, BUFSIZE, stdin ) )
error_exit( 4, &file, &peer, "cannot get offset position." );
if ( memcmp( buf, "OFFSET ", 7 ) )
error_exit( 5, &file, &peer, "received message syntax error." );
file.offset = strtoul( buf + 7, (char**)NULL, 10 );
printf( "[INFO] Offset %u\n", file.offset );
/* send file */
pure_putfile( &file, &peer );
/* that's all */
close( file.handle );
close( peer.handle );
return 0;
}
syntax highlighted by Code2HTML, v. 0.9.1