From 7e12cd48525b92a7b7090738c03d10d5e616a92e Mon Sep 17 00:00:00 2001 From: Iru Cai Date: Thu, 17 May 2018 14:13:49 +0800 Subject: ssh_endian.h --- src/protocol/CMakeLists.txt | 1 - src/protocol/internal/buffer.c | 2 +- src/protocol/internal/fqterm_serialization.h | 54 ----------------------- src/protocol/internal/fqterm_ssh1_packet.cpp | 2 +- src/protocol/internal/fqterm_ssh2_packet.cpp | 2 +- src/protocol/internal/fqterm_ssh_channel.cpp | 1 + src/protocol/internal/fqterm_ssh_packet.cpp | 1 - src/protocol/internal/fqterm_ssh_packet.h | 1 - src/protocol/internal/ssh_endian.h | 65 ++++++++++++++++++++++++++++ src/protocol/internal/ssh_rsa.c | 1 + src/protocol/internal/ssh_session.h | 1 + 11 files changed, 71 insertions(+), 60 deletions(-) delete mode 100644 src/protocol/internal/fqterm_serialization.h create mode 100644 src/protocol/internal/ssh_endian.h diff --git a/src/protocol/CMakeLists.txt b/src/protocol/CMakeLists.txt index e6db775..c4c9e0f 100644 --- a/src/protocol/CMakeLists.txt +++ b/src/protocol/CMakeLists.txt @@ -29,7 +29,6 @@ set(internal_SRCS internal/ssh_diffie-hellman.c internal/crc32.c internal/ssh_packet.c - internal/fqterm_serialization.h internal/fqterm_ssh_auth.h internal/fqterm_ssh_const.h internal/fqterm_ssh_kex.h diff --git a/src/protocol/internal/buffer.c b/src/protocol/internal/buffer.c index 388cbe0..f75d33e 100644 --- a/src/protocol/internal/buffer.c +++ b/src/protocol/internal/buffer.c @@ -18,7 +18,7 @@ */ #include "buffer.h" -#include +#include "ssh_endian.h" #define INITSIZE 2048 diff --git a/src/protocol/internal/fqterm_serialization.h b/src/protocol/internal/fqterm_serialization.h deleted file mode 100644 index 7a858c0..0000000 --- a/src/protocol/internal/fqterm_serialization.h +++ /dev/null @@ -1,54 +0,0 @@ -/*************************************************************************** - * fqterm, a terminal emulator for both BBS and *nix. * - * Copyright (C) 2008 fqterm development group. * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * - ***************************************************************************/ - -#ifndef FQTERM_SERIALIZATION_H -#define FQTERM_SERIALIZATION_H - -#if defined(WIN32) -typedef unsigned __int16 u_int16_t; -#else -#include -#endif - -namespace FQTerm { - -inline u_int16_t ntohu16(const unsigned char *buf) { - return (buf[0] << 8) | buf[1]; -} - -inline u_int32_t ntohu32(const unsigned char *buf) { - return (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; -} - -inline void htonu32(unsigned char *buf, u_int32_t number) { - buf[0] = (number >> 24) & 0xFF; - buf[1] = (number >> 16) & 0xFF; - buf[2] = (number >> 8) & 0xFF; - buf[3] = number & 0xFF; -} - -inline void htonu16(unsigned char *buf, u_int16_t number) { - buf[0] = (number >> 8 & 0xFF); - buf[1] = (number & 0xFF); -} - -} // namespace FQTerm - -#endif // FQTERM_SERIALIZATION_H diff --git a/src/protocol/internal/fqterm_ssh1_packet.cpp b/src/protocol/internal/fqterm_ssh1_packet.cpp index 5e64d45..7605b51 100644 --- a/src/protocol/internal/fqterm_ssh1_packet.cpp +++ b/src/protocol/internal/fqterm_ssh1_packet.cpp @@ -21,7 +21,7 @@ #include "fqterm_trace.h" #include "fqterm_ssh1_packet.h" -#include "fqterm_serialization.h" +#include "ssh_endian.h" #include "crc32.h" #include "ssh_packet.h" diff --git a/src/protocol/internal/fqterm_ssh2_packet.cpp b/src/protocol/internal/fqterm_ssh2_packet.cpp index e13cab7..75a2cc4 100644 --- a/src/protocol/internal/fqterm_ssh2_packet.cpp +++ b/src/protocol/internal/fqterm_ssh2_packet.cpp @@ -21,7 +21,7 @@ #include "fqterm_trace.h" #include "fqterm_ssh2_packet.h" -#include "fqterm_serialization.h" +#include "ssh_endian.h" #include "buffer.h" #include "ssh_packet.h" diff --git a/src/protocol/internal/fqterm_ssh_channel.cpp b/src/protocol/internal/fqterm_ssh_channel.cpp index e997121..9db2efb 100644 --- a/src/protocol/internal/fqterm_ssh_channel.cpp +++ b/src/protocol/internal/fqterm_ssh_channel.cpp @@ -22,6 +22,7 @@ #include "fqterm_ssh_const.h" #include "fqterm_ssh_packet.h" #include "fqterm_trace.h" +#include "ssh_endian.h" #include namespace FQTerm { diff --git a/src/protocol/internal/fqterm_ssh_packet.cpp b/src/protocol/internal/fqterm_ssh_packet.cpp index 9553e98..cc258b2 100644 --- a/src/protocol/internal/fqterm_ssh_packet.cpp +++ b/src/protocol/internal/fqterm_ssh_packet.cpp @@ -22,7 +22,6 @@ #include "fqterm_ssh_packet.h" #include "fqterm_ssh_const.h" -#include "fqterm_serialization.h" #include "crc32.h" #include diff --git a/src/protocol/internal/fqterm_ssh_packet.h b/src/protocol/internal/fqterm_ssh_packet.h index b7bec91..5b51fbb 100644 --- a/src/protocol/internal/fqterm_ssh_packet.h +++ b/src/protocol/internal/fqterm_ssh_packet.h @@ -27,7 +27,6 @@ #include "fqterm_ssh_types.h" #include "ssh_mac.h" -#include "fqterm_serialization.h" #include "ssh_cipher.h" #include "buffer.h" diff --git a/src/protocol/internal/ssh_endian.h b/src/protocol/internal/ssh_endian.h new file mode 100644 index 0000000..1a42225 --- /dev/null +++ b/src/protocol/internal/ssh_endian.h @@ -0,0 +1,65 @@ +/* + * ssh_endian.h: endian conversion + * Copyright (C) 2018 Iru Cai + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef SSH_ENDIAN_H +#define SSH_ENDIAN_H + +#include + +#if defined(WIN32) +static inline uint16_t bswap_16(uint16_t x) +{ + return (x << 8) | (x >> 8); +} + +static inline uint32_t bswap_32(uint32_t x) +{ + return (bswap_16(x) << 16) | bswap_16(x >> 16); +} + +#define htobe16 bswap_16 +#define be16toh bswap_16 +#define htobe32 bswap_32 +#define be32toh bswap_32 + +#else +#include +#endif + +static inline uint16_t ntohu16(const unsigned char *buf) +{ + return be16toh(*(uint16_t *)buf); +} + +static inline uint32_t ntohu32(const unsigned char *buf) +{ + return be32toh(*(uint32_t *)buf); +} + +static inline void htonu32(unsigned char *buf, uint32_t number) +{ + *(uint32_t *)buf = htobe32(number); +} + +static inline void htonu16(unsigned char *buf, uint16_t number) +{ + *(uint16_t *)buf = htobe16(number); +} + +#endif diff --git a/src/protocol/internal/ssh_rsa.c b/src/protocol/internal/ssh_rsa.c index 2bd328c..d6f3186 100644 --- a/src/protocol/internal/ssh_rsa.c +++ b/src/protocol/internal/ssh_rsa.c @@ -2,6 +2,7 @@ #include "ssh_pubkey_crypto.h" #include "ssh_rsa.h" #include "buffer.h" +#include "ssh_endian.h" static RSA *CreateRSAContext(unsigned char *hostkey, int len) { diff --git a/src/protocol/internal/ssh_session.h b/src/protocol/internal/ssh_session.h index 98adb50..2473e23 100644 --- a/src/protocol/internal/ssh_session.h +++ b/src/protocol/internal/ssh_session.h @@ -2,6 +2,7 @@ #define SSH_SESSION_H #include "ssh_diffie-hellman.h" +#include #ifdef __cplusplus extern "C" { -- cgit v1.2.3