Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions src/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

/* external support */
#include <string.h>
#include <fcntl.h>
#include "exttime.h"
#include "extthrd.h"
#include "extmath.h"
Expand Down Expand Up @@ -492,18 +493,39 @@ int send_tf(NODE *np)
{
int status;
word32 first, count;
char cmd[128], fname[32];
char fname[32];
BTRAILER bt;
FILE *ifp, *ofp;
word32 j;

sprintf(fname, "tf%u.tmp", (int) getpid());

first = get32(np->tx.blocknum); /* first trailer to send */
count = get32(&np->tx.blocknum[4]); /* count of trailers to send */

/* limit tfile extract to 1000 trailers */
if(count > 1000) return VERROR;
sprintf(cmd, "dd if=tfile.dat of=%s bs=%u skip=%u count=%u 2>/dev/null",
fname, (int) sizeof(BTRAILER), first, count);
system(cmd);
if (count > 1000) return VERROR;

/* extract trailers from tfile.dat to temp file */
ifp = fopen("tfile.dat", "rb");
if (ifp == NULL) return VERROR;
if (fseek64(ifp, (long long) first * sizeof(BTRAILER), SEEK_SET) != 0) {
fclose(ifp);
return VERROR;
}
{ int fd = open(fname, O_WRONLY | O_CREAT | O_TRUNC, 0600);
ofp = (fd != -1) ? fdopen(fd, "wb") : NULL; }
if (ofp == NULL) {
fclose(ifp);
return VERROR;
}
for (j = 0; j < count && Running; j++) {
if (fread(&bt, sizeof(BTRAILER), 1, ifp) != 1) break;
if (fwrite(&bt, sizeof(BTRAILER), 1, ofp) != 1) break;
}
fclose(ifp);
fclose(ofp);

status = send_file(np, fname); /* returns VEOK or VERROR */
remove(fname);
return status;
Expand Down
Loading