6 #include <sys/socket.h> 22 FILE* pFile = fopen ( fname ,
"r" );
26 fseek (pFile , 0 , SEEK_END);
27 unsigned int lSize = ftell (pFile);
31 void* buffer = malloc (
sizeof(Bytef)*(lSize));
33 size_t result = fread (buffer, 1, lSize ,pFile);
35 if ( !result ) {
std::cerr <<
"Failed to read " << fname <<std::endl;
exit(1); }
42 unsigned int deflatedSize = compressBound(lSize) + 4;
43 Bytef * deflatedBuff = (Bytef*) malloc (
sizeof(Bytef)*(deflatedSize));
44 *((
unsigned int*)deflatedBuff) = htonl(lSize);
47 *buffPtr = deflatedBuff;
50 zippedSize = deflatedSize;
51 compress(deflatedBuff+4, &zippedSize, (
const Bytef *)buffer, lSize);
67 std::cerr <<
"Uasage: sendCrashReport <fileName>" << std::endl;
exit(1);
71 int sd = socket(AF_INET,SOCK_DGRAM, 0);
72 if (sd < 0) {
return 1; }
75 struct sockaddr_in cliAddr;
76 cliAddr.sin_family = AF_INET;
77 cliAddr.sin_addr.s_addr = htonl(INADDR_ANY);
78 cliAddr.sin_port = htons(0);
80 int rc = bind(sd, (
struct sockaddr *) &cliAddr,
sizeof(cliAddr));
82 std::cerr <<
"Can't bind port %d " << rc << std::endl;
exit(1);
86 struct hostent*
h = gethostbyname(
"xrootd.t2.ucsd.edu");
91 struct sockaddr_in remoteServAddr;
92 remoteServAddr.sin_family = h->h_addrtype;
93 memcpy((
char *) &remoteServAddr.sin_addr.s_addr, h->h_addr_list[0], h->h_length);
94 remoteServAddr.sin_port = htons(9699);
97 unsigned long buffSize;
100 sendto(sd, buff, buffSize, 0,
101 (
struct sockaddr *) &remoteServAddr,
102 sizeof(remoteServAddr));
void getCompressedBuffer(const char *fname, Bytef **buffPtr, unsigned long &zippedSize)
int main(int argc, char **argv)