Lines Matching +full:pkt +full:- +full:size

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
46 #include "tftp-file.h"
47 #include "tftp-io.h"
48 #include "tftp-utils.h"
49 #include "tftp-options.h"
54 static int send_packet(int peer, uint16_t block, char *pkt, int size);
69 { -1, NULL }
93 for (pe = errmsgs; pe->e_code >= 0; pe++) in errtomsg()
94 if (pe->e_code == error) in errtomsg()
95 return (pe->e_msg); in errtomsg()
101 send_packet(int peer, uint16_t block, char *pkt, int size) in send_packet() argument
109 if (sendto(peer, pkt, size, 0, (struct sockaddr *)&peer_sock, in send_packet()
110 peer_sock.ss_len) == size) { in send_packet()
115 (pkt))->th_opcode)), block, i); in send_packet()
120 packettype(ntohs(((struct tftphdr *)(pkt))->th_opcode)), in send_packet()
150 tp->th_opcode = htons((u_short)ERROR); in send_error()
151 tp->th_code = htons((u_short)error); in send_error()
152 for (pe = errmsgs; pe->e_code >= 0; pe++) in send_error()
153 if (pe->e_code == error) in send_error()
155 if (pe->e_code < 0) { in send_error()
156 pe->e_msg = strerror(error - 100); in send_error()
157 tp->th_code = EUNDEF; /* set 'undef' errorcode */ in send_error()
159 snprintf(tp->th_msg, MAXPKTSIZE - 4, "%s%n", pe->e_msg, &length); in send_error()
163 tftp_log(LOG_DEBUG, "Sending ERROR %d: %s", error, tp->th_msg); in send_error()
180 int size; in send_wrq() local
190 tp->th_opcode = htons((u_short)WRQ); in send_wrq()
191 size = offsetof(struct tftphdr, th_stuff); in send_wrq()
193 bp = tp->th_stuff; in send_wrq()
194 strlcpy(bp, filename, sizeof(buf) - size); in send_wrq()
198 size += strlen(filename) + 1; in send_wrq()
200 strlcpy(bp, mode, sizeof(buf) - size); in send_wrq()
204 size += strlen(mode) + 1; in send_wrq()
207 size += make_options(peer, bp, sizeof(buf) - size); in send_wrq()
209 n = sendto(peer, buf, size, 0, in send_wrq()
211 if (n != size) { in send_wrq()
228 int size; in send_rrq() local
238 tp->th_opcode = htons((u_short)RRQ); in send_rrq()
239 size = offsetof(struct tftphdr, th_stuff); in send_rrq()
241 bp = tp->th_stuff; in send_rrq()
242 strlcpy(bp, filename, sizeof(buf) - size); in send_rrq()
246 size += strlen(filename) + 1; in send_rrq()
248 strlcpy(bp, mode, sizeof(buf) - size); in send_rrq()
252 size += strlen(mode) + 1; in send_rrq()
256 size += make_options(peer, bp, sizeof(buf) - size); in send_rrq()
259 n = sendto(peer, buf, size, 0, in send_rrq()
261 if (n != size) { in send_rrq()
275 int size, i, n; in send_oack() local
290 size = sizeof(buf) - 2; in send_oack()
291 tp->th_opcode = htons((u_short)OACK); in send_oack()
294 n = snprintf(bp, size, "%s%c%s", options[i].o_type, in send_oack()
297 size -= n+1; in send_oack()
298 if (size < 0) { in send_oack()
304 size = bp - buf; in send_oack()
306 if (sendto(peer, buf, size, 0, in send_oack()
307 (struct sockaddr *)&peer_sock, peer_sock.ss_len) != size) { in send_oack()
322 int size; in send_ack() local
331 tp->th_opcode = htons((u_short)ACK); in send_ack()
332 tp->th_block = htons((u_short)block); in send_ack()
333 size = 4; in send_ack()
335 if (sendto(fp, buf, size, 0, in send_ack()
336 (struct sockaddr *)&peer_sock, peer_sock.ss_len) != size) { in send_ack()
348 send_data(int peer, uint16_t block, char *data, int size) in send_data() argument
351 struct tftphdr *pkt; in send_data() local
356 block, size); in send_data()
360 pkt = (struct tftphdr *)buf; in send_data()
362 pkt->th_opcode = htons((u_short)DATA); in send_data()
363 pkt->th_block = htons((u_short)block); in send_data()
364 memcpy(pkt->th_data, data, size); in send_data()
366 n = send_packet(peer, block, (char *)pkt, size + 4); in send_data()
377 receive_packet(int peer, char *data, int size, struct sockaddr_storage *from, in receive_packet() argument
381 struct tftphdr *pkt; in receive_packet() local
391 pkt = (struct tftphdr *)data; in receive_packet()
395 if (poll(&pfd, 1, 1000 * (timeout < 0 ? -timeout : timeout)) < 1) { in receive_packet()
403 n = recvfrom(peer, data, size, 0, (struct sockaddr *)pfrom, &fromlen); in receive_packet()
418 pkt->th_opcode = ntohs((u_short)pkt->th_opcode); in receive_packet()
419 if (pkt->th_opcode == DATA || in receive_packet()
420 pkt->th_opcode == ACK) in receive_packet()
421 pkt->th_block = ntohs((u_short)pkt->th_block); in receive_packet()
423 if (pkt->th_opcode == DATA && n > pktsize) { in receive_packet()
428 if (((struct sockaddr_in *)(pfrom))->sin_addr.s_addr != in receive_packet()
429 ((struct sockaddr_in *)(&peer_sock))->sin_addr.s_addr) { in receive_packet()
435 if (pkt->th_opcode == ERROR) { in receive_packet()
436 tftp_log(pkt->th_code == EUNDEF ? LOG_DEBUG : LOG_ERR, in receive_packet()
437 "Got ERROR packet: %s", pkt->th_msg); in receive_packet()
443 n, packettype(pkt->th_opcode)); in receive_packet()
445 return n - 4; in receive_packet()