Subject: About "Channel open fail"..help pls

About "Channel open fail"..help pls

From: 이효신 <hwangyaksa_at_naver.com>
Date: Mon, 25 Aug 2014 09:03:10 +0900 (KST)

hello. i am lee from korea.
for ask ur help, write this mail. ^^
 
when i had made ssh module with libssh2, encounter Two error. and i cant solve this for 2 weeks.
 
first one, by sample code, libssh2_channel_open_session() did work just one time. i can open first channel .
after open and excute command line, read and close channel. and when retry open other channel, i can see this error message in debug panel " Unable to send channel-open request".
any information by FAQ useless for me..
 
and i try other way with libssh2_channel_direct_tcpip().
 
second problem, by sample code by FAQ info, i get some test code.
thsi one.
but just change err message. i cant open first channel. with message "Channel open failure"
 
os : window7
tool: microsoft visual studio 2010
 
any information, any advice! pls help
 
char request[]="GET /\n";
 char buffer[BUFSIZE];
 LIBSSH2_CHANNEL *channel;
 char *error;
 int rv;
 channel=libssh2_channel_direct_tcpip(session, "localhost", 3017);
 if(!channel) {
  libssh2_session_last_error(session, &amp;error, NULL, 0);
  fprintf(stderr, "libssh2_channel_direct_tcpip: %s\n", error);
  return 1;
 }
 if(libssh2_channel_write(channel, request, strlen(request)) &lt;= 0) {
  libssh2_session_last_error(session, &amp;error, NULL, 0);
  fprintf(stderr, "libssh2_channel_write: %s\n", error);
  return 1;
 }
 
 rv=libssh2_channel_read(channel, buffer, BUFSIZE-1);
 if(rv &lt;= 0) {
  libssh2_session_last_error(session, &amp;error, NULL, 0);
  fprintf(stderr, "libssh2_channel_read: %s\n", error);
  return 1;
 }
 buffer[rv]='\0';
 printf("%s\n", buffer);
 libssh2_channel_free(channel);
 return 0;
}
 
int test7() {
 struct hostent *hen;
 struct sockaddr_in sin;
 int ssh_socket;
 char *error;
 LIBSSH2_SESSION *ssh_session;
  ssh_socket = socket(AF_INET, SOCK_STREAM, 0);
 if(ssh_socket &lt; 0) {
  perror("socket");
  return 1;
 }
 sin.sin_family = AF_INET;
 sin.sin_port = htons(22);
 hen=gethostbyname("xxx.xxx.xxx.xxx");
 if(!hen) {
// fprintf(stderr, "gethostbyname: %s", hstrerror(h_errno));
  return 1;
 }
 memcpy(&amp;(sin.sin_addr.s_addr), hen-&gt;h_addr_list[0], hen-&gt;h_length);
 
 if ( connect(ssh_socket, (struct sockaddr*)(&amp;sin), sizeof(struct sockaddr_in)) ) {
  perror("connect");
  //return 1;
 }
 
 ssh_session = libssh2_session_init();
 
 if (libssh2_session_startup(ssh_session, ssh_socket)) {
  libssh2_session_last_error(ssh_session, &amp;error, NULL, 0);
  fprintf(stderr, "libssh2_session_startup: %s\n", error);
  return 1;
 }
 
 if(libssh2_userauth_password(ssh_session, "id", "pw")) {
  libssh2_session_last_error(ssh_session, &amp;error, NULL, 0);
  fprintf(stderr, "libssh2_userauth_password: %s\n", error);
  return 1;
 }
 if(do_channel(ssh_session)) return 1;
 if(do_channel(ssh_session)) return 1;
 return 0;
}
 
 
 

_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2014-08-25