110
111
TelOpenAndConnect(struct win *p) {
114
struct addrinfo hints, *res0, *res;
116
if (!(p->w_cmdargs[1])) {
117
Msg(0, "Usage: screen //telnet host [port]");
121
memset(&hints, 0, sizeof(hints));
122
hints.ai_family = af;
123
hints.ai_socktype = SOCK_STREAM;
124
hints.ai_protocol = IPPROTO_TCP;
125
if(getaddrinfo(p->w_cmdargs[1], p->w_cmdargs[2] ? p->w_cmdargs[2] : TEL_DEFPORT,
127
Msg(0, "unknown host: %s", p->w_cmdargs[1]);
131
for(res = res0; res; res = res->ai_next) {
132
if((fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == -1) {
136
Msg(errno, "TelOpenAndConnect: socket");
142
if (setsockopt(fd, SOL_SOCKET, SO_OOBINLINE, (char *)&on, sizeof(on)))
143
Msg(errno, "TelOpenAndConnect: setsockopt SO_OOBINLINE");
145
if (p->w_cmdargs[2] && strcmp(p->w_cmdargs[2], TEL_DEFPORT))
146
snprintf(buf, 256, "Trying %s %s...", p->w_cmdargs[1], p->w_cmdargs[2]);
148
snprintf(buf, 256, "Trying %s...", p->w_cmdargs[1]);
149
WriteString(p, buf, strlen(buf));
150
if (connect(fd, res->ai_addr, res->ai_addrlen)) {
151
if (errno == EINPROGRESS) {
152
p->w_telstate = TEL_CONNECTING;
153
p->w_telconnev.fd = fd;
154
p->w_telconnev.handler = tel_connev_fn;
155
p->w_telconnev.data = (char *)p;
156
p->w_telconnev.type = EV_WRITE;
157
p->w_telconnev.pri = 1;
158
debug("telnet connect in progress...\n");
159
evenq(&p->w_telconnev);
166
Msg(errno, "TelOpenAndConnect: connect");
173
WriteString(p, "connected.\r\n", 12);
174
if (!(p->w_cmdargs[2] && strcmp(p->w_cmdargs[2], TEL_DEFPORT)))
175
TelReply(p, (char *)tn_init, sizeof(tn_init));
177
memcpy(&p->w_telsa, &res->ai_addr, sizeof(res->ai_addr));
115
struct addrinfo hints, *res0, *res;
117
if (!(p->w_cmdargs[1])) {
118
Msg(0, "Usage: screen //telnet host [port]");
122
memset(&hints, 0, sizeof(hints));
123
hints.ai_family = af;
124
hints.ai_socktype = SOCK_STREAM;
125
hints.ai_protocol = IPPROTO_TCP;
127
if(getaddrinfo(p->w_cmdargs[1], p->w_cmdargs[2] ? p->w_cmdargs[2] : TEL_DEFPORT, &hints, &res0)) {
128
Msg(0, "unknown host: %s", p->w_cmdargs[1]);
132
for(res = res0; res; res = res->ai_next) {
133
if((fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == -1) {
137
Msg(errno, "TelOpenAndConnect: socket");
143
if (setsockopt(fd, SOL_SOCKET, SO_OOBINLINE, (char *)&on, sizeof(on)))
144
Msg(errno, "TelOpenAndConnect: setsockopt SO_OOBINLINE");
146
if (p->w_cmdargs[2] && strcmp(p->w_cmdargs[2], TEL_DEFPORT))
147
snprintf(buf, 256, "Trying %s %s...", p->w_cmdargs[1], p->w_cmdargs[2]);
149
snprintf(buf, 256, "Trying %s...", p->w_cmdargs[1]);
151
WriteString(p, buf, strlen(buf));
152
if (connect(fd, res->ai_addr, res->ai_addrlen)) {
153
if (errno == EINPROGRESS) {
154
p->w_telstate = TEL_CONNECTING;
155
p->w_telconnev.fd = fd;
156
p->w_telconnev.handler = tel_connev_fn;
157
p->w_telconnev.data = (char *)p;
158
p->w_telconnev.type = EV_WRITE;
159
p->w_telconnev.pri = 1;
160
debug("telnet connect in progress...\n");
161
evenq(&p->w_telconnev);
168
Msg(errno, "TelOpenAndConnect: connect");
175
WriteString(p, "connected.\r\n", 12);
177
if (!(p->w_cmdargs[2] && strcmp(p->w_cmdargs[2], TEL_DEFPORT)))
178
TelReply(p, (char *)tn_init, sizeof(tn_init));
181
memcpy(&p->w_telsa, &res->ai_addr, sizeof(res->ai_addr));