What magic did openssh do to handle programs like VIM?

Aaron Lewis the.warl0ck.1989 at gmail.com
Mon Feb 10 19:39:51 EST 2014


Hi,

I'm trying to write my own remote shell program,

It simply connects to a remote server then copy the sock fd to stdin,
stdout and stderr. And it works.

But I found several problems:
1. It doesn't handle characters like ^A ^E or tab (any bash/readline stuff)
    -> openssh itself doesn't seem to incorporate readline, so the
magic is not on           readline
2. If I run command like VIM, it doesn't run.
    And buttons like "<ESC>:q" won't work

Can someone enlighten me about what SSH did, so it all works perfectly?

Attached the prototype:

    int sockfd = socket(PF_INET, SOCK_STREAM, 0);
    struct sockaddr_in remaddr = { 0 };

    remaddr.sin_family = AF_INET;
    remaddr.sin_port = htons(9999);
    remaddr.sin_addr.s_addr = inet_addr("192.168.56.1");

    if (connect(sockfd, (struct sockaddr *)&remaddr, sizeof(struct sockaddr)))
        ERR_QUIT("connect");

    for (int i = 0; i < 2; ++i )
        dup2 (sockfd, i);
    execl("/bin/bash", "/bin/bash", "-i", NULL);



-- 
Best Regards,
Aaron Lewis - PGP: 0x13714D33 - http://pgp.mit.edu/
Finger Print:   9F67 391B B770 8FF6 99DC  D92D 87F6 2602 1371 4D33


More information about the openssh-unix-dev mailing list