#include <termios.h>
#include <arpa/telnet.h>
#include <netinet/in.h>
-#include "busybox.h"
+#include "libbb.h"
#ifdef DOTRACE
#define TRACE(x, y) do { if (x) printf y; } while (0)
typedef unsigned char byte;
-
struct globals {
int netfd; /* console fd:s are 0 and 1 (and 2) */
short iaclen; /* could even use byte */
struct termios termios_def;
struct termios termios_raw;
};
-
-#define G (*(struct globals*)bb_common_bufsiz1)
-
+#define G (*(struct globals*)&bb_common_bufsiz1)
+void BUG_telnet_globals_too_big(void);
+#define INIT_G() do { \
+ if (sizeof(G) > COMMON_BUFSIZE) \
+ BUG_telnet_globals_too_big(); \
+ /* memset(&G, 0, sizeof G); - already is */ \
+} while (0)
/* Function prototypes */
static void rawmode(void);
else if (*p == 0x0d)
outbuf[j++] = 0x00;
}
- if (j > 0 )
+ if (j > 0)
write(G.netfd, outbuf, j);
}
}
#endif
-static char const escapecharis[] = "\r\nEscape character is ";
+static char const escapecharis[] ALIGN1 = "\r\nEscape character is ";
static void setConMode(void)
{
tcsetattr(0, TCSADRAIN, &G.termios_def);
}
-void BUG_telnet_globals_too_big(void);
-
-int telnet_main(int argc, char** argv);
-int telnet_main(int argc, char** argv)
+int telnet_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int telnet_main(int argc, char **argv)
{
char *host;
int port;
int maxfd;
#endif
- if (sizeof(G) > sizeof(bb_common_bufsiz1))
- BUG_telnet_globals_too_big();
- /* memset(&G, 0, sizeof G); - already is */
+ INIT_G();
#if ENABLE_FEATURE_AUTOWIDTH
get_terminal_width_height(0, &G.win_width, &G.win_height);
bb_show_usage();
#if ENABLE_FEATURE_TELNET_AUTOLOGIN
- if (1 & getopt32(argc, argv, "al:", &G.autologin))
+ if (1 & getopt32(argv, "al:", &G.autologin))
G.autologin = getenv("USER");
argv += optind;
#else