From 0e2d331497aa57a383ff9b512a257910cded8f14 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Sun, 26 Jan 2003 11:48:03 +0000 Subject: [PATCH] Added SILC_SWAB_[16/32] to swab integer byte order. Use SILC_SWAB_16 instead of htons with ports in server. --- CHANGES | 9 +++++++ apps/silcd/idlist.c | 2 +- apps/silcd/server_backup.c | 4 +-- apps/silcd/serverid.c | 2 +- lib/silcutil/silctypes.h | 50 ++++++++++++++++++++++++++++++++------ 5 files changed, 56 insertions(+), 11 deletions(-) diff --git a/CHANGES b/CHANGES index e7e21376..bdc29f9b 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,15 @@ Sun Jan 26 12:20:30 EET 2003 Pekka Riikonen * 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 * Send DISCONNECT in close admin command in server. Affected diff --git a/apps/silcd/idlist.c b/apps/silcd/idlist.c index 9acdd068..fb457b6c 100644 --- a/apps/silcd/idlist.c +++ b/apps/silcd/idlist.c @@ -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; diff --git a/apps/silcd/server_backup.c b/apps/silcd/server_backup.c index f91a6d29..757f5177 100644 --- a/apps/silcd/server_backup.c +++ b/apps/silcd/server_backup.c @@ -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, diff --git a/apps/silcd/serverid.c b/apps/silcd/serverid.c index d9e39bb5..7d8fdea5 100644 --- a/apps/silcd/serverid.c +++ b/apps/silcd/serverid.c @@ -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))); diff --git a/lib/silcutil/silctypes.h b/lib/silcutil/silctypes.h index 7d4594cf..c763f8fa 100644 --- a/lib/silcutil/silctypes.h +++ b/lib/silcutil/silctypes.h @@ -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 */ -- 2.24.0