7
#include <sys/socket.h>
10
#if defined (HAVE_SYS_TERMIOS_H)
11
#include <sys/termios.h>
13
#if defined (HAVE_TERMIOS_H)
18
#if defined (HAVE_TERMIO_H)
21
#define TIOCGETA TCGETA
22
#define TIOCSETAF TCSETAF
28
#define termios termio
29
#define tcflag_t ushort
32
#ifdef HAVE_SYS_IOCTL_H
33
#include <sys/ioctl.h>
38
#define DEFAULTPORT "2947"
41
extern char *device_name;
42
extern int device_speed;
45
/* define global variables */
47
struct termios ttyset, ttyset_old;
55
temp = malloc (strlen (device_name) + 1);
56
strcpy (temp, device_name);
58
if ((p = strchr (temp, ':')))
60
char *port = DEFAULTPORT;
67
/* temp now holds the HOSTNAME portion and port the port number. */
69
fprintf (stderr, "Host: %s Port: %s\n", temp, port);
70
ttyfd = connectTCP (temp, port);
74
setsockopt (ttyfd, SOL_SOCKET, SO_REUSEADDR, (char *) &one,
77
if (write (ttyfd, "r\n", 2) != 2)
78
errexit ("Can't write to socket");
82
ttyfd = open (temp, O_RDWR | O_NONBLOCK);
91
/* Save original terminal parameters */
92
if (tcgetattr (ttyfd, &ttyset_old) != 0)
95
if (ioctl (ttyfd, TIOCGETA, &ttyset) < 0)
98
#if defined (USE_TERMIO)
99
ttyset.c_cflag = CBAUD & device_speed;
101
ttyset.c_ispeed = device_speed;
102
ttyset.c_ospeed = device_speed;
104
ttyset.c_cflag &= ~(PARENB | CRTSCTS);
105
ttyset.c_cflag |= (CSIZE & CS8) | CREAD | CLOCAL;
106
ttyset.c_iflag = ttyset.c_oflag = ttyset.c_lflag = (tcflag_t) 0;
107
ttyset.c_oflag = (ONLCR);
108
if (ioctl (ttyfd, TIOCSETAF, &ttyset) < 0)
122
#if defined (USE_TERMIO)
123
ttyset.c_cflag = CBAUD & B0;
125
ttyset.c_ispeed = B0;
126
ttyset.c_ospeed = B0;
128
ioctl (ttyfd, TIOCSETAF, &ttyset);
130
/* Restore original terminal parameters */
131
tcsetattr (ttyfd, TCSANOW, &ttyset_old);