#ifdef WIN32 #include #endif #include #include #include #include #include #include "transfer.h" #include "dataspy.h" // 24 byte data block header - used for data blocks in shared memory and data blocks on disc or tape. typedef struct s_data_header { char header_id[8]; int header_sequence; short header_stream; short header_tape; short header_MyEndian; short header_DataEndian; int header_dataLen; } DATA_HEADER; // 32 byte header - used when transfering data blocks using TCP typedef struct s_block_header { /* format of data block */ unsigned short hdr_flags; /* see below */ unsigned short hdr_stream; /* =0 for forced ack request or 1=>MAX_STREAM */ unsigned short hdr_endian; /* data byte order */ unsigned short hdr_ID; unsigned int hdr_sequence; /* for this stream */ unsigned int hdr_blocklength; /* total length of this block including the header */ unsigned int hdr_datalength; /* length of user data in the block */ unsigned int hdr_offset; /* very large blocks may be fragmented */ unsigned int hdr_id1; /* for spy to locate header =0x19062002 */ unsigned int hdr_id2; /* for spy to locate header =0x09592400 */ } XFER_HEADER; void Usage(char *progname) { fprintf(stderr,"Usage\n%s -n server -p [port] -i [id] -I [ID] -s [buffer size]\n",progname); fprintf(stderr,"\tserver is the IP address or name of destination\n"); fprintf(stderr,"\tport is the base TCP port to use\n"); fprintf(stderr,"\tid is the source data shared memory area ID to use\n"); fprintf(stderr,"\tID is the destination TCP port offset to use\n"); fprintf(stderr,"\tmode is the protocol transfer option\n"); fprintf(stderr,"Defaults are (none); 10305; 0; 0; 64K\n"); exit(1); } int main(int argc, char **argv) { char Buffer [64+(64*1024)]; /* a 64Kbyte data buffer + a bit extra to handle block headers */ DATA_HEADER data_header; int BufferLength; int DataLength; char *TS_Server= NULL; int Port=10305; int ID=0; int id=0; int Mode=3; unsigned int stream = 1; int verbose=0; int s; int i; int BufferSize=64*1024; int DelayTicks=10; #ifndef WIN32 struct timespec time_request; #endif if (argc >1) { for(i=1;i 0) { memcpy (data_header.header_id, (char*)&Buffer[sizeof(HEADER)-sizeof(DATA_HEADER)], sizeof(DATA_HEADER)); BufferLength = data_header.header_dataLen; /* the actual application data less headers */ if (verbose) printf("buffer length=%d\n",BufferLength); /* transfer this data buffer. This requires that we allow 32 bytes for use by the protocol overheads */ s = transferMultiTxData (ID, &Buffer[sizeof(HEADER)], stream, BufferLength); /* write data from offset 32 bytes */ if (verbose) printf("transfer done with code=%d\n",s); } else { if (DelayTicks) { #ifdef WIN32 Sleep((DWORD)DelayTicks); #endif #ifdef LINUX time_request.tv_sec = DelayTicks/1000; time_request.tv_nsec = (DelayTicks - (time_request.tv_sec * 1000)) * 1000000; i = nanosleep(&time_request, NULL); #endif } } } }