According to the documentation, sendto() should either send the packet
as given or return with an error. However, given that it can return
the number of bytes sent, treat the theoretical error of a short
packet send separately, since errno would not be set in this case.
Similarly, treat a short packet recv() separately from an error where
errno is set.
Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
sizeof(dest->ip));
saved_errno = errno;
close(s);
- if (ret != len) {
+ if (ret == -1) {
D_ERR("Failed sendto (%s)\n", strerror(saved_errno));
return -1;
}
+ if ((size_t)ret != len) {
+ DBG_ERR("Failed sendto - didn't send full packet\n");
+ return -1;
+ }
break;
case AF_INET6:
sizeof(tmpdest));
saved_errno = errno;
close(s);
-
- if (ret != len) {
+ if (ret == -1) {
D_ERR("Failed sendto (%s)\n", strerror(saved_errno));
return -1;
}
+ if ((size_t)ret != len) {
+ DBG_ERR("Failed sendto - didn't send full packet\n");
+ return -1;
+ }
break;
default:
int ret;
nread = recv(s, pkt, sizeof(pkt), MSG_TRUNC);
- if (nread < sizeof(*eth)) {
+ if (nread == -1) {
+ return errno;
+ }
+ if ((size_t)nread < sizeof(*eth)) {
return EMSGSIZE;
}