Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > uk.comp.sys.mac > #119753
| From | richard@cogsci.ed.ac.uk (Richard Tobin) |
|---|---|
| Newsgroups | uk.comp.sys.mac |
| Subject | Re: High Sierra - telnet gone? |
| Date | 2017-10-05 09:17 +0000 |
| Organization | Language Technology Group, University of Edinburgh |
| Message-ID | <or4tbo$hc3$1@macpro.inf.ed.ac.uk> (permalink) |
| References | <f3ikqdFrvgfU1@mid.individual.net> <f3ku1rFdls2U1@mid.individual.net> <f3l0t3Feak0U1@mid.individual.net> <f3mb3sFn7rhU1@mid.individual.net> |
In article <f3mb3sFn7rhU1@mid.individual.net>,
Ian McCall <ian@eruvia.org> wrote:
>Hmm. Can you use netcat for interactive?
>
>ie. the:
>
>telnet some.host.invalid
>EHLO
>MAIL From:
>....etc...
If not, it's easy to write a C program to do it. Here's one I wrote
some time ago. It will produce warnings when compiled because things
have changed since then...
/* Copyright Richard Tobin 1991 and 2017 */
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <netdb.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#define FAMILY(s) s.addr.sa_family
#define NAMELEN(s) (FAMILY(s) == AF_INET \
? sizeof(s.inaddr) \
: strlen(s.unaddr.sun_path) + sizeof(s.unaddr) - sizeof(s.unaddr.sun_path))
void usage();
int transfer();
int main(argc,argv)
char *argv[];
{
union {struct sockaddr addr;
struct sockaddr_un unaddr;
struct sockaddr_in inaddr;} s;
struct hostent *serverhost;
int fd, fd1, c, family = AF_UNSPEC, server = -1;
extern char *optarg;
extern int optind, opterr;
while((c = getopt(argc, argv, "uisc")) != EOF)
switch(c)
{
case 'u':
family = AF_UNIX;
break;
case 'i':
family = AF_INET;
break;
case 's':
server = 1;
break;
case 'c':
server = 0;
break;
default:
usage();
}
if(family == AF_UNSPEC || server == -1)
usage();
if((family == AF_UNIX && (argc - optind) != 1) ||
(family == AF_INET && (argc - optind) != (server ? 1 : 2)))
usage();
fd = socket(family, SOCK_STREAM, 0);
if(fd < 0)
{
perror("socket: socket failed");
exit(1);
}
if(server)
{
switch(family)
{
case AF_UNIX:
unlink(argv[argc-1]);
s.unaddr.sun_family = AF_UNIX;
strcpy(s.unaddr.sun_path, argv[optind]);
break;
case AF_INET:
bzero(&s.inaddr, sizeof(s.inaddr));
s.inaddr.sin_family = AF_INET;
s.inaddr.sin_port = htons(atoi(argv[argc-1]));
break;
}
if(bind(fd, &s.addr, NAMELEN(s)) != 0)
{
perror("socket: bind failed");
exit(1);
}
if(listen(fd, 5) != 0)
{
perror("socket: listen failed");
exit(1);
}
while(1)
{
fprintf(stderr, "waiting\n");
if((fd1 = accept(fd, 0, 0)) < 0)
{
perror("socket: accept failed");
exit(1);
}
fprintf(stderr, "transferring\n");
if(transfer(fd1, fd1) < 0)
exit(1);
fprintf(stderr, "closing\n");
close(fd1);
}
}
else
{
switch(family)
{
case AF_UNIX:
s.unaddr.sun_family = AF_UNIX;
strcpy (s.unaddr.sun_path, argv[argc-1]);
break;
case AF_INET:
bzero(&s.inaddr, sizeof(s.inaddr));
serverhost = gethostbyname(argv[argc-2]);
if(serverhost == (struct hostent *)0)
{
perror("socket: gethostbyname failed");
exit(1);
}
bcopy(serverhost->h_addr,&s.inaddr.sin_addr, serverhost->h_length);
s.inaddr.sin_family = AF_INET;
s.inaddr.sin_port = htons(atoi(argv[argc-1]));
}
if(connect(fd, &s.addr, NAMELEN(s)) != 0)
{
perror("socket: connect failed");
exit(1);
}
transfer(fd, 0);
exit(0);
}
}
int transfer(fd, clientfd)
int fd;
{
int i, infds, nread;
char buf[256];
infds = (1 << 0) | (1 << fd);
while(infds != 0)
{
i = infds;
if(select(32, &i, (long *)0, (long *)0, (struct timeval *)0) < 0)
{
perror("socket: select");
return -1;
}
if(i & (1 << fd))
{
nread = read(fd, buf, sizeof(buf));
if(nread < 0)
{
perror("socket: read from socket");
return -1;
}
if(nread == 0)
{
fprintf(stderr, "eof on socket\n");
#if 0
if(fd == clientfd)
return 0;
else
#endif
infds &= ~(1 << fd);
}
else
write(1, buf, nread); /* /\/ */
}
if(i & (1 << 0))
{
nread = read(0, buf, sizeof(buf));
if(nread < 0)
{
perror("socket: read from stdin");
return -1;
}
if(nread == 0)
{
fprintf(stderr, "eof on stdin\n");
shutdown(fd, 1);
#if 0
if(0 == clientfd)
return 0;
else
#endif
infds &= ~(1 << 0);
}
else
write(fd, buf, nread); /* /\/ */
}
}
return 0;
}
void usage()
{
fprintf(stderr, "usage: socket role type name\n");
fprintf(stderr, " where role is -s[erver] or -c[lient],\n");
fprintf(stderr, " type is -u[nix] or -i[nternet], and\n");
fprintf(stderr, " name is filename or host (if client) and port.\n");
exit(2);
}
Back to uk.comp.sys.mac | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
High Sierra - telnet gone? Ian McCall <ian@eruvia.org> - 2017-10-04 00:29 +0100
Re: High Sierra - telnet gone? dempson@actrix.gen.nz (David Empson) - 2017-10-04 13:26 +1300
Re: High Sierra - telnet gone? italiancar@gmail.com (Steve H) - 2017-10-04 07:49 +0100
Re: High Sierra - telnet gone? Ian McCall <ian@eruvia.org> - 2017-10-04 09:27 +0100
Re: High Sierra - telnet gone? Huge <Huge@nowhere.much.invalid> - 2017-10-04 08:48 +0000
Re: High Sierra - telnet gone? Paul Sture <nospam@sture.ch> - 2017-10-04 13:13 +0200
Re: High Sierra - telnet gone? Paul Sture <nospam@sture.ch> - 2017-10-04 13:09 +0200
Re: High Sierra - telnet gone? nospam <nospam@nospam.invalid> - 2017-10-04 10:20 -0400
Re: High Sierra - telnet gone? Paul Sture <nospam@sture.ch> - 2017-10-04 16:59 +0200
Re: High Sierra - telnet gone? Huge <Huge@nowhere.much.invalid> - 2017-10-04 15:20 +0000
Re: High Sierra - telnet gone? Ian McCall <ian@eruvia.org> - 2017-10-04 21:19 +0100
Re: High Sierra - telnet gone? Jaimie Vandenbergh <jaimie@sometimes.sessile.org> - 2017-10-04 21:25 +0100
Re: High Sierra - telnet gone? nospam <nospam@nospam.invalid> - 2017-10-04 16:32 -0400
Re: High Sierra - telnet gone? Huge <Huge@nowhere.much.invalid> - 2017-10-04 21:07 +0000
Re: High Sierra - telnet gone? Ian McCall <ian@eruvia.org> - 2017-10-05 10:08 +0100
Re: High Sierra - telnet gone? richard@cogsci.ed.ac.uk (Richard Tobin) - 2017-10-05 09:17 +0000
Re: High Sierra - telnet gone? real-not-anti-spam-address@apple-juice.co.uk (D.M. Procida) - 2017-10-06 15:50 +0100
Re: High Sierra - telnet gone? Huge <Huge@nowhere.much.invalid> - 2017-10-05 09:27 +0000
Re: High Sierra - telnet gone? Ian McCall <ian@eruvia.org> - 2017-10-05 11:52 +0100
Re: High Sierra - telnet gone? Huge <Huge@nowhere.much.invalid> - 2017-10-05 11:04 +0000
Re: High Sierra - telnet gone? Ian McCall <ian@eruvia.org> - 2017-10-05 12:38 +0100
Re: High Sierra - telnet gone? Ian McCall <ian@eruvia.org> - 2017-10-05 12:42 +0100
Re: High Sierra - telnet gone? Huge <Huge@nowhere.much.invalid> - 2017-10-05 11:44 +0000
Re: High Sierra - telnet gone? Paul Sture <nospam@sture.ch> - 2017-10-05 13:29 +0200
Re: High Sierra - telnet gone? Paul Sture <nospam@sture.ch> - 2017-10-05 12:41 +0200
Re: High Sierra - telnet gone? nospam <nospam@nospam.invalid> - 2017-10-04 11:35 -0400
Re: High Sierra - telnet gone? Jaimie Vandenbergh <jaimie@sometimes.sessile.org> - 2017-10-04 17:55 +0100
Re: High Sierra - telnet gone? Paul Sture <nospam@sture.ch> - 2017-10-05 02:14 +0200
Re: High Sierra - telnet gone? Chris Ridd <chrisridd@mac.com> - 2017-10-04 19:13 +0100
Re: High Sierra - telnet gone? stk.usenet@haller-berlin.de (Stefan Haller) - 2017-10-05 09:10 +0200
Re: High Sierra - telnet gone? Huge <Huge@nowhere.much.invalid> - 2017-10-05 08:53 +0000
Re: High Sierra - telnet gone? nospam <nospam@nospam.invalid> - 2017-10-05 09:49 -0400
Re: High Sierra - telnet gone? italiancar@gmail.com (Steve H) - 2017-10-07 15:06 +0100
Re: High Sierra - telnet gone? Huge <Huge@nowhere.much.invalid> - 2017-10-07 15:55 +0000
Re: High Sierra - telnet gone? Ray <buggeroff@outlook.corn> - 2017-10-08 06:53 +0100
csiph-web