#include <unistd.h>
#include <sys/types.h>
#include <sys/time.h>

int main()
{
  struct timeval tv;
  fd_set set;
  tv.tv_sec = 2;
  tv.tv_usec = 0;
  FD_ZERO(&set);
  FD_SET(0, &set);

  if (select(1, &set, NULL, NULL, &tv)) {
    /* Got data from the client side - it must be his https-request. */
    /* FIXME: analyze it, it could be the client ssh greeting */
    execl("/usr/bin/nc", "/usr/bin/nc", "localhost", "444", NULL);
  } else {
    /* No data sent by the client - it must be waiting for the ssh
       greeting from the server. Connect it to the sshd server. */
    execl("/usr/bin/nc", "/usr/bin/nc", "localhost", "ssh", NULL);
  }
}
