Added SILC_SWAB_[16/32] to swab integer byte order. silc.server.0.9.12
authorPekka Riikonen <priikone@silcnet.org>
Sun, 26 Jan 2003 11:48:03 +0000 (11:48 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Sun, 26 Jan 2003 11:48:03 +0000 (11:48 +0000)
Use SILC_SWAB_16 instead of htons with ports in server.

CHANGES
apps/silcd/idlist.c
apps/silcd/server_backup.c
apps/silcd/serverid.c
lib/silcutil/silctypes.h

diff --git a/CHANGES b/CHANGES
index e7e213762bf55020b9624c6f8f57eb8db066a073..bdc29f9baa208e961cae4cbd0c636da66d50b065 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -3,6 +3,15 @@ Sun Jan 26 12:20:30 EET 2003  Pekka Riikonen <priikone@silcnet.org>
        * Fixed a double free in INVITE command error handling in
          server.  Affected file silcd/command.c.
 
+       * Added macros SILC_SWAB_[16|32] to swab byte order of
+         16-bit and 32-bit unsigned integers.  Affected file
+         lib/silcutil/silctypes.h.
+
+       * Use the SILC_SWAB_16 instead of htons() in server when
+         handling ports since the ports in structures are always
+         in little-endian order (regardless of platform).  Affected
+         file silcd/serverid.c and silcd/server_backup.c.
+
 Tue Jan 21 17:18:04 EET 2003  Pekka Riikonen <priikone@silcnet.org>
 
        * Send DISCONNECT in close admin command in server.  Affected
index 9acdd06844330fd6b2e7f93baaa55d344aa68687..fb457b6c44335fe596b732bccd50aed9d8f0b605 100644 (file)
@@ -227,7 +227,7 @@ silc_idlist_find_server_by_conn(SilcIDList id_list, char *hostname,
     
     if (sock && ((sock->hostname && !strcasecmp(sock->hostname, hostname)) ||
                 (sock->ip && !strcasecmp(sock->ip, hostname)))
-       && server->id->port == htons(port))
+       && server->id->port == SILC_SWAB_16(port))
       break;
 
     id_cache = NULL;
index f91a6d29556ae2b9800d12bd991767332b99503f..757f5177a17d0e812a64f01521870d0cc3ddf256 100644 (file)
@@ -96,7 +96,7 @@ void silc_server_backup_add(SilcServer server, SilcServerEntry backup_server,
     if (!server->backup->servers[i].server) {
       server->backup->servers[i].server = backup_server;
       server->backup->servers[i].local = local;
-      server->backup->servers[i].port = htons(port);
+      server->backup->servers[i].port = SILC_SWAB_16(port);
       memset(server->backup->servers[i].ip.data, 0,
             sizeof(server->backup->servers[i].ip.data));
       silc_net_addr2bin(ip, server->backup->servers[i].ip.data,
@@ -111,7 +111,7 @@ void silc_server_backup_add(SilcServer server, SilcServerEntry backup_server,
                                         (i + 1));
   server->backup->servers[i].server = backup_server;
   server->backup->servers[i].local = local;
-  server->backup->servers[i].port = htons(port);
+  server->backup->servers[i].port = SILC_SWAB_16(port);
   memset(server->backup->servers[i].ip.data, 0,
         sizeof(server->backup->servers[i].ip.data));
   silc_net_addr2bin(ip, server->backup->servers[i].ip.data,
index d9e39bb5350c35d0b5eacbbf346d82580297c231..7d8fdea5c1f059e28cf8ffd9d779677c8d2c75f4 100644 (file)
@@ -42,7 +42,7 @@ void silc_id_create_server_id(const char *ip, SilcUInt16 port, SilcRng rng,
   }
 
   (*new_id)->ip.data_len = silc_net_is_ip4(ip) ? 4 : 16;
-  (*new_id)->port = htons(port);
+  (*new_id)->port = SILC_SWAB_16(port);
   (*new_id)->rnd = silc_rng_get_rn16(rng);
 
   SILC_LOG_DEBUG(("New ID (%s)", silc_id_render(*new_id, SILC_ID_SERVER)));
index 7d4594cfcae17d3c2e2982c8e35a386118a6f353..c763f8fa3b6be5fa1b6f613bbc0a926cdd6d2354 100644 (file)
@@ -245,9 +245,9 @@ typedef SilcUInt32 * void *;
 
 /* Macros */
 
-#define GET_WORD(cp) ((SilcUInt32)(SilcUInt8)(cp)[0]) << 24    \
-                   | ((SilcUInt32)(SilcUInt8)(cp)[1] << 16)    \
-                   | ((SilcUInt32)(SilcUInt8)(cp)[2] << 8)     \
+#define SILC_GET_WORD(cp) ((SilcUInt32)(SilcUInt8)(cp)[0]) << 24       \
+                   | ((SilcUInt32)(SilcUInt8)(cp)[1] << 16)            \
+                   | ((SilcUInt32)(SilcUInt8)(cp)[2] << 8)             \
                    | ((SilcUInt32)(SilcUInt8)(cp)[3])
 
 /****d* silcutil/SILCTypes/SILC_GET16_MSB
@@ -302,10 +302,10 @@ do {                                                      \
  *
  * SOURCE
  */
-#define SILC_GET64_MSB(l, cp)                          \
-do {                                                   \
-       (l) = ((((SilcUInt64)GET_WORD((cp))) << 32) |   \
-             ((SilcUInt64)GET_WORD((cp) + 4)));        \
+#define SILC_GET64_MSB(l, cp)                                  \
+do {                                                           \
+       (l) = ((((SilcUInt64)SILC_GET_WORD((cp))) << 32) |      \
+             ((SilcUInt64)SILC_GET_WORD((cp) + 4)));           \
 } while(0)
 /***/
 
@@ -455,4 +455,40 @@ do {                                               \
 } while(0)
 /***/
 
+/****d* silcutil/SILCTypes/SILC_SWAB_16
+ *
+ * NAME
+ *
+ *    #define SILC_SWAB_16 ...
+ *
+ * DESCRIPTION
+ *
+ *    Swabs 16-bit unsigned integer byte order.
+ *
+ * SOURCE
+ */
+#define SILC_SWAB_16(l)                                                \
+  ((SilcUInt16)(((SilcUInt16)(l) & (SilcUInt16)0x00FFU) << 8) |        \
+               (((SilcUInt16)(l) & (SilcUInt16)0xFF00U) >> 8))
+/***/
+
+/****d* silcutil/SILCTypes/SILC_SWAB_32
+ *
+ * NAME
+ *
+ *    #define SILC_SWAB_32 ...
+ *
+ * DESCRIPTION
+ *
+ *    Swabs 32-bit unsigned integer byte order.
+ *
+ * SOURCE
+ */
+#define SILC_SWAB_32(l)                                                        \
+  ((SilcUInt32)(((SilcUInt32)(l) & (SilcUInt32)0x000000FFUL) << 24) |  \
+               (((SilcUInt32)(l) & (SilcUInt32)0x0000FF00UL) << 8)  |  \
+               (((SilcUInt32)(l) & (SilcUInt32)0x00FF0000UL) >> 8)  |  \
+               (((SilcUInt32)(l) & (SilcUInt32)0xFF000000UL) >> 24))
+/***/
+
 #endif /* SILCTYPES_H */