[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: X11 Forwarding example


I believe after you call the exec, and in your code you just wait, the program should actually be reading stdout from the remote. In that case, your code would read from there until the x11 program terminated and subsequently the read would fail.

Alex

--
Alexander Grotewohl
https://dcclost.com

________________________________
From: lucky62 <lucky62@xxxxxxxxxx>
Sent: Wednesday, November 18, 2020 8:33:10 AM
To: libssh@xxxxxxxxxx <libssh@xxxxxxxxxx>
Subject: Re: X11 Forwarding example

Hi,

I am trying to create x11 example by myself.

I have already created example skeleton with these steps:

  *       create the session
  *       set callbacks
  *       set options (host,...)
  *       connect to host
  *       authenticate
  *       create and open channel
  *       send x11-req
  *       send exec request (start X app on server)
     *   here the program is just sleeping for 5 seconds to wait for server response... (in while loop 5000 x 1ms)

This is my x11 callback, which is currently doing nothing - just to see that is called:

static ssh_channel x11_callback( ssh_session session, const char * originator_address, int originator_port, void *userdata ) {
   fprintf( stderr, "x11callback:\n" );
   fprintf( stderr, "   OrigAddr: |%s|\n", originator_address );
   fprintf( stderr, "   OrigPort: |%d|\n", originator_port );
   return NULL;
}


But when exec request is sent to the server and success confirmed then nothing happens immediately.
Program is waiting 5 seconds and x11 callback is called then. Why?

[2020/11/18 13:33:12.599888, 3] channel_request:  Sent a SSH_MSG_CHANNEL_REQUEST exec
[2020/11/18 13:33:12.602802, 3] ssh_packet_socket_callback:  packet: read type 93 [len=16,padding=6,comp=9,payload=9]
[2020/11/18 13:33:12.602862, 3] ssh_packet_process:  Dispatching handler for packet type 93
[2020/11/18 13:33:12.602897, 2] channel_rcv_change_window:  Adding 2097152 bytes to channel (43:0) (from 0 bytes)
[2020/11/18 13:33:12.602921, 3] ssh_packet_socket_callback:  Processing 36 bytes left in socket buffer
[2020/11/18 13:33:12.602944, 3] ssh_packet_socket_callback:  packet: read type 99 [len=16,padding=10,comp=5,payload=5]
[2020/11/18 13:33:12.602964, 3] ssh_packet_process:  Dispatching handler for packet type 99
[2020/11/18 13:33:12.602985, 3] ssh_packet_channel_success:  Received SSH_CHANNEL_SUCCESS on channel (43:0)
[2020/11/18 13:33:12.603006, 3] ssh_packet_need_rekey:  packet: [data_rekey_needed=0, out_blocks=44, in_blocks=67
[2020/11/18 13:33:12.603026, 3] ssh_packet_need_rekey:  packet: [data_rekey_needed=0, out_blocks=44, in_blocks=67
[2020/11/18 13:33:12.603049, 2] channel_request:  Channel request exec success
        5 seconds delay...
[2020/11/18 13:33:17.603149, 3] ssh_packet_need_rekey:  packet: [data_rekey_needed=0, out_blocks=44, in_blocks=67
[2020/11/18 13:33:17.603358, 3] ssh_socket_unbuffered_write:  Enabling POLLOUT for socket
[2020/11/18 13:33:17.603381, 3] packet_send2:  packet: wrote [type=96, len=16, padding_size=10, comp=5, payload=5]
[2020/11/18 13:33:17.603452, 3] ssh_channel_send_eof:  Sent a EOF on client channel (43:0)
[2020/11/18 13:33:17.603486, 3] ssh_packet_need_rekey:  packet: [data_rekey_needed=0, out_blocks=44, in_blocks=67
[2020/11/18 13:33:17.603521, 3] packet_send2:  packet: wrote [type=97, len=16, padding_size=10, comp=5, payload=5]
[2020/11/18 13:33:17.603543, 3] ssh_channel_close:  Sent a close on client channel (43:0)
[2020/11/18 13:33:17.603578, 3] ssh_packet_socket_callback:  packet: read type 90 [len=48,padding=10,comp=37,payload=37]
[2020/11/18 13:33:17.603601, 3] ssh_packet_process:  Dispatching handler for packet type 90
[2020/11/18 13:33:17.603624, 3] ssh_packet_channel_open:  Clients wants to open a x11 channel
x11callback:
   OrigAddr: |127.0.0.1|
   OrigPort: |55280|
[2020/11/18 13:33:17.603672, 3] ssh_packet_need_rekey:  packet: [data_rekey_needed=0, out_blocks=45, in_blocks=70
[2020/11/18 13:33:17.603703, 3] packet_send2:  packet: wrote [type=92, len=32, padding_size=14, comp=17, payload=17]
[2020/11/18 13:33:17.603733, 3] ssh_packet_need_rekey:  packet: [data_rekey_needed=0, out_blocks=45, in_blocks=69
[2020/11/18 13:33:17.603772, 3] ssh_socket_unbuffered_write:  Enabling POLLOUT for socket
[2020/11/18 13:33:17.603796, 3] ssh_packet_need_rekey:  packet: [data_rekey_needed=0, out_blocks=46, in_blocks=70
[2020/11/18 13:33:17.603831, 3] packet_send2:  packet: wrote [type=1, len=32, padding_size=11, comp=20, payload=20]



How to correctly wait for server response?
Any help is appreciated.

thx in advance
Jan


P.S.: My monolithic program is attached. Many things are hardcoded (auth, host, ..)
       Compiled on my Linux Mint 20 by command:  gcc -o my_x11_client my_x11_client.c -lssh

Follow-Ups:
Re: X11 Forwarding examplelucky62 <lucky62@xxxxxxxxxx>
References:
X11 Forwarding examplelucky62 <lucky62@xxxxxxxxxx>
Re: X11 Forwarding examplelucky62 <lucky62@xxxxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org