Skip to content

Commit 45554bf

Browse files
committed
Merge remote-tracking branch 'bytesgalore/rpl_udp_send_buffer'
2 parents aeb5316 + b9e5c94 commit 45554bf

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

examples/rpl_udp/udp.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,21 @@ int udp_send(int argc, char **argv)
102102
ipv6_addr_t ipaddr;
103103
int bytes_sent;
104104
int address;
105-
char text[5];
106105

107106
if (argc != 3) {
108107
printf("usage: send <addr> <text>\n");
109108
return 1;
110109
}
111110

112-
address = atoi(argv[1]);
111+
/* max payload size = MTU - MAC - AES - IPV6_HDR_LEN - UDP_HDR_LEN
112+
* 33 = 127 - 25 - 21 - 40 - 8
113+
*/
114+
if (strlen(argv[2]) > 32) {
115+
puts("<text> is too large to be sent (max. 33 characters).");
116+
return 1;
117+
}
113118

114-
strncpy(text, argv[2], sizeof(text));
115-
text[sizeof(text) - 1] = 0;
119+
address = atoi(argv[1]);
116120

117121
sock = socket_base_socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP);
118122

@@ -134,8 +138,8 @@ int udp_send(int argc, char **argv)
134138
memcpy(&sa.sin6_addr, &ipaddr, 16);
135139
sa.sin6_port = HTONS(SERVER_PORT);
136140

137-
bytes_sent = socket_base_sendto(sock, (char *)text,
138-
strlen(text) + 1, 0, &sa,
141+
bytes_sent = socket_base_sendto(sock, argv[2],
142+
strlen(argv[2]), 0, &sa,
139143
sizeof(sa));
140144

141145
if (bytes_sent < 0) {

0 commit comments

Comments
 (0)