mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-18 20:57:56 +00:00
Better error logging for recvwithttl()
This commit is contained in:
parent
16995f1041
commit
72482b3427
@ -248,6 +248,8 @@ int overlay_mdp_recv(int mdp_sockfd, overlay_mdp_frame *mdp, mdp_port_t port, in
|
||||
mdp->packetTypeAndFlags = 0;
|
||||
set_nonblock(mdp_sockfd);
|
||||
len = recvwithttl(mdp_sockfd, (unsigned char *)mdp, sizeof(overlay_mdp_frame), ttl, (struct sockaddr *)&recvaddr, &recvaddrlen);
|
||||
if (len == -1)
|
||||
WHYF_perror("recvwithttl(%d,%p,%zu,&%d,%p,%p)", mdp_sockfd, mdp, sizeof(overlay_mdp_frame), *ttl, &recvaddr, &recvaddrlen);
|
||||
set_block(mdp_sockfd);
|
||||
if (len <= 0)
|
||||
return -1; // no packet received
|
||||
|
13
net.c
13
net.c
@ -143,7 +143,7 @@ ssize_t recvwithttl(int sock,unsigned char *buffer, size_t bufferlen,int *ttl,
|
||||
{
|
||||
struct msghdr msg;
|
||||
struct iovec iov[1];
|
||||
|
||||
struct cmsghdr cmsgcmsg[16];
|
||||
iov[0].iov_base=buffer;
|
||||
iov[0].iov_len=bufferlen;
|
||||
bzero(&msg,sizeof(msg));
|
||||
@ -151,18 +151,13 @@ ssize_t recvwithttl(int sock,unsigned char *buffer, size_t bufferlen,int *ttl,
|
||||
msg.msg_namelen = *recvaddrlen;
|
||||
msg.msg_iov = &iov[0];
|
||||
msg.msg_iovlen = 1;
|
||||
// setting the following makes the data end up in the wrong place
|
||||
// msg.msg_iov->iov_base=iov_buffer;
|
||||
// msg.msg_iov->iov_len=sizeof(iov_buffer);
|
||||
|
||||
struct cmsghdr cmsgcmsg[16];
|
||||
msg.msg_control = &cmsgcmsg[0];
|
||||
msg.msg_controllen = sizeof(struct cmsghdr)*16;
|
||||
msg.msg_control = cmsgcmsg;
|
||||
msg.msg_controllen = sizeof cmsgcmsg;
|
||||
msg.msg_flags = 0;
|
||||
|
||||
ssize_t len = recvmsg(sock,&msg,0);
|
||||
if (len == -1 && errno != EAGAIN && errno != EWOULDBLOCK)
|
||||
return WHY_perror("recvmsg");
|
||||
return WHYF_perror("recvmsg(%d,%p,0)", sock, &msg);
|
||||
|
||||
#if 0
|
||||
if (config.debug.packetrx) {
|
||||
|
@ -258,9 +258,9 @@ overlay_interface_read_any(struct sched_ent *alarm){
|
||||
|
||||
/* Read only one UDP packet per call to share resources more fairly, and also
|
||||
enable stats to accurately count packets received */
|
||||
plen = recvwithttl(alarm->poll.fd, packet, sizeof(packet), &recvttl, &src_addr, &addrlen);
|
||||
plen = recvwithttl(alarm->poll.fd, packet, sizeof packet, &recvttl, &src_addr, &addrlen);
|
||||
if (plen == -1) {
|
||||
WHY_perror("recvwithttl(c)");
|
||||
WHYF_perror("recvwithttl(%d,%p,%zu,&%d,%p,%p)", alarm->poll.fd, packet, sizeof packet, recvttl, &src_addr, &addrlen);
|
||||
unwatch(alarm);
|
||||
close(alarm->poll.fd);
|
||||
return;
|
||||
@ -584,9 +584,9 @@ static void interface_read_dgram(struct overlay_interface *interface){
|
||||
/* Read only one UDP packet per call to share resources more fairly, and also
|
||||
enable stats to accurately count packets received */
|
||||
int recvttl=1;
|
||||
plen = recvwithttl(interface->alarm.poll.fd,packet, sizeof(packet), &recvttl, &src_addr, &addrlen);
|
||||
plen = recvwithttl(interface->alarm.poll.fd, packet, sizeof packet, &recvttl, &src_addr, &addrlen);
|
||||
if (plen == -1) {
|
||||
WHY_perror("recvwithttl(c)");
|
||||
WHYF_perror("recvwithttl(%d,%p,%zu,&%d,%p,%p)", interface->alarm.poll.fd, packet, sizeof packet, recvttl, &src_addr, &addrlen);
|
||||
overlay_interface_close(interface);
|
||||
return;
|
||||
}
|
||||
|
@ -1138,7 +1138,9 @@ static void mdp_poll2(struct sched_ent *alarm)
|
||||
};
|
||||
int ttl=-1;
|
||||
|
||||
ssize_t len = recvwithttl(alarm->poll.fd, buffer, sizeof(buffer), &ttl, (struct sockaddr *)&addr, &client.addrlen);
|
||||
ssize_t len = recvwithttl(alarm->poll.fd, buffer, sizeof buffer, &ttl, (struct sockaddr *)&addr, &client.addrlen);
|
||||
if (len == -1)
|
||||
WHYF_perror("recvwithttl(%d,%p,%zu,&%d,%p,%p)", alarm->poll.fd, buffer, sizeof buffer, ttl, &addr, &client.addrlen);
|
||||
|
||||
if (len<sizeof(struct mdp_header)){
|
||||
WHYF("Expected length %d, got %d from %s", (int)sizeof(struct mdp_header), (int)len, alloca_sockaddr(client.addr, client.addrlen));
|
||||
@ -1184,14 +1186,16 @@ static void overlay_mdp_poll(struct sched_ent *alarm)
|
||||
unsigned char buffer[16384];
|
||||
int ttl;
|
||||
unsigned char recvaddrbuffer[1024];
|
||||
struct sockaddr *recvaddr=(struct sockaddr *)&recvaddrbuffer[0];
|
||||
socklen_t recvaddrlen=sizeof(recvaddrbuffer);
|
||||
struct sockaddr *recvaddr = (struct sockaddr *)recvaddrbuffer;
|
||||
socklen_t recvaddrlen = sizeof recvaddrbuffer;
|
||||
struct sockaddr_un *recvaddr_un=NULL;
|
||||
|
||||
ttl=-1;
|
||||
bzero((void *)recvaddrbuffer,sizeof(recvaddrbuffer));
|
||||
|
||||
ssize_t len = recvwithttl(alarm->poll.fd,buffer,sizeof(buffer),&ttl, recvaddr, &recvaddrlen);
|
||||
ssize_t len = recvwithttl(alarm->poll.fd, buffer, sizeof buffer, &ttl, recvaddr, &recvaddrlen);
|
||||
if (len == -1)
|
||||
WHYF_perror("recvwithttl(%d,%p,%zu,&%d,%p,%p)", alarm->poll.fd, buffer, sizeof buffer, ttl, recvaddr, &recvaddrlen);
|
||||
recvaddr_un=(struct sockaddr_un *)recvaddr;
|
||||
|
||||
if (len > 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user