diff options
author | Boian Bonev <bbonev@ipacct.com> | 2011-11-11 03:29:42 +0530 |
---|---|---|
committer | Boian Bonev <bbonev@ipacct.com> | 2011-11-11 03:29:42 +0530 |
commit | 8e00efedad165bfed2856a41cbf492c91e0ddce0 (patch) | |
tree | bc049940745022b177f81197bbb8fe49177bad63 | |
parent | 00fc2f34ee4fd77310e1ed4d1ddacccdb20c473d (diff) | |
parent | 904d05c3d9dec35bad0413f933ea690868a09f4f (diff) | |
download | MAC-Telnet-8e00efedad165bfed2856a41cbf492c91e0ddce0.tar.gz MAC-Telnet-8e00efedad165bfed2856a41cbf492c91e0ddce0.zip |
Merge branch 'master' of https://github.com/haakonnessjoen/MAC-Telnet
-rw-r--r-- | mactelnet.c | 11 | ||||
-rw-r--r-- | mactelnetd.c | 28 | ||||
-rw-r--r-- | protocol.c | 14 |
3 files changed, 28 insertions, 25 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; diff --git a/mactelnetd.c b/mactelnetd.c index d1842f8..ed9c3f9 100644 --- a/mactelnetd.c +++ b/mactelnetd.c @@ -547,7 +547,7 @@ static void handle_data_packet(struct mt_connection *curconn, struct mt_mactelne for (i = 0; i < 16; ++i) { curconn->enckey[i] = rand() % 256; } - curconn->have_enckey=1; + curconn->have_enckey = 1; memset(curconn->trypassword, 0, sizeof(curconn->trypassword)); } @@ -564,13 +564,17 @@ static void handle_data_packet(struct mt_connection *curconn, struct mt_mactelne got_user_packet = 1; } else if (cpkt.cptype == MT_CPTYPE_TERM_WIDTH) { - - curconn->terminal_width = cpkt.data[0] | (cpkt.data[1]<<8); + unsigned short width; + + memcpy(&width, cpkt.data, 2); + curconn->terminal_width = le16toh(width); got_width_packet = 1; } else if (cpkt.cptype == MT_CPTYPE_TERM_HEIGHT) { + unsigned short height; - curconn->terminal_height = cpkt.data[0] | (cpkt.data[1]<<8); + memcpy(&height, cpkt.data, 2); + curconn->terminal_height = le16toh(height); got_height_packet = 1; } else if (cpkt.cptype == MT_CPTYPE_TERM_TYPE) { @@ -750,11 +754,6 @@ static void daemonize() { fd = open("/dev/null",O_RDWR); dup(fd); dup(fd); - - signal(SIGCHLD,SIG_IGN); - signal(SIGTSTP,SIG_IGN); - signal(SIGTTOU,SIG_IGN); - signal(SIGTTIN,SIG_IGN); } static void print_version() { @@ -923,13 +922,14 @@ int main (int argc, char **argv) { if (!foreground) { daemonize(); - } else { - signal(SIGCHLD,SIG_IGN); - signal(SIGTSTP,SIG_IGN); - signal(SIGTTOU,SIG_IGN); - signal(SIGTTIN,SIG_IGN); } + /* Handle zombies etc */ + signal(SIGCHLD,SIG_IGN); + signal(SIGTSTP,SIG_IGN); + signal(SIGTTOU,SIG_IGN); + signal(SIGTTIN,SIG_IGN); + openlog("mactelnetd", LOG_PID, LOG_DAEMON); syslog(LOG_NOTICE, "Bound to %s:%d", inet_ntoa(si_me.sin_addr), sourceport); @@ -16,6 +16,7 @@ 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 <string.h> #include <stdio.h> #include <stdlib.h> @@ -25,6 +26,7 @@ #include <netinet/in.h> #include <netinet/ether.h> #include <time.h> +#include <endian.h> #include "protocol.h" #include "config.h" @@ -69,7 +71,6 @@ int init_packet(struct mt_packet *packet, enum mt_ptype ptype, unsigned char *sr } int add_control_packet(struct mt_packet *packet, enum mt_cptype cptype, void *cpdata, int data_len) { - unsigned int templen; unsigned char *data = packet->data + packet->size; /* Something is really wrong. Packets should never become over 1500 bytes */ @@ -95,11 +96,12 @@ int add_control_packet(struct mt_packet *packet, enum mt_cptype cptype, void *cp /* Data length */ #if BYTE_ORDER == LITTLE_ENDIAN - templen = data_len; - templen = htonl(templen); - memcpy(data + 5, &templen, sizeof(templen)); + { + unsigned int templen; + templen = htonl(data_len); + memcpy(data + 5, &templen, sizeof(templen)); + } #else -#pragma unused(templen) memcpy(data + 5, &data_len, sizeof(data_len)); #endif @@ -357,7 +359,7 @@ struct mt_mndp_info *parse_mndp(const unsigned char *data, const int packet_len) case MT_MNDPTYPE_TIMESTAMP: memcpy(&(packet.uptime), p, 4); -/* Seems like ping uptime is transmitted as little endian? */ + /* Seems like ping uptime is transmitted as little endian? */ packet.uptime = le32toh(packet.uptime); break; |