You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
3.7 KiB

  1. From 1479d3acc7ffb77225ea294f83a8d3fbdadfece6 Mon Sep 17 00:00:00 2001
  2. From: Michael Heimpold <mhei@heimpold.de>
  3. Date: Thu, 13 Apr 2017 20:37:35 +0200
  4. Subject: [PATCH] dataxfer.c: in case port is not connected display this
  5. directly
  6. In this case we don't bother to call into getnameinfo but show
  7. directly "unconnected", this prevents showing an error message.
  8. Signed-off-by: Michael Heimpold <mhei@heimpold.de>
  9. Signed-off-by: Corey Minyard <cminyard@mvista.com>
  10. diff --git a/dataxfer.c b/dataxfer.c
  11. index 9955403..d6a59d9 100644
  12. --- a/dataxfer.c
  13. +++ b/dataxfer.c
  14. @@ -3700,19 +3700,23 @@ showshortport(struct controller_info *cntlr, port_info_t *port)
  15. if (!netcon)
  16. netcon = &(port->netcons[0]);
  17. - err = getnameinfo(netcon->raddr, netcon->raddrlen,
  18. - buffer, sizeof(buffer),
  19. - portbuff, sizeof(portbuff),
  20. - NI_NUMERICHOST | NI_NUMERICSERV);
  21. - if (err) {
  22. - snprintf(buffer, sizeof(buffer), "*err*,%s", gai_strerror(err));
  23. - /* gai_strerror could return an elongated string which could break
  24. - our pretty formatted output below, so truncate the string nicely */
  25. - if (strlen(buffer) > REMOTEADDR_COLUMN_WIDTH)
  26. - strcpy(&buffer[REMOTEADDR_COLUMN_WIDTH - 3], "...");
  27. - count = controller_outputf(cntlr, "%s", buffer);
  28. + if (port->net_to_dev_state != PORT_UNCONNECTED) {
  29. + err = getnameinfo(netcon->raddr, netcon->raddrlen,
  30. + buffer, sizeof(buffer),
  31. + portbuff, sizeof(portbuff),
  32. + NI_NUMERICHOST | NI_NUMERICSERV);
  33. + if (err) {
  34. + snprintf(buffer, sizeof(buffer), "*err*,%s", gai_strerror(err));
  35. + /* gai_strerror could return an elongated string which could break
  36. + our pretty formatted output below, so truncate the string nicely */
  37. + if (strlen(buffer) > REMOTEADDR_COLUMN_WIDTH)
  38. + strcpy(&buffer[REMOTEADDR_COLUMN_WIDTH - 3], "...");
  39. + count = controller_outputf(cntlr, "%s", buffer);
  40. + } else {
  41. + count = controller_outputf(cntlr, "%s,%s", buffer, portbuff);
  42. + }
  43. } else {
  44. - count = controller_outputf(cntlr, "%s,%s", buffer, portbuff);
  45. + count = controller_outputf(cntlr, "unconnected");
  46. }
  47. while (count < REMOTEADDR_COLUMN_WIDTH + 1) {
  48. @@ -3762,21 +3766,25 @@ showport(struct controller_info *cntlr, port_info_t *port)
  49. controller_outputf(cntlr, " timeout: %d\r\n", port->timeout);
  50. for_each_connection(port, netcon) {
  51. - err = getnameinfo(netcon->raddr, netcon->raddrlen,
  52. - buffer, sizeof(buffer),
  53. - portbuff, sizeof(portbuff),
  54. - NI_NUMERICHOST | NI_NUMERICSERV);
  55. - if (err) {
  56. - snprintf(buffer, sizeof(buffer), "*err*,%s", gai_strerror(err));
  57. - controller_outputf(cntlr, " connected to: %s\r\n", buffer);
  58. + if (port->net_to_dev_state != PORT_UNCONNECTED) {
  59. + err = getnameinfo(netcon->raddr, netcon->raddrlen,
  60. + buffer, sizeof(buffer),
  61. + portbuff, sizeof(portbuff),
  62. + NI_NUMERICHOST | NI_NUMERICSERV);
  63. + if (err) {
  64. + snprintf(buffer, sizeof(buffer), "*err*,%s", gai_strerror(err));
  65. + controller_outputf(cntlr, " connected to: %s\r\n", buffer);
  66. + } else {
  67. + controller_outputf(cntlr, " connected to: %s,%s\r\n",
  68. + buffer, portbuff);
  69. + }
  70. + controller_outputf(cntlr, " bytes read from TCP: %d\r\n",
  71. + netcon->bytes_received);
  72. + controller_outputf(cntlr, " bytes written to TCP: %d\r\n",
  73. + netcon->bytes_sent);
  74. } else {
  75. - controller_outputf(cntlr, " connected to: %s,%s\r\n",
  76. - buffer, portbuff);
  77. + controller_outputf(cntlr, " unconnected\r\n");
  78. }
  79. - controller_outputf(cntlr, " bytes read from TCP: %d\r\n",
  80. - netcon->bytes_received);
  81. - controller_outputf(cntlr, " bytes written to TCP: %d\r\n",
  82. - netcon->bytes_sent);
  83. }
  84. controller_outputf(cntlr, " device: %s\r\n", port->io.devname);
  85. --
  86. 2.7.4