PUD: add getOlsrMessageOriginator function
authorFerry Huberts <f.huberts@mindef.nl>
Thu, 4 Aug 2011 11:16:02 +0000 (13:16 +0200)
committerFerry Huberts <f.huberts@mindef.nl>
Thu, 18 Aug 2011 13:13:11 +0000 (15:13 +0200)
Signed-off-by: Ferry Huberts <f.huberts@mindef.nl>
lib/pud/src/nodeIdConversion.c
lib/pud/src/pud.c
lib/pud/src/wireFormat.c
lib/pud/src/wireFormat.h

index 4834b5f..03606d9 100644 (file)
@@ -244,14 +244,7 @@ void getNodeIdStringFromOlsr(int ipVersion, union olsr_message *olsrMessage,
 
        /* message has NO nodeId information */
        noId: {
-               const void * addr;
-
-               if (ipVersion == AF_INET) {
-                       addr = (const void *) &olsrMessage->v4.originator;
-               } else {
-                       addr = (const void *) &olsrMessage->v6.originator;
-               }
-
+               void * addr = getOlsrMessageOriginator(ipVersion, olsrMessage);
                *nodeId = inet_ntop(ipVersion, addr, nodeIdBuffer, nodeIdBufferSize);
        }
 
index 2daacfd..d9d0cd1 100644 (file)
@@ -119,7 +119,8 @@ static void sendToAllTxInterfaces(unsigned char *buffer,
  */
 bool packetReceivedFromOlsr(union olsr_message *olsrMessage,
                struct interface *in_if __attribute__ ((unused)), union olsr_ip_addr *ipaddr __attribute__ ((unused))) {
-       const union olsr_ip_addr * originator;
+       const union olsr_ip_addr * originator = getOlsrMessageOriginator(
+                       olsr_cnf->ip_version, olsrMessage);
        unsigned int transmitStringLength;
        unsigned char buffer[BUFFER_SIZE_FROM_OLSR];
 
@@ -129,12 +130,10 @@ bool packetReceivedFromOlsr(union olsr_message *olsrMessage,
 
        /* determine the originator of the messsage */
        if (olsr_cnf->ip_version == AF_INET) {
-               originator = (const union olsr_ip_addr *) &olsrMessage->v4.originator;
 #ifdef PUD_DUMP_GPS_PACKETS_RX_OLSR
                olsrMessageSize = ntohs(olsrMessage->v4.olsr_msgsize);
 #endif
        } else {
-               originator = (const union olsr_ip_addr *) &olsrMessage->v6.originator;
 #ifdef PUD_DUMP_GPS_PACKETS_RX_OLSR
                olsrMessageSize = ntohs(olsrMessage->v6.olsr_msgsize);
 #endif
index 8956597..be7462d 100644 (file)
  * GPS Information Conversion Functions For OLSR GPS Wire Format
  */
 
+/* ************************************************************************
+ * OLSR Header
+ * ************************************************************************ */
+
+/**
+ Determine the originator of an OLSR message
+
+ @param ipVersion
+ The IP version
+ @param olsrMessage
+ A pointer to the OLSR message
+ @return
+ A pointer to the originator address
+ */
+inline union olsr_ip_addr * getOlsrMessageOriginator(int ipVersion,
+               union olsr_message * olsrMessage) {
+       if (ipVersion == AF_INET) {
+               return (union olsr_ip_addr *) &olsrMessage->v4.originator;
+       }
+
+       return (union olsr_ip_addr *) &olsrMessage->v6.originator;
+}
+
 /* ************************************************************************
  * VALIDITY TIME
  * ************************************************************************ */
index 7aa6bb9..7c13a21 100644 (file)
@@ -197,6 +197,13 @@ typedef struct _PudOlsrWireFormat {
  * FUNCTIONS
  * ************************************************************************ */
 
+/*
+ * OLSR header
+ */
+
+union olsr_ip_addr * getOlsrMessageOriginator(int ipVersion,
+               union olsr_message * olsrMessage);
+
 /*
  * PudOlsrWireFormat
  */