/[LeafOK_CVS]/lbbs/src/bbs_net.c
ViewVC logotype

Diff of /lbbs/src/bbs_net.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.46 by sysadm, Wed Jun 4 13:42:53 2025 UTC Revision 1.48 by sysadm, Thu Jun 5 08:36:02 2025 UTC
# Line 36  Line 36 
36  #include <netinet/in.h>  #include <netinet/in.h>
37  #include <netinet/ip.h>  #include <netinet/ip.h>
38  #include <arpa/inet.h>  #include <arpa/inet.h>
39    #include <libssh/libssh.h>
40    #include <libssh/server.h>
41    #include <libssh/callbacks.h>
42    
43  #define MENU_CONF_DELIM " \t\r\n"  #define MENU_CONF_DELIM " \t\r\n"
44    
# Line 239  int bbsnet_connect(int n) Line 242  int bbsnet_connect(int n)
242          }          }
243    
244          sin.sin_family = AF_INET;          sin.sin_family = AF_INET;
245          sin.sin_addr.s_addr = (hostaddr_server[0] != '\0' ? inet_addr(hostaddr_server) : INADDR_ANY);          sin.sin_addr.s_addr = (BBS_address[0] != '\0' ? inet_addr(BBS_address) : INADDR_ANY);
246          sin.sin_port = 0;          sin.sin_port = 0;
247    
248          if (bind(sock, (struct sockaddr *)&sin, sizeof(sin)) < 0)          if (bind(sock, (struct sockaddr *)&sin, sizeof(sin)) < 0)
# Line 408  int bbsnet_connect(int n) Line 411  int bbsnet_connect(int n)
411    
412          while (loop && !SYS_server_exit)          while (loop && !SYS_server_exit)
413          {          {
414                    if (SSH_v2 && ssh_channel_is_closed(SSH_channel))
415                    {
416                            log_error("SSH channel is closed\n");
417                            loop = 0;
418                            break;
419                    }
420    
421                  nfds = epoll_wait(epollfd, events, MAX_EVENTS, 100); // 0.1 second                  nfds = epoll_wait(epollfd, events, MAX_EVENTS, 100); // 0.1 second
422    
423                  if (nfds < 0)                  if (nfds < 0)
# Line 435  int bbsnet_connect(int n) Line 445  int bbsnet_connect(int n)
445                                  stdin_read_wait = 1;                                  stdin_read_wait = 1;
446                                  while (input_buf_len < sizeof(input_buf) && !SYS_server_exit)                                  while (input_buf_len < sizeof(input_buf) && !SYS_server_exit)
447                                  {                                  {
448                                          ret = (int)read(STDIN_FILENO, input_buf + input_buf_len, sizeof(input_buf) - (size_t)input_buf_len);                                          if (SSH_v2)
449                                            {
450                                                    ret = ssh_channel_read_nonblocking(SSH_channel, input_buf + input_buf_len, sizeof(input_buf) - (uint32_t)input_buf_len, 0);
451                                                    if (ret == SSH_ERROR)
452                                                    {
453                                                            log_error("ssh_channel_read_nonblocking() error: %s\n", ssh_get_error(SSH_session));
454                                                            loop = 0;
455                                                            break;
456                                                    }
457                                                    else if (ret == SSH_EOF)
458                                                    {
459                                                            stdin_read_wait = 0;
460                                                            loop = 0;
461                                                            break;
462                                                    }
463                                                    else if (ret == 0)
464                                                    {
465                                                            stdin_read_wait = 0;
466                                                            break; // Check whether channel is still open
467                                                    }
468                                            }
469                                            else
470                                            {
471                                                    ret = (int)read(STDIN_FILENO, input_buf + input_buf_len, sizeof(input_buf) - (size_t)input_buf_len);
472                                            }
473                                          if (ret < 0)                                          if (ret < 0)
474                                          {                                          {
475                                                  if (errno == EAGAIN || errno == EWOULDBLOCK)                                                  if (errno == EAGAIN || errno == EWOULDBLOCK)
# Line 559  int bbsnet_connect(int n) Line 593  int bbsnet_connect(int n)
593                                  stdout_write_wait = 1;                                  stdout_write_wait = 1;
594                                  while (output_buf_offset < output_buf_len && !SYS_server_exit)                                  while (output_buf_offset < output_buf_len && !SYS_server_exit)
595                                  {                                  {
596                                          ret = (int)write(STDOUT_FILENO, output_buf + output_buf_offset, (size_t)(output_buf_len - output_buf_offset));                                          if (SSH_v2)
597                                            {
598                                                    ret = ssh_channel_write(SSH_channel, output_buf + output_buf_offset, (uint32_t)(output_buf_len - output_buf_offset));
599                                                    if (ret == SSH_ERROR)
600                                                    {
601                                                            log_error("ssh_channel_write() error: %s\n", ssh_get_error(SSH_session));
602                                                            loop = 0;
603                                                            break;
604                                                    }
605                                            }
606                                            else
607                                            {
608                                                    ret = (int)write(STDOUT_FILENO, output_buf + output_buf_offset, (size_t)(output_buf_len - output_buf_offset));
609                                            }
610                                          if (ret < 0)                                          if (ret < 0)
611                                          {                                          {
612                                                  if (errno == EAGAIN || errno == EWOULDBLOCK)                                                  if (errno == EAGAIN || errno == EWOULDBLOCK)
# Line 623  cleanup: Line 670  cleanup:
670          tm_used = gmtime(&t_used);          tm_used = gmtime(&t_used);
671    
672          log_common("BBSNET disconnect, %d days %d hours %d minutes %d seconds used\n",          log_common("BBSNET disconnect, %d days %d hours %d minutes %d seconds used\n",
673                          tm_used->tm_mday - 1, tm_used->tm_hour, tm_used->tm_min,                             tm_used->tm_mday - 1, tm_used->tm_hour, tm_used->tm_min,
674                          tm_used->tm_sec);                             tm_used->tm_sec);
675    
676          return 0;          return 0;
677  }  }
# Line 697  int bbs_net() Line 744  int bbs_net()
744                  ch = igetch(100);                  ch = igetch(100);
745                  switch (ch)                  switch (ch)
746                  {                  {
747                  case KEY_NULL:  // broken pipe                  case KEY_NULL: // broken pipe
748                  case KEY_ESC:                  case KEY_ESC:
749                  case Ctrl('C'): // user cancel                  case Ctrl('C'): // user cancel
750                          goto cleanup;                          goto cleanup;


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1