/* Send a write request to the server. 1. Format message. 2. Send the request using the connection handle. 3. Return the number of bytes sent, or negative on error. */ int tftp_send_wrq(struct tftp_conn *tc) { int reqlen = TFTP_WRQ_LEN(tc->fname, tc->mode); struct tftp_wrq *wrq; if((wrq = malloc(reqlen)) == NULL) return -1; wrq->opcode = htons(OPCODE_WRQ); strcpy (&wrq->req[0], tc->fname); strcpy (&wrq->req[strlen(tc->fname) + 1], tc->mode); // Save the message in the msgbuffer memcpy(tc->msgbuf, wrq, reqlen); size_t size = sendto(tc->sock, wrq, reqlen, 0, (struct sockaddr *) &tc->peer_addr, tc->addrlen); printf("SENT WRQ\n"); free(wrq); print_message((struct tftp_msg *) tc->msgbuf, 0); return size; }
/* Send a write request to the server. 1. Format message. 2. Send the request using the connection handle. 3. Return the number of bytes sent, or negative on error. */ int tftp_send_wrq(struct tftp_conn *tc) { /* ===ADDED/CHANGED=== */ struct tftp_wrq *wrq; wrq = malloc(TFTP_WRQ_LEN(tc->fname,tc->mode)); wrq->opcode = htons(OPCODE_WRQ); int index = snprintf(wrq->req, BLOCK_SIZE, "%s", tc->fname); index++; snprintf((wrq->req + index), (BLOCK_SIZE - index - 1), "%s", tc->mode); int bytes_sent = sendto(tc->sock, wrq, TFTP_WRQ_LEN(tc->fname, tc->mode), 0, (struct sockaddr *) &(tc->peer_addr), tc->addrlen); free(wrq); return bytes_sent; /* ===END OF ADDED/CHANGED=== */ }