gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r8160 - in GNUnet/src: applications/getoption applications/


From: gnunet
Subject: [GNUnet-SVN] r8160 - in GNUnet/src: applications/getoption applications/identity applications/stats applications/tbench applications/tracekit applications/traffic include server util/os
Date: Sun, 1 Feb 2009 19:51:33 -0700 (MST)

Author: grothoff
Date: 2009-02-01 19:51:33 -0700 (Sun, 01 Feb 2009)
New Revision: 8160

Modified:
   GNUnet/src/applications/getoption/getoption.c
   GNUnet/src/applications/identity/identity.h
   GNUnet/src/applications/stats/clientapi.c
   GNUnet/src/applications/stats/statistics.c
   GNUnet/src/applications/stats/statistics.h
   GNUnet/src/applications/tbench/tbench.h
   GNUnet/src/applications/tracekit/tracekit.h
   GNUnet/src/applications/traffic/clientapi.c
   GNUnet/src/applications/traffic/traffic.c
   GNUnet/src/applications/traffic/traffic.h
   GNUnet/src/include/chat.h
   GNUnet/src/include/dht.h
   GNUnet/src/include/dv.h
   GNUnet/src/include/fs.h
   GNUnet/src/include/gnunet_util_common.h
   GNUnet/src/include/gnunet_util_core.h
   GNUnet/src/include/gnunet_util_crypto.h
   GNUnet/src/include/gnunet_util_network.h
   GNUnet/src/server/connection.h
   GNUnet/src/util/os/console.c
Log:
fixing Mantis 1429

Modified: GNUnet/src/applications/getoption/getoption.c
===================================================================
--- GNUnet/src/applications/getoption/getoption.c       2009-02-01 07:48:08 UTC 
(rev 8159)
+++ GNUnet/src/applications/getoption/getoption.c       2009-02-02 02:51:33 UTC 
(rev 8160)
@@ -41,6 +41,7 @@
   CS_getoption_reply_MESSAGE *rep;
   char *val;
   int ret;
+  size_t vlen;
 
   if (ntohs (message->size) != sizeof (CS_getoption_request_MESSAGE))
     return GNUNET_SYSERR;
@@ -58,10 +59,10 @@
                                                       NULL, &val))
       || (val == NULL))
     return GNUNET_SYSERR;       /* signal error: option not set */
-
-  rep = GNUNET_malloc (sizeof (GNUNET_MessageHeader) + strlen (val) + 1);
-  rep->header.size = htons (sizeof (GNUNET_MessageHeader) + strlen (val) + 1);
-  memcpy (rep->value, val, strlen (val) + 1);
+  vlen = strlen(val) + 1;
+  rep = GNUNET_malloc (sizeof (GNUNET_MessageHeader) + vlen);
+  rep->header.size = htons (sizeof (GNUNET_MessageHeader) + vlen);
+  memcpy (rep->value, val, vlen);
   rep->header.type = htons (GNUNET_CS_PROTO_GET_OPTION_REPLY);
   ret = coreAPI->cs_send_message (sock, &rep->header, GNUNET_YES);
   GNUNET_free (rep);

Modified: GNUnet/src/applications/identity/identity.h
===================================================================
--- GNUnet/src/applications/identity/identity.h 2009-02-01 07:48:08 UTC (rev 
8159)
+++ GNUnet/src/applications/identity/identity.h 2009-02-02 02:51:33 UTC (rev 
8160)
@@ -57,13 +57,13 @@
 {
   GNUNET_MessageHeader header;
 
-  unsigned int trust;
+  unsigned int trust GNUNET_PACKED;
 
   GNUNET_PeerIdentity peer;
 
-  GNUNET_CronTime last_message;
+  GNUNET_CronTime last_message GNUNET_PACKED;
 
-  unsigned int bpm;
+  unsigned int bpm GNUNET_PACKED;
 } CS_identity_peer_info_MESSAGE;
 
 

Modified: GNUnet/src/applications/stats/clientapi.c
===================================================================
--- GNUnet/src/applications/stats/clientapi.c   2009-02-01 07:48:08 UTC (rev 
8159)
+++ GNUnet/src/applications/stats/clientapi.c   2009-02-02 02:51:33 UTC (rev 
8160)
@@ -294,17 +294,24 @@
                              void *cls)
 {
   CS_stats_reply_MESSAGE *statMsg;
+  const unsigned long long * values;
+  const char * text;
   GNUNET_MessageHeader csHdr;
   unsigned int count;
   unsigned int i;
-  int mpos;
+  unsigned int mcnt;
+  unsigned int moff;
   int ret;
+  size_t slen;
+  unsigned short mlen;
 
   ret = GNUNET_OK;
   csHdr.size = htons (sizeof (GNUNET_MessageHeader));
   csHdr.type = htons (GNUNET_CS_PROTO_STATS_GET_STATISTICS);
   if (GNUNET_SYSERR == GNUNET_client_connection_write (sock, &csHdr))
-    return GNUNET_SYSERR;
+    {
+      return GNUNET_SYSERR;
+    }
   statMsg = GNUNET_malloc (sizeof (CS_stats_reply_MESSAGE));
   statMsg->totalCounters = htonl (1);   /* to ensure we enter the loop */
   count = 0;
@@ -316,16 +323,24 @@
          count, ntohl(statMsg->totalCounters) ); */
       if (GNUNET_SYSERR ==
           GNUNET_client_connection_read (sock,
-                                         (GNUNET_MessageHeader **) & statMsg))
+                                         (GNUNET_MessageHeader **) &statMsg))
         return GNUNET_SYSERR;
-      if ((ntohs (statMsg->header.size) < sizeof (CS_stats_reply_MESSAGE)) ||
-          (((char *) statMsg)[ntohs (statMsg->header.size) - 1] != '\0'))
+      mlen = ntohs(statMsg->header.size);
+      if ((mlen < sizeof (CS_stats_reply_MESSAGE)) ||
+          (((const char *) statMsg)[mlen - 1] != '\0'))
         {
           GNUNET_GE_BREAK (ectx, 0);
           ret = GNUNET_SYSERR;
           break;
         }
-      mpos = sizeof (unsigned long long) * ntohl (statMsg->statCounters);
+      mcnt = ntohl (statMsg->statCounters);
+      if ( (sizeof(CS_stats_reply_MESSAGE) + mcnt * sizeof(unsigned long long) 
+ mcnt
+           > mlen) )
+       {
+          GNUNET_GE_BREAK (ectx, 0);
+          ret = GNUNET_SYSERR;
+          break;
+       }
       if (count == 0)
         {
           ret = processor (_("Uptime (seconds)"),
@@ -334,14 +349,14 @@
                              GNUNET_ntohll (statMsg->startTime)) /
                             GNUNET_CRON_SECONDS), cls);
         }
-      for (i = 0; i < ntohl (statMsg->statCounters); i++)
+      moff = 0;
+      values = (const unsigned long long*) &statMsg[1];
+      text = (const char*) &values[mcnt];
+      for (i = 0; i < mcnt; i++)
         {
-          if (mpos +
-              strlen (&
-                      ((char
-                        *) (((CS_stats_reply_MESSAGE_GENERIC *)
-                             statMsg)->values))[mpos]) + 1 >
-              ntohs (statMsg->header.size) - sizeof (CS_stats_reply_MESSAGE))
+         slen = strlen(&text[moff]) + 1;
+          if (moff + slen >
+              mlen - sizeof (CS_stats_reply_MESSAGE) - sizeof(unsigned long 
long) * mcnt)
             {
               GNUNET_GE_BREAK (ectx, 0);
               ret = GNUNET_SYSERR;
@@ -350,20 +365,12 @@
           if (ret != GNUNET_SYSERR)
             {
               ret =
-                processor (&
-                           ((char
-                             *) (((CS_stats_reply_MESSAGE_GENERIC *)
-                                  statMsg)->values))[mpos],
-                           GNUNET_ntohll (((CS_stats_reply_MESSAGE_GENERIC *)
-                                           statMsg)->values[i]), cls);
+                processor (&text[moff],
+                           GNUNET_ntohll (values[i]), cls);
             }
-          mpos +=
-            strlen (&
-                    ((char
-                      *) (((CS_stats_reply_MESSAGE_GENERIC *)
-                           statMsg)->values))[mpos]) + 1;
+          moff += strlen (&text[moff]) + 1;
         }
-      count += ntohl (statMsg->statCounters);
+      count += mcnt;
     }                           /* end while */
   GNUNET_free (statMsg);
   return ret;

Modified: GNUnet/src/applications/stats/statistics.c
===================================================================
--- GNUnet/src/applications/stats/statistics.c  2009-02-01 07:48:08 UTC (rev 
8159)
+++ GNUnet/src/applications/stats/statistics.c  2009-02-02 02:51:33 UTC (rev 
8160)
@@ -303,18 +303,22 @@
                 const GNUNET_MessageHeader * originalRequestMessage)
 {
   CS_stats_reply_MESSAGE *statMsg;
-  int pos;                      /* position in the values-descriptions */
-  int start;
-  int end;
-  int mpos;                     /* postion in the message */
+  unsigned long long * values;
+  char * text;
+  unsigned int pos;
+  unsigned int start;
+  unsigned int end;
+  unsigned int mpos;
+  unsigned int moff;
+  unsigned int mcnt;
+  unsigned int msize;
 
   immediateUpdates ();
   statMsg = GNUNET_malloc (GNUNET_MAX_BUFFER_SIZE);
   statMsg->header.type = htons (GNUNET_CS_PROTO_STATS_STATISTICS);
   statMsg->totalCounters = htonl (statCounters);
-  statMsg->statCounters = htons (0);
   statMsg->startTime = GNUNET_htonll (startTime);
-
+  values = (unsigned long long*) &statMsg[1];
   start = 0;
   while (start < statCounters)
     {
@@ -322,40 +326,36 @@
       /* first pass: gauge how many statistic numbers
          and their descriptions we can send in one message */
       mpos = 0;
-      while ((pos < statCounters) &&
-             (mpos + sizeof (unsigned long long)
-              + entries[pos].descStrLen + 1
-              < GNUNET_MAX_BUFFER_SIZE - sizeof (CS_stats_reply_MESSAGE)))
+      moff = 0;
+      while ( (pos < statCounters) &&
+             (moff + sizeof (unsigned long long)
+              + entries[pos].descStrLen + 1
+              < GNUNET_MAX_BUFFER_SIZE - sizeof (CS_stats_reply_MESSAGE)))
         {
-          mpos += sizeof (unsigned long long);  /* value */
-          mpos += entries[pos].descStrLen + 1;
+          moff += sizeof (unsigned long long);  /* value */
+         values[pos - start] = GNUNET_htonll (entries[pos].value);
+          moff += entries[pos].descStrLen + 1;
           pos++;
         }
       end = pos;
-      /* second pass: copy values and messages to message */
+      mcnt = end - start;
+      statMsg->statCounters = htonl (mcnt);
+      /* second pass: copy messages to message */      
+      text = (char* ) &values[mcnt];
+      moff = 0;
       for (pos = start; pos < end; pos++)
-        ((CS_stats_reply_MESSAGE_GENERIC *) statMsg)->values[pos -
-                                                             start] =
-          GNUNET_htonll (entries[pos].value);
-      mpos = sizeof (unsigned long long) * (end - start);
-      for (pos = start; pos < end; pos++)
         {
-          memcpy (&
-                  ((char
-                    *) (((CS_stats_reply_MESSAGE_GENERIC *)
-                         statMsg))->values)[mpos], entries[pos].description,
+          memcpy (&text[moff], 
+                 entries[pos].description,
                   entries[pos].descStrLen + 1);
-          mpos += entries[pos].descStrLen + 1;
+          moff += entries[pos].descStrLen + 1;
         }
-      statMsg->statCounters = htonl (end - start);
+      msize = moff 
+       + sizeof(unsigned long long) * mcnt 
+       + sizeof (CS_stats_reply_MESSAGE);
       GNUNET_GE_ASSERT (NULL,
-                        mpos + sizeof (CS_stats_reply_MESSAGE) <
-                        GNUNET_MAX_BUFFER_SIZE);
-
-      statMsg->header.size = htons (mpos + sizeof (CS_stats_reply_MESSAGE));
-      /* printf("writing message of size %d with stats %d to %d out of %d to 
socket\n",
-         ntohs(statMsg->header.size),
-         start, end, statCounters); */
+                        msize < GNUNET_MAX_BUFFER_SIZE);
+      statMsg->header.size = htons (msize);
       if (GNUNET_SYSERR ==
           coreAPI->cs_send_message (sock, &statMsg->header, GNUNET_YES))
         break;                  /* abort, socket error! */

Modified: GNUnet/src/applications/stats/statistics.h
===================================================================
--- GNUnet/src/applications/stats/statistics.h  2009-02-01 07:48:08 UTC (rev 
8159)
+++ GNUnet/src/applications/stats/statistics.h  2009-02-02 02:51:33 UTC (rev 
8160)
@@ -31,6 +31,10 @@
  * Statistics message. Contains the timestamp and an aribtrary
  * (bounded by the maximum CS message size!) number of statistical
  * numbers. If needed, several messages are used.
+ *
+ * The struct is followed by statCounters 64-bit 
+ * integers which are then followed by 0-terminated
+ * strings.
  */
 typedef struct
 {
@@ -38,33 +42,24 @@
   /**
    * For 64-bit alignment...
    */
-  int reserved;
-  /* timestamp  (network byte order) */
-  GNUNET_CronTime startTime;
-  /* total number of statistical counters */
-  int totalCounters;
-  /* number of statistical counters in this message */
-  int statCounters;
+  int reserved GNUNET_PACKED;
 
-} CS_stats_reply_MESSAGE;
+  /**
+   * timestamp  (network byte order) 
+   */
+  GNUNET_CronTime startTime GNUNET_PACKED;
 
-/**
- * Generic version of CS_stats_reply_MESSAGE with field for finding the end
- * of the struct. Use the other version for allocation.
- */
-typedef struct
-{
-  CS_stats_reply_MESSAGE stats_cs_message;
+  /**
+   * total number of statistical counters 
+   */
+  unsigned int totalCounters GNUNET_PACKED;
 
-  /* values[statCounters] */
-  unsigned long long values[1];
+  /**
+   * number of statistical counters in this message 
+   */
+  unsigned int statCounters GNUNET_PACKED;
 
-  /* description for each of the values,
-     separated by '\0'-terminators; the
-     last description is also terminated
-     by a '\0'; again statCounters entries */
-  /* char descriptions[0]; */
-} CS_stats_reply_MESSAGE_GENERIC;
+} CS_stats_reply_MESSAGE;
 
 /**
  * Query protocol supported message.  Contains the type of
@@ -78,7 +73,7 @@
    * The type of the message (XX_CS_PROTO_XXXX)
    * we want to know the status of.
    */
-  unsigned short type;
+  unsigned short type GNUNET_PACKED;
 
   /**
    * 0 for plaintext P2P,
@@ -86,7 +81,7 @@
    * 2 for either plaintext or ciphertext P2P,
    * 3 for client-server
    */
-  unsigned short handlerType;
+  unsigned short handlerType GNUNET_PACKED;
 
 } CS_stats_get_supported_MESSAGE;
 

Modified: GNUnet/src/applications/tbench/tbench.h
===================================================================
--- GNUnet/src/applications/tbench/tbench.h     2009-02-01 07:48:08 UTC (rev 
8159)
+++ GNUnet/src/applications/tbench/tbench.h     2009-02-02 02:51:33 UTC (rev 
8160)
@@ -37,16 +37,16 @@
    * How big is each message (plus headers).
    * Note that GNUnet is limited to 64k messages.
    */
-  unsigned int msgSize;
+  unsigned int msgSize GNUNET_PACKED;
   /**
    * How many messages should be transmitted in
    * each iteration?
    */
-  unsigned int msgCnt;
+  unsigned int msgCnt GNUNET_PACKED;
   /**
    * How many iterations should be performed?
    */
-  unsigned int iterations;
+  unsigned int iterations GNUNET_PACKED;
   /**
    * Which peer should receive the messages?
    */
@@ -55,21 +55,21 @@
    * Inter packet space in milliseconds (delay
    * introduced when sending messages).
    */
-  GNUNET_CronTime intPktSpace;
+  GNUNET_CronTime intPktSpace GNUNET_PACKED;
   /**
    * Time to wait for the arrival of all repies
    * in one iteration.
    */
-  GNUNET_CronTime timeOut;
+  GNUNET_CronTime timeOut GNUNET_PACKED;
   /**
    * intPktSpace delay is only introduced every
    * trainSize messages.
    */
-  unsigned int trainSize;
+  unsigned int trainSize GNUNET_PACKED;
   /**
    * Which priority should be used?
    */
-  unsigned int priority;
+  unsigned int priority GNUNET_PACKED;
 } CS_tbench_request_MESSAGE;
 
 /**
@@ -78,15 +78,15 @@
 typedef struct
 {
   GNUNET_MessageHeader header;
-  unsigned int max_loss;
-  unsigned int min_loss;
-  float mean_loss;
-  float variance_loss;
+  unsigned int max_loss GNUNET_PACKED;
+  unsigned int min_loss GNUNET_PACKED;
+  float mean_loss GNUNET_PACKED;
+  float variance_loss GNUNET_PACKED;
 
-  GNUNET_CronTime max_time;
-  GNUNET_CronTime min_time;
-  float mean_time;
-  float variance_time;
+  GNUNET_CronTime max_time GNUNET_PACKED;
+  GNUNET_CronTime min_time GNUNET_PACKED;
+  float mean_time GNUNET_PACKED;
+  float variance_time GNUNET_PACKED;
 } CS_tbench_reply_MESSAGE;
 
 #endif

Modified: GNUnet/src/applications/tracekit/tracekit.h
===================================================================
--- GNUnet/src/applications/tracekit/tracekit.h 2009-02-01 07:48:08 UTC (rev 
8159)
+++ GNUnet/src/applications/tracekit/tracekit.h 2009-02-02 02:51:33 UTC (rev 
8160)
@@ -35,22 +35,22 @@
   /**
    * When was this probe started? (NBO)
    */
-  GNUNET_Int32Time timestamp;
+  GNUNET_Int32Time timestamp GNUNET_PACKED;
 
   /**
    * How many more hops should this probe go (NBO)
    */
-  unsigned int hopsToGo;
+  unsigned int hopsToGo GNUNET_PACKED;
 
   /**
    * How important is the probe for the sender? (NBO)
    */
-  unsigned int priority;
+  unsigned int priority GNUNET_PACKED;
 
   /**
    * Internal client id of the sender.
    */
-  unsigned int clientId;
+  unsigned int clientId GNUNET_PACKED;
 
   /**
    * Which peer is the ultimate receiver of this
@@ -80,12 +80,12 @@
    * At what time was the initator sending the
    * request?
    */
-  GNUNET_Int32Time initiatorTimestamp;
+  GNUNET_Int32Time initiatorTimestamp GNUNET_PACKED;
 
   /**
    * Internal client Id of the sender.
    */
-  unsigned int clientId;
+  unsigned int clientId GNUNET_PACKED;
 
 } P2P_tracekit_reply_MESSAGE;
 
@@ -96,12 +96,12 @@
   /**
    * How many more hops should this probe go (NBO)
    */
-  unsigned int hops;
+  unsigned int hops GNUNET_PACKED;
 
   /**
    * How important is the probe for the sender? (NBO)
    */
-  unsigned int priority;
+  unsigned int priority GNUNET_PACKED;
 } CS_tracekit_probe_MESSAGE;
 
 typedef struct

Modified: GNUnet/src/applications/traffic/clientapi.c
===================================================================
--- GNUnet/src/applications/traffic/clientapi.c 2009-02-01 07:48:08 UTC (rev 
8159)
+++ GNUnet/src/applications/traffic/clientapi.c 2009-02-02 02:51:33 UTC (rev 
8160)
@@ -54,6 +54,7 @@
 {
   CS_traffic_info_MESSAGE *info;
   CS_traffic_request_MESSAGE req;
+  const TRAFFIC_COUNTER *tc;
   int i;
 
   req.header.size = htons (sizeof (CS_traffic_request_MESSAGE));
@@ -75,16 +76,15 @@
       return GNUNET_SYSERR;
     }
 
+  tc = (const TRAFFIC_COUNTER*) &info[1];
   for (i = ntohl (info->count) - 1; i >= 0; i--)
     {
-      const TRAFFIC_COUNTER *tc =
-        &((CS_traffic_info_MESSAGE_GENERIC *) info)->counters[i];
-      if ((tc->flags & GNUNET_TRAFFIC_TYPE_MASK) == direction)
+      if ((tc[i].flags & GNUNET_TRAFFIC_TYPE_MASK) == direction)
         {
-          *count = ntohl (tc->count);
-          *avg_size = ntohl (tc->avrg_size);
-          *peers = ntohs (tc->flags) & GNUNET_TRAFFIC_DIVERSITY_MASK;
-          *time = ntohl (tc->time_slots);
+          *count = ntohl (tc[i].count);
+          *avg_size = ntohl (tc[i].avrg_size);
+          *peers = ntohs (tc[i].flags) & GNUNET_TRAFFIC_DIVERSITY_MASK;
+          *time = ntohl (tc[i].time_slots);
         }                       /* end if received */
     }                           /* end for all counters */
   GNUNET_free (info);

Modified: GNUnet/src/applications/traffic/traffic.c
===================================================================
--- GNUnet/src/applications/traffic/traffic.c   2009-02-01 07:48:08 UTC (rev 
8159)
+++ GNUnet/src/applications/traffic/traffic.c   2009-02-02 02:51:33 UTC (rev 
8160)
@@ -300,6 +300,7 @@
   CS_traffic_info_MESSAGE *reply;
   unsigned int count;
   unsigned int i;
+  TRAFFIC_COUNTER * tc;
 
   GNUNET_mutex_lock (lock);
   count = 0;
@@ -318,19 +319,18 @@
                               count * sizeof (TRAFFIC_COUNTER));
   reply->count = htonl (count);
   count = 0;
+  tc = (TRAFFIC_COUNTER*) &reply[1];
   for (i = 0; i < max_message_type; i++)
     if (counters[i] != NULL)
       {
         if (counters[i]->send.slots != 0)
-          buildSummary (&((CS_traffic_info_MESSAGE_GENERIC *) reply)->counters
-                        [count++], &counters[i]->send,
+          buildSummary (&tc[count++], &counters[i]->send,
                         GNUNET_TRAFFIC_TYPE_SENT, countTimeUnits, i);
         if (counters[i]->receive.slots != 0)
-          buildSummary (&((CS_traffic_info_MESSAGE_GENERIC *) reply)->counters
-                        [count++], &counters[i]->receive,
+          buildSummary (&tc[count++],
+                        &counters[i]->receive,
                         GNUNET_TRAFFIC_TYPE_RECEIVED, countTimeUnits, i);
       }
-
   GNUNET_mutex_unlock (lock);
   return reply;
 }

Modified: GNUnet/src/applications/traffic/traffic.h
===================================================================
--- GNUnet/src/applications/traffic/traffic.h   2009-02-01 07:48:08 UTC (rev 
8159)
+++ GNUnet/src/applications/traffic/traffic.h   2009-02-02 02:51:33 UTC (rev 
8160)
@@ -36,24 +36,24 @@
   /**
    * Flags. See TC_XXXX definitions.
    */
-  unsigned short flags;
+  unsigned short flags GNUNET_PACKED;
 
   /**
    * What is the message type that this counter is concerned with?
    */
-  unsigned short type;
+  unsigned short type GNUNET_PACKED;
 
   /**
    * What was the number of messages of this type that the peer
    * processed in the last n time units?
    */
-  unsigned int count;
+  unsigned int count GNUNET_PACKED;
 
   /**
    * What is the average size of the last "count" messages that
    * the peer processed?
    */
-  unsigned int avrg_size;
+  unsigned int avrg_size GNUNET_PACKED;
 
   /**
    * In which of the last 32 time units did the peer receive or send a
@@ -61,14 +61,15 @@
    * seconds ago, the highest bit (2^31) corresponds to the current
    * second.
    */
-  unsigned int time_slots;
+  unsigned int time_slots GNUNET_PACKED;
 } TRAFFIC_COUNTER;
 
 
 /**
  * Format of the reply-message to a CS_TRAFFIC_QUERY.
  * A message of this format is send back to the client
- * if it sends a CS_TRAFFIC_QUERY to gnunetd.
+ * if it sends a CS_TRAFFIC_QUERY to gnunetd.  This
+ * struct is followed by count TRAFFIC_COUNTERs.
  */
 typedef struct
 {
@@ -78,26 +79,11 @@
    * The number of different message types we have seen
    * in the last time.
    */
-  unsigned int count;
+  unsigned int count GNUNET_PACKED;
 
 } CS_traffic_info_MESSAGE;
 
 /**
- * Generic version of CS_traffic_info_MESSAGE with field for accessing end of 
struct
- * (use the other version for allocation).
- */
-typedef struct
-{
-  CS_traffic_info_MESSAGE cs_traffic_info;
-
-  /**
-   * "count" traffic counters.
-   */
-  TRAFFIC_COUNTER counters[1];
-
-} CS_traffic_info_MESSAGE_GENERIC;
-
-/**
  * Request for CS_traffic_info_MESSAGE.
  */
 typedef struct
@@ -108,7 +94,7 @@
    * How many time units back should the statistics returned contain?
    * (in network byte order) Must be smaller or equal to HISTORY_SIZE.
    */
-  unsigned int timePeriod;
+  unsigned int timePeriod GNUNET_PACKED;
 
 } CS_traffic_request_MESSAGE;
 

Modified: GNUnet/src/include/chat.h
===================================================================
--- GNUnet/src/include/chat.h   2009-02-01 07:48:08 UTC (rev 8159)
+++ GNUnet/src/include/chat.h   2009-02-02 02:51:33 UTC (rev 8160)
@@ -40,13 +40,13 @@
   /**
    * Message options, see GNUNET_CHAT_MSG_OPTIONS.
    */
-  unsigned int msg_options;
+  unsigned int msg_options GNUNET_PACKED;
 
   /**
    * Hash of the public key of the pseudonym of the
    * sender of the message (all zeros for anonymous).
    */
-  GNUNET_HashCode sender;
+  GNUNET_HashCode sender GNUNET_PACKED;
 
 } CS_chat_MESSAGE_ReceiveNotification;
 
@@ -61,23 +61,23 @@
   /**
    * Desired message options, see GNUNET_CHAT_MSG_OPTIONS.
    */
-  unsigned int msg_options;
+  unsigned int msg_options GNUNET_PACKED;
 
   /**
    * Sequence number of the message (unique per sender).
    */
-  unsigned int sequence_number;
+  unsigned int sequence_number GNUNET_PACKED;
 
   /**
    * Reserved (for alignment).
    */
-  unsigned int reserved;
+  unsigned int reserved GNUNET_PACKED;
 
   /**
    * Who should receive this message?  Set to all zeros
    * for "everyone".
    */
-  GNUNET_HashCode target;
+  GNUNET_HashCode target GNUNET_PACKED;
 
 } CS_chat_MESSAGE_TransmitRequest;
 
@@ -93,22 +93,22 @@
   /**
    * Sequence number of the original message.
    */
-  unsigned int sequence_number;
+  unsigned int sequence_number GNUNET_PACKED;
 
   /**
    * Time of receipt.
    */
-  GNUNET_CronTime timestamp;
+  GNUNET_CronTime timestamp GNUNET_PACKED;
 
   /**
    * Who is confirming the receipt?
    */
-  GNUNET_HashCode target;
+  GNUNET_HashCode target GNUNET_PACKED;
 
   /**
    * Hash of the (possibly encrypted) content.
    */
-  GNUNET_HashCode content;
+  GNUNET_HashCode content GNUNET_PACKED;
 
   /**
    * Signature confirming receipt.  Signature
@@ -134,17 +134,17 @@
    * receive private messages, this should be set to
    * GNUNET_CHAT_MSG_PRIVATE | GNUNET_CHAT_MSG_ACKNOWLEDGED.
    */
-  unsigned int msg_options;
+  unsigned int msg_options GNUNET_PACKED;
 
   /**
    * Length of the room name.
    */
-  unsigned short room_name_len;
+  unsigned short room_name_len GNUNET_PACKED;
 
   /**
    * Reserved (should be zero).
    */
-  unsigned short reserved;
+  unsigned short reserved GNUNET_PACKED;
 
   /**
    * Private key of the joining member.
@@ -170,7 +170,7 @@
    * acknowledgements and receive private messages, this should be set
    * to GNUNET_CHAT_MSG_PRIVATE | GNUNET_CHAT_MSG_ACKNOWLEDGED.
    */
-  unsigned int msg_options;
+  unsigned int msg_options GNUNET_PACKED;
 
   /**
    * Public key of the new user.
@@ -191,7 +191,7 @@
   /**
    * Reserved (for alignment).
    */
-  unsigned int reserved;
+  unsigned int reserved GNUNET_PACKED;
 
   /**
    * Who is leaving?

Modified: GNUnet/src/include/dht.h
===================================================================
--- GNUnet/src/include/dht.h    2009-02-01 07:48:08 UTC (rev 8159)
+++ GNUnet/src/include/dht.h    2009-02-02 02:51:33 UTC (rev 8160)
@@ -55,9 +55,9 @@
 
   GNUNET_MessageHeader header;
 
-  unsigned int type;            /* nbo */
+  unsigned int type GNUNET_PACKED;            /* nbo */
 
-  GNUNET_HashCode key;
+  GNUNET_HashCode key GNUNET_PACKED;
 
 } CS_dht_request_put_MESSAGE;
 
@@ -71,9 +71,9 @@
 
   GNUNET_MessageHeader header;
 
-  unsigned int type;            /* nbo */
+  unsigned int type GNUNET_PACKED;            /* nbo */
 
-  GNUNET_HashCode key;
+  GNUNET_HashCode key GNUNET_PACKED;
 
 } CS_dht_request_get_MESSAGE;
 

Modified: GNUnet/src/include/dv.h
===================================================================
--- GNUnet/src/include/dv.h     2009-02-01 07:48:08 UTC (rev 8159)
+++ GNUnet/src/include/dv.h     2009-02-02 02:51:33 UTC (rev 8160)
@@ -39,17 +39,17 @@
  */
 typedef struct
 {
-  GNUNET_MessageHeader header;
+  GNUNET_MessageHeader header GNUNET_PACKED;
 
   /**
    * Cost from received from node to neighbor node, takes distance into account
    */
-  unsigned int cost;
+  unsigned int cost GNUNET_PACKED;
 
   /**
    * Identity of neighbor of received from node
    */
-  GNUNET_PeerIdentity neighbor;
+  GNUNET_PeerIdentity neighbor GNUNET_PACKED;
 
 } p2p_dv_MESSAGE_NeighborInfo;
 

Modified: GNUnet/src/include/fs.h
===================================================================
--- GNUnet/src/include/fs.h     2009-02-01 07:48:08 UTC (rev 8159)
+++ GNUnet/src/include/fs.h     2009-02-02 02:51:33 UTC (rev 8160)
@@ -44,20 +44,20 @@
   /**
    * Should be zero.
    */
-  int reserved;
+  int reserved GNUNET_PACKED;
 
   /**
    * Type of the content that we're looking for.
    * 0 for any.
    */
-  unsigned int type;
+  unsigned int type GNUNET_PACKED;
 
   /**
    * What are the anonymity requirements for this content?
    * Use 0 if anonymity is not required (enables direct
    * sharing / DHT routing).
    */
-  unsigned int anonymity_level;
+  unsigned int anonymity_level GNUNET_PACKED;
 
   /**
    * Identity of the peer that is known to have the
@@ -69,7 +69,7 @@
   /**
    * What are the queries?
    */
-  GNUNET_HashCode query[1];
+  GNUNET_HashCode query[1] GNUNET_PACKED;
 
 } CS_fs_request_search_MESSAGE;
 
@@ -86,12 +86,12 @@
    * Anonymity level for the content, maybe
    * 0 if not known.
    */
-  unsigned int anonymity_level;
+  unsigned int anonymity_level GNUNET_PACKED;
 
   /**
    * Expiration time of the response (relative to now).
    */
-  GNUNET_CronTime expiration_time;
+  GNUNET_CronTime expiration_time GNUNET_PACKED;
 
 } CS_fs_reply_content_MESSAGE;
 
@@ -108,24 +108,24 @@
   /**
    * Reserved (should be zero).  For alignment.
    */
-  int reserved;
+  int reserved GNUNET_PACKED;
 
   /**
    * Priority for the on-demand encoded entry.
    */
-  unsigned int priority;
+  unsigned int priority GNUNET_PACKED;
 
   /**
    * What are the anonymity requirements for this content?
    * Use 0 if anonymity is not required (enables direct
    * sharing / DHT routing).
    */
-  unsigned int anonymity_level;
+  unsigned int anonymity_level GNUNET_PACKED;
 
   /**
    * At what time does the entry expire?
    */
-  GNUNET_CronTime expiration;
+  GNUNET_CronTime expiration GNUNET_PACKED;
 
 } CS_fs_request_insert_MESSAGE;
 
@@ -138,13 +138,13 @@
 {
   GNUNET_MessageHeader header;
 
-  unsigned int reserved;
+  unsigned int reserved GNUNET_PACKED;
 
   /**
    * What is the GNUNET_hash of the file that contains
    * this block?
    */
-  GNUNET_HashCode fileId;
+  GNUNET_HashCode fileId GNUNET_PACKED;
 
 } CS_fs_request_init_index_MESSAGE;
 
@@ -160,37 +160,37 @@
   /**
    * Reserved (should be zero).  For alignment.
    */
-  int reserved;
+  int reserved GNUNET_PACKED;
 
   /**
    * Priority for the on-demand encoded entry.
    */
-  unsigned int priority;
+  unsigned int priority GNUNET_PACKED;
 
   /**
    * What are the anonymity requirements for this content?
    * Use 0 if anonymity is not required (enables direct
    * sharing / DHT routing).
    */
-  unsigned int anonymity_level;
+  unsigned int anonymity_level GNUNET_PACKED;
 
   /**
    * At what time does the entry expire?
    */
-  GNUNET_CronTime expiration;
+  GNUNET_CronTime expiration GNUNET_PACKED;
 
   /**
    * At what offset in the plaintext file is
    * this content stored?
    */
-  unsigned long long fileOffset;
+  unsigned long long fileOffset GNUNET_PACKED;
 
   /**
    * What is the GNUNET_hash of the file that contains
    * this block?  Used by gnunetd for the name
    * of the file in the on-demand datastore.
    */
-  GNUNET_HashCode fileId;
+  GNUNET_HashCode fileId GNUNET_PACKED;
 
 } CS_fs_request_index_MESSAGE;
 
@@ -205,7 +205,7 @@
   /**
    * Reserved (should be zero).  For alignment.
    */
-  int reserved;
+  int reserved GNUNET_PACKED;
 
 } CS_fs_request_delete_MESSAGE;
 
@@ -219,13 +219,13 @@
   /**
    * Size of each block of the file.
    */
-  unsigned int blocksize;
+  unsigned int blocksize GNUNET_PACKED;
 
   /**
    * What is the GNUNET_hash of the file that should be
    * unindexed?
    */
-  GNUNET_HashCode fileId;
+  GNUNET_HashCode fileId GNUNET_PACKED;
 
 } CS_fs_request_unindex_MESSAGE;
 
@@ -236,13 +236,13 @@
 {
   GNUNET_MessageHeader header;
 
-  unsigned int reserved;
+  unsigned int reserved GNUNET_PACKED;
 
   /**
    * What is the GNUNET_hash of the file that should be
    * unindexed?
    */
-  GNUNET_HashCode fileId;
+  GNUNET_HashCode fileId GNUNET_PACKED;
 
 } CS_fs_request_test_index_MESSAGE;
 
@@ -263,30 +263,30 @@
   /**
    * Type of the query (block type).
    */
-  unsigned int type;
+  unsigned int type GNUNET_PACKED;
 
   /**
    * How important is this request (network byte order)
    */
-  unsigned int priority;
+  unsigned int priority GNUNET_PACKED;
 
   /**
    * Relative time to live in GNUNET_CRON_MILLISECONDS (network byte order)
    */
-  int ttl;
+  int ttl GNUNET_PACKED;
 
   /**
    * The content hash should be mutated using this value
    * before checking against the bloomfilter (used to
    * get many different filters for the same hash codes).
    */
-  int filter_mutator;
+  int filter_mutator GNUNET_PACKED;
 
   /**
    * How many queries do we have (should be
    * greater than zero).
    */
-  unsigned int number_of_queries;
+  unsigned int number_of_queries GNUNET_PACKED;
 
   /**
    * To whom to return results?
@@ -297,7 +297,7 @@
    * Hashcodes of the file(s) we're looking for.
    * Details depend on the query type.
    */
-  GNUNET_HashCode queries[1];
+  GNUNET_HashCode queries[1] GNUNET_PACKED;
 
 } P2P_gap_query_MESSAGE;
 
@@ -314,13 +314,13 @@
   /**
    * Always zero (for now).
    */
-  unsigned int reserved;        /* for 64-bit alignment */
+  unsigned int reserved GNUNET_PACKED;        /* for 64-bit alignment */
 
   /**
    * When does this result expire?  The given time
    * is relative (and in big-endian).
    */
-  unsigned long long expiration;
+  unsigned long long expiration GNUNET_PACKED;
 
 } P2P_gap_reply_MESSAGE;
 

Modified: GNUnet/src/include/gnunet_util_common.h
===================================================================
--- GNUnet/src/include/gnunet_util_common.h     2009-02-01 07:48:08 UTC (rev 
8159)
+++ GNUnet/src/include/gnunet_util_common.h     2009-02-02 02:51:33 UTC (rev 
8160)
@@ -40,6 +40,12 @@
 #define GNUNET_NO      0
 
 /**
+ * gcc-ism to get packed structs.
+ */
+#define GNUNET_PACKED __attribute__((packed))
+
+
+/**
  * Function called with a filename.
  *
  * @param filename complete filename (absolute path)

Modified: GNUnet/src/include/gnunet_util_core.h
===================================================================
--- GNUnet/src/include/gnunet_util_core.h       2009-02-01 07:48:08 UTC (rev 
8159)
+++ GNUnet/src/include/gnunet_util_core.h       2009-02-02 02:51:33 UTC (rev 
8160)
@@ -80,18 +80,18 @@
   /**
    * time this address expires  (network byte order)
    */
-  GNUNET_Int32Time expiration_time;
+  GNUNET_Int32Time expiration_time GNUNET_PACKED;
 
   /**
    * advertised MTU for sending (replies can have a different
    * MTU!)
    */
-  unsigned int MTU;
+  unsigned int MTU GNUNET_PACKED;
 
   /**
    * size of the sender address
    */
-  unsigned short senderAddressSize;
+  unsigned short senderAddressSize GNUNET_PACKED;
 
   /**
    * protocol supported by the node (only one protocol
@@ -99,7 +99,7 @@
    * Examples are UDP, TCP, etc. This field is
    * in network byte order
    */
-  unsigned short protocol;
+  unsigned short protocol GNUNET_PACKED;
 
 } GNUNET_MessageHello;
 

Modified: GNUnet/src/include/gnunet_util_crypto.h
===================================================================
--- GNUnet/src/include/gnunet_util_crypto.h     2009-02-01 07:48:08 UTC (rev 
8159)
+++ GNUnet/src/include/gnunet_util_crypto.h     2009-02-02 02:51:33 UTC (rev 
8160)
@@ -92,14 +92,14 @@
   /**
    * Total size of the structure, in bytes, in big-endian!
    */
-  unsigned short len;
-  unsigned short sizen;         /*  in big-endian! */
-  unsigned short sizee;         /*  in big-endian! */
-  unsigned short sized;         /*  in big-endian! */
-  unsigned short sizep;         /*  in big-endian! */
-  unsigned short sizeq;         /*  in big-endian! */
-  unsigned short sizedmp1;      /*  in big-endian! */
-  unsigned short sizedmq1;      /*  in big-endian! */
+  unsigned short len GNUNET_PACKED;
+  unsigned short sizen GNUNET_PACKED;         /*  in big-endian! */
+  unsigned short sizee GNUNET_PACKED;         /*  in big-endian! */
+  unsigned short sized GNUNET_PACKED;         /*  in big-endian! */
+  unsigned short sizep GNUNET_PACKED;         /*  in big-endian! */
+  unsigned short sizeq GNUNET_PACKED;         /*  in big-endian! */
+  unsigned short sizedmp1 GNUNET_PACKED;      /*  in big-endian! */
+  unsigned short sizedmq1 GNUNET_PACKED;      /*  in big-endian! */
   /* followed by the actual values */
 } GNUNET_RSA_PrivateKeyEncoded;
 
@@ -119,11 +119,11 @@
   /**
    * In big-endian, must be GNUNET_RSA_KEY_LEN+4
    */
-  unsigned short len;
+  unsigned short len GNUNET_PACKED;
   /**
    * Size of n in key; in big-endian!
    */
-  unsigned short sizen;
+  unsigned short sizen GNUNET_PACKED;
   /**
    * The key itself, contains n followed by e.
    */
@@ -131,7 +131,7 @@
   /**
    * Padding (must be 0)
    */
-  unsigned short padding;
+  unsigned short padding GNUNET_PACKED;
 } GNUNET_RSA_PublicKey;
 
 /**

Modified: GNUnet/src/include/gnunet_util_network.h
===================================================================
--- GNUnet/src/include/gnunet_util_network.h    2009-02-01 07:48:08 UTC (rev 
8159)
+++ GNUnet/src/include/gnunet_util_network.h    2009-02-02 02:51:33 UTC (rev 
8160)
@@ -96,7 +96,7 @@
  */
 typedef struct
 {
-  GNUNET_HashCode hashPubKey;
+  GNUNET_HashCode hashPubKey GNUNET_PACKED;
 } GNUNET_PeerIdentity;
 
 /**
@@ -108,12 +108,12 @@
   /**
    * The length of the struct (in bytes, including the length field itself)
    */
-  unsigned short size;
+  unsigned short size GNUNET_PACKED;
 
   /**
    * The type of the message (XX_CS_PROTO_XXXX)
    */
-  unsigned short type;
+  unsigned short type GNUNET_PACKED;
 
 } GNUNET_MessageHeader;
 
@@ -131,7 +131,7 @@
   /**
    * The return value (network byte order)
    */
-  int return_value;
+  int return_value GNUNET_PACKED;
 
 } GNUNET_MessageReturnValue;
 
@@ -149,7 +149,7 @@
   /**
    * The return value (network byte order)
    */
-  GNUNET_GE_KIND kind;
+  GNUNET_GE_KIND kind GNUNET_PACKED;
 
 } GNUNET_MessageReturnErrorMessage;
 

Modified: GNUnet/src/server/connection.h
===================================================================
--- GNUnet/src/server/connection.h      2009-02-01 07:48:08 UTC (rev 8159)
+++ GNUnet/src/server/connection.h      2009-02-02 02:51:33 UTC (rev 8160)
@@ -43,13 +43,13 @@
 {
   /* GNUNET_hash of the plaintext, used to verify message integrity;
      ALSO used as the IV for the symmetric cipher! */
-  GNUNET_HashCode hash;
+  GNUNET_HashCode hash GNUNET_PACKED;
   /* sequence number, in network byte order, 0 for plaintext messages! */
-  unsigned int sequenceNumber;
+  unsigned int sequenceNumber GNUNET_PACKED;
   /* timestamp  (network byte order), 0 for plaintext messages! */
-  GNUNET_Int32Time timeStamp;
+  GNUNET_Int32Time timeStamp GNUNET_PACKED;
   /* desired bandwidth, 0 for plaintext messages! */
-  unsigned int bandwidth;
+  unsigned int bandwidth GNUNET_PACKED;
 } GNUNET_TransportPacket_HEADER;        /* 76 bytes */
 
 /* ***************** GNUnet core internals ************ */

Modified: GNUnet/src/util/os/console.c
===================================================================
--- GNUnet/src/util/os/console.c        2009-02-01 07:48:08 UTC (rev 8159)
+++ GNUnet/src/util/os/console.c        2009-02-02 02:51:33 UTC (rev 8160)
@@ -301,7 +301,9 @@
    * close usual incoming fds, but redirect them somewhere
    * useful so the fds don't get reallocated elsewhere.
    */
-  if (dup2 (nullfd, 0) < 0 || dup2 (nullfd, 1) < 0 || dup2 (nullfd, 2) < 0)
+  if ( (dup2 (nullfd, 0) < 0) || 
+       (dup2 (nullfd, 1) < 0) || 
+       (dup2 (nullfd, 2) < 0) )
     {
       GNUNET_GE_LOG_STRERROR (ectx,
                               GNUNET_GE_FATAL | GNUNET_GE_USER |





reply via email to

[Prev in Thread] Current Thread [Next in Thread]