Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

UDP destination address returned by recvmsg is wrong/invalid #76

Open
cwmos opened this issue Apr 24, 2018 · 0 comments
Open

UDP destination address returned by recvmsg is wrong/invalid #76

cwmos opened this issue Apr 24, 2018 · 0 comments

Comments

@cwmos
Copy link

cwmos commented Apr 24, 2018

Below is a fix for this problem below. Together with other fixes I have reported recently, the fix below made the (high quality) program I tried to run with DCE actually work. The fix only applies to IPv4. I think the same problem exists for IPv6 and can be fixed in the same way though some additions to ipv6-packet-info-tag.cc in NS3 would be needed.

First, this patch for ns-3.26 is needed. It sets the source and destination (local) addresses in the Ipv4PacketInfoTag in the ForwardUp method. Actually, only the destination address is needed to solve this particular problem but it seems like a bug the other one is not set.

diff -r /home/user/dce.clean/source/ns-3.26/src/internet/model/udp-socket-impl.cc ./src/internet/model/udp-socket-impl.cc
1001a1002,1003
>       tag.SetLocalAddress(header.GetDestination());
>       tag.SetAddress(header.GetSource());

Second, this patch for DCE 1.9 is needed. It uses the information set by NS-3 above and also includes an extra memset to avoid passing undefined values to the user:

diff --git a/model/unix-datagram-socket-fd.cc b/model/unix-datagram-socket-fd.cc
index 690b0e0..a6577a2 100644
--- a/model/unix-datagram-socket-fd.cc
+++ b/model/unix-datagram-socket-fd.cc
@@ -234,12 +234,10 @@ UnixDatagramSocketFd::DoRecvmsg (struct msghdr *msg, int flags)
               if (isTagPresent)
                 {
                   struct in_pktinfo pkt;
+                  memset(&pkt,0,sizeof(pkt));
                   Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
                   pkt.ipi_ifindex = ipv4->GetInterfaceForDevice (node->GetDevice (ipv4Tag.GetRecvIf ()));
-                  if (msg->msg_name)
-                    {
-                      memcpy (&pkt.ipi_addr, msg->msg_name, sizeof (pkt.ipi_addr));
-                    }
+                  pkt.ipi_addr.s_addr=htonl(ipv4Tag.GetLocalAddress().Get());
                   cmsg.Add (SOL_IP, IP_PKTINFO, sizeof (struct in_pktinfo), (const uint8_t *)&pkt);
 
                   NS_LOG_DEBUG ("ipv4 tag, iface: " <<  pkt.ipi_ifindex);
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant