PUD: pud: make IPv6 work in sendToAllTxInterfaces
authorFerry Huberts <ferry.huberts@pelagic.nl>
Mon, 4 Jun 2012 07:39:57 +0000 (09:39 +0200)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Thu, 7 Jun 2012 22:30:03 +0000 (00:30 +0200)
Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
lib/pud/src/pud.c

index 738ee89..54fbc7e 100644 (file)
@@ -82,16 +82,24 @@ void pudError(bool useErrno, const char *format, ...) {
  */
 static void sendToAllTxInterfaces(unsigned char *buffer,
                unsigned int bufferLength) {
-       union olsr_sockaddr * txAddress;
+       union olsr_sockaddr * txAddress = getTxMcAddr();
+       struct sockaddr * addr;
+       socklen_t addrSize;
        TRxTxNetworkInterface *txNetworkInterfaces = getTxNetworkInterfaces();
+
+       if (txAddress->in.sa_family == AF_INET) {
+               addr = (struct sockaddr *)&txAddress->in4;
+               addrSize = sizeof(struct sockaddr_in);
+       } else {
+               addr = (struct sockaddr *)&txAddress->in6;
+               addrSize = sizeof(struct sockaddr_in6);
+       }
+
        while (txNetworkInterfaces != NULL) {
                TRxTxNetworkInterface *networkInterface = txNetworkInterfaces;
                errno = 0;
-               txAddress = getTxMcAddr();
-               if (sendto(networkInterface->socketFd, buffer, bufferLength, 0,
-                               (struct sockaddr *) &txAddress->in, sizeof(txAddress->in)) < 0) {
-                       pudError(true, "Transmit error on interface %s",
-                                       (char *) &networkInterface->name);
+               if (sendto(networkInterface->socketFd, buffer, bufferLength, 0, addr, addrSize) < 0) {
+                       pudError(true, "Transmit error on interface %s", (char *) &networkInterface->name);
                }
                txNetworkInterfaces = networkInterface->next;
        }