Lines Matching refs:packet
181 static inline int check_data( uint8_t *packet, uint16_t *opcode, in check_data() argument
184 *opcode = (uint16_t) packet[0] << 8 | (uint16_t) packet[1]; in check_data()
186 *blockno = (uint16_t) packet[2] << 8 | (uint16_t) packet[3]; in check_data()
193 static int mkpkt_data(int fd, off_t offset, uint8_t *packet, uint16_t blockno) in mkpkt_data() argument
198 packet[0] = TFTP_OP_DATA >> 8; in mkpkt_data()
199 packet[1] = TFTP_OP_DATA & 0xff; in mkpkt_data()
200 packet[2] = blockno >> 8; in mkpkt_data()
201 packet[3] = blockno & 0xff; in mkpkt_data()
207 nbytesread = readall(fd, &packet[TFTP_DATAHEADERSIZE], TFTP_DATASIZE); in mkpkt_data()
213 static int read_ack(int sd, uint8_t *packet, struct sockaddr_storage *server, in read_ack() argument
223 nbytes = read_server(sd, packet, TFTP_IOBUFSIZE, &from); in read_ack()
242 packetlen = mkpkt_err(packet, TFTP_ER_UNKID, TFTP_ES_UNKID); in read_ack()
243 (void) write_server(sd, packet, packetlen, server); in read_ack()
246 opcode = (uint16_t) packet[0] << 8 | (uint16_t) packet[1]; in read_ack()
247 rblockno = (uint16_t) packet[2] << 8 | (uint16_t) packet[3]; in read_ack()
252 packetlen = mkpkt_err(packet, TFTP_ER_ILLEGALOP, TFTP_ES_ILLEGALOP); in read_ack()
253 (void) write_server(sd, packet, packetlen, server); in read_ack()
270 uint8_t *packet; in file_get() local
276 packet = (uint8_t*) xzalloc(TFTP_IOBUFSIZE); in file_get()
279 len = mkpkt_request(packet, TFTP_OP_RRQ, TT.remote_file, 1); in file_get()
280 ret = write_server(sd, packet, len, &server); in file_get()
291 nbytesrecvd = read_server(sd, packet, TFTP_IOBUFSIZE, &from); in file_get()
312 len = mkpkt_err(packet, TFTP_ER_UNKID, TFTP_ES_UNKID); in file_get()
313 ret = write_server(sd, packet, len, &from); in file_get()
321 if (check_data(packet, &opcode, &rblockno) != 0 in file_get()
334 len = mkpkt_ack(packet, 0); in file_get()
335 ret = write_server(sd, packet, len, &from); in file_get()
342 len = mkpkt_err(packet, TFTP_ER_ILLEGALOP, TFTP_ES_ILLEGALOP); in file_get()
343 ret = write_server(sd, packet, len, &from); in file_get()
362 if (writeall(fd, packet + TFTP_DATAHEADERSIZE, ndatabytes) < 0){ in file_get()
366 len = mkpkt_ack(packet, blockno); in file_get()
367 ret = write_server(sd, packet, len, &server); in file_get()
377 free(packet); in file_get()
385 uint8_t *packet; in file_put() local
391 packet = (uint8_t*)xzalloc(TFTP_IOBUFSIZE); in file_put()
395 packetlen = mkpkt_request(packet, TFTP_OP_WRQ, TT.remote_file, 1); in file_put()
396 ret = write_server(sd, packet, packetlen, &server); in file_put()
398 if (read_ack(sd, packet, &server, &port, NULL) == 0) break; in file_put()
405 packetlen = mkpkt_data(fd, offset, packet, blockno); in file_put()
408 ret = write_server(sd, packet, packetlen, &server); in file_put()
411 if (read_ack(sd, packet, &server, &port, &rblockno) == 0) { in file_put()
428 free(packet); in file_put()