summaryrefslogtreecommitdiff
path: root/mactelnet.c
diff options
context:
space:
mode:
authorHåkon Nessjøen <haakon.nessjoen@gmail.com>2011-11-08 23:06:39 +0100
committerHåkon Nessjøen <haakon.nessjoen@gmail.com>2011-11-08 23:06:39 +0100
commitd876aad77b29f410c9c4218636482cab59504fac (patch)
treec3e72662159b3d47162da3e1c664da7e8a589927 /mactelnet.c
parentb7543bdfda84c0287dd0d183fa764c9931a4c211 (diff)
downloadMAC-Telnet-d876aad77b29f410c9c4218636482cab59504fac.tar.gz
MAC-Telnet-d876aad77b29f410c9c4218636482cab59504fac.zip
Clean up and bugfix endianess handling
Diffstat (limited to 'mactelnet.c')
-rw-r--r--mactelnet.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/mactelnet.c b/mactelnet.c
index 288fd3b..ce91d01 100644
--- a/mactelnet.c
+++ b/mactelnet.c
@@ -16,12 +16,14 @@
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#define _BSD_SOURCE
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
+#include <endian.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netinet/ether.h>
@@ -177,11 +179,8 @@ static void send_auth(char *username, char *password) {
plen += add_control_packet(&data, MT_CPTYPE_TERM_TYPE, terminal, strlen(terminal));
if (is_a_tty && get_terminal_size(&width, &height) != -1) {
-#if BYTE_ORDER == BIG_ENDIAN
- /* Seems like Mikrotik are sending data little_endianed? */
- width = ((width & 0xff) << 8) | ((width & 0xff00) >> 8);
- height = ((height & 0xff) << 8) | ((height & 0xff00) >> 8);
-#endif
+ width = htole16(width);
+ height = htole16(height);
plen += add_control_packet(&data, MT_CPTYPE_TERM_WIDTH, &width, 2);
plen += add_control_packet(&data, MT_CPTYPE_TERM_HEIGHT, &height, 2);
}
@@ -200,6 +199,8 @@ static void sig_winch(int sig) {
/* terminal height/width has changed, inform server */
if (get_terminal_size(&width, &height) != -1) {
init_packet(&data, MT_PTYPE_DATA, srcmac, dstmac, sessionkey, outcounter);
+ width = htole16(width);
+ height = htole16(height);
plen = add_control_packet(&data, MT_CPTYPE_TERM_WIDTH, &width, 2);
plen += add_control_packet(&data, MT_CPTYPE_TERM_HEIGHT, &height, 2);
outcounter += plen;