#include #include "socket.h" #include #include #include #define VERSION "0.03" int printflag = 1; int main( int argc, char ** argv ) { struct sockaddr_in a; // struct sockaddr_in l; FILE *f; int s; int r; int timeout = 2; unsigned int port; unsigned long ip; // unsigned long ip2; printf("TDUMP.EXE (c) 2004 Josh Levine\r\n"); if (argc != 4 ) { printf("Syntax: TDUMP address port file\r\n"); printf("Where: address is the tcpip address to connect to\r\n"); printf(" port is the tcpip port to connect to\r\n"); printf(" file is the file to dump down the socket once connected\r\n"); printf("Returns:\r\n"); printf(" 0 = connected and dumped successfully\r\n"); printf(" 1 = error connecting or dumping\r\n"); return(1); } printf("IP=[%s], PORT=[%s]\r\n", argv[1] , argv[2] ); printf("Checking for TCP/IP stack...\r\n"); if (!loaded()) { printf("Novell TCP/IP stack not loaded!\r\n"); return(1); } printf("Creating socket...\r\n"); s = socket( PF_INET , SOCK_STREAM , 0 ); if ( s < 0 ) { printf("Error creating socket %d.\r\n",errno); return( 1 ); } // l.sin_family = AF_INET; // l.sin_port = 0; // l.sin_addr.s_addr = 0; // printf("Binding socket...\r\n"); // r = bind( s , (struct sockaddr *) &l , sizeof( struct sockaddr ) ); // if (r != 0 ) { // printf("Error binding %d.\r\n",r); // soclose(s); // return(1); // } // printf("socket bind success!\r\n"); port = atoi( argv[2] ); ip = rhost( &argv[1] ); // ip = 0; // ip |= (( ip2 >> 24 ) &0xff) ; // ip |= (( ip2 >> 16 ) &0xff) << 8; // ip |= (( ip2 >> 8 ) &0xff) << 16; // ip |= (( ip2 >> 0 ) &0xff) << 24; bzero( (char *)&a , sizeof( a ) ); a.sin_family = AF_INET; a.sin_port = htons( port ); // if (( hp = gethostbyaddr( argv[1] ) ) == NULL ) { // printf( "gethostbyname failed\r\n"); // return(1); // } // bcopy( hp->h_addr , (char *) &a.sin_addr , hp->h_length ); a.sin_addr.s_addr = ip ; printf("Setting socket timeouts to %d seconds...\r\n", timeout ); setsockopt( s , SOL_SOCKET , SO_SNDTIMEO , &timeout , sizeof(timeout) ); setsockopt( s , SOL_SOCKET , SO_RCVTIMEO , &timeout , sizeof(timeout) ); printf("Connecting to [%s]:[%ud]...\r\n", inet_ntoa( a.sin_addr ) , port ); r = connect( s , (struct sockaddr *) &a , sizeof( struct sockaddr ) ); if (r != 0 ) { printf("Connect failed... "); switch (errno) { default: printf("unknown %d",errno); break; } printf(".\r\n"); return(1); } printf("Connected!\r\n"); printf("Opening file %s...\r\n",argv[3]); f = fopen( argv[3] , "rb" ); if (!f) { printf("Could not open file!\r\n"); return(1); } while (!feof(f)) { char x[1]; x[0] =fgetc( f ); r=send( s , x , 1 , 0 ); if ( r != 1 ) { printf("Error on send() = %d\r\n",r); break; } else { if (printflag) { if (isprint( *x ) ) { printf("%c",*x); } else { printf("[%d]",*x); } } } } printf("flushing...\r\n"); fflush(f); printf("closing file...\r\n"); fclose(f); printf("closing socket...\r\n"); soclose(s); return 0; }