The following example illustrates how a client application written in C can use the SSH or Telnet protocol to establish a JUNOScript connection and session. In the line that begins with the string execlp, the client application invokes the ssh command. (Substitute the telnet command if appropriate.) The routing-platform argument to the execlp routine specifies the hostname or IP address of the JUNOScript server. The junoscript argument is the command that converts the connection to a JUNOScript session.
For more information about JUNOScript sessions, see Controlling the JUNOScript Session.
int ipipes[ 2 ], opipes[ 2 ];
pid_t pid;
int rc;
char buf[ BUFSIZ ];
if (pipe(ipipes) <0 || pipe(opipes) <0)
err(1, "pipe failed");
pid = fork( );
if (pid <0)
err(1, "fork failed");
if (pid == 0) {
dup2(opipes[ 0 ], STDIN_FILENO);
dup2(ipipes[ 1 ], STDOUT_FILENO);
dup2(ipipes[ 1 ], STDERR_FILENO);
close(ipipes[ 0 ]); /* close read end of pipe */
close(ipipes[ 1 ]); /* close write end of pipe */
close(opipes[ 0 ]); /* close read end of pipe */
close(opipes[ 1 ]); /* close write end of pipe */
execlp("ssh", "ssh", "-x", routing-platform , "junoscript", NULL);
err (1, "unable to execute: ssh %s junoscript," router);
}
close(ipipes[ 1 ]); /* close write end of pipe */
close(opipes[ 0 ]); /* close read end of pipe */
if (write(opipes[ 1 ], initial_handshake, strlen(initial_handshake)) <0 )
err(1, "writing initial handshake failed");
rc=read(ipipes[ 0 ], buf, sizeof(buf));
if (rc <0)
err(1, "read initial handshake failed");