Skip to content

Commit 460036e

Browse files
committed
output received packets to filie
1 parent 63f86a7 commit 460036e

File tree

5 files changed

+5
-1
lines changed

5 files changed

+5
-1
lines changed

go-back-n/gbn.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,13 @@ ssize_t gbn_recv(int sockfd, void *buf, size_t len, int flags){
156156
/* Receiver responds with DATAACK */
157157
printf("INFO: Packet seqnum : %d State seqnum: %d\n",packet->seqnum,state.seqnum);
158158
if(state.seqnum == packet->seqnum){
159-
printf("INFO: Received DATA packet is in sequence.\n");
159+
printf("INFO: Received DATA packet is in sequence.\n");
160+
memcpy(buf,packet->data,strlen(packet->data));
160161
state.seqnum = packet->seqnum + 1;
161162
ack_packet->seqnum = state.seqnum;
162163
ack_packet->checksum = 0;
163164
is_seq = true;
165+
return strlen(packet->data);
164166
}else {
165167
printf("INFO: DATA packet has the incorrect sequence number.\n");
166168
ack_packet->seqnum = state.seqnum;

go-back-n/gbn.o

168 Bytes
Binary file not shown.

go-back-n/hello.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,5 @@ Hello World !
109109
Hello World !
110110
./receiver 10000 r.txt
111111
./sender localhost 10000 hello.txt
112+
*****************
113+
THE END

go-back-n/receiver

56 Bytes
Binary file not shown.

go-back-n/sender

48 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)