[lug] RE: reference/tutorial for connecting to port 23
matthew.w.mcillece at lmco.com
matthew.w.mcillece at lmco.com
Wed Jul 26 12:57:15 MDT 2000
This helps tremendously! Thanks much!
> -----Original Message-----
> From: Alan Robertson [SMTP:alanr at suse.com]
> Sent: Wednesday, July 26, 2000 12:50 PM
> To: lug at lug.boulder.co.us
> Cc: clue-talk at clue.denver.co.us
> Subject: CLUE-Talk: Re: [lug] reference/tutorial for connecting to
> port 23
>
> matthew.w.mcillece at lmco.com wrote:
> >
> > Does anyone know where I might find an explanation of how to
> automatically
> > pass the output of a distinct process to (and through) a connection such
> as
> > telnet? I've always expected telnet to be tied to the keyboard that
> > initiated the connection, but now need to pass characters generated by
> > another process through without user intervention, if possible. I've
> been
> > reading an IRIX Network Programming Guide but the discussion is not what
> I
> > can use. I've also grepped through all the Linux HOWTO's, but haven't
> found
> > anything quite on topic.
>
> Here's some GPLed code I wrote a week or so ago to do that:
> /*
> * Start a process with its stdin and stdout redirected to pipes
> * so the parent process can talk to it.
> */
> int
> StartProcess(const char * cmd, int * readfd, int * writefd)
> {
> pid_t pid;
> int wrpipe[2]; /* The pipe the parent process writes to
> */
> /* (which the child process reads from) */
> int rdpipe[2]; /* The pipe the parent process reads from
> */
> /* (which the child process writes to) */
>
> if (pipe(wrpipe) < 0) {
> perror("cannot create pipe\n");
> return(-1);
> }
> if (pipe(rdpipe) < 0) {
> perror("cannot create pipe\n");
> close(wrpipe[0]);
> close(wrpipe[1]);
> return(-1);
> }
> switch(pid=fork()) {
>
> case -1: perror("cannot StartProcess cmd");
> close(rdpipe[0]);
> close(wrpipe[1]);
> close(wrpipe[0]);
> close(rdpipe[1]);
> return(-1);
>
> case 0: /* We are the child */
>
> /* Redirect stdin */
> close(0);
> dup2(wrpipe[0], 0);
> close(wrpipe[0]);
> close(wrpipe[1]);
>
> /* Redirect stdout */
> close(1);
> dup2(rdpipe[1], 1);
> close(rdpipe[0]);
> close(rdpipe[1]);
>
> execlp("/bin/sh", "sh", "-c", cmd, NULL);
> perror("cannot exec shell!");
> exit(1);
>
> default: /* We are the parent */
> *readfd = rdpipe[0];
> close(rdpipe[1]);
>
> *writefd = wrpipe[1];
> close(wrpipe[0]);
> return(pid);
> }
> /*NOTREACHED*/
> return(-1);
> }
>
>
> Hope this helps... [I specifically use it with telnet...]
>
> -- Alan Robertson
> alanr at suse.com
More information about the LUG
mailing list