您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

hostport.cxx 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* Copyright 2016 Pierre Ossman <ossman@cendio.se> for Cendio AB
  2. *
  3. * This is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This software is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this software; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  16. * USA.
  17. */
  18. #include <stdio.h>
  19. #include <rfb/Hostname.h>
  20. static void doTest(const char* hostAndPort,
  21. const char* expectedHost, int expectedPort)
  22. {
  23. char* host;
  24. int port;
  25. printf("\"%s\": ", hostAndPort);
  26. rfb::getHostAndPort(hostAndPort, &host, &port);
  27. if (strcmp(host, expectedHost) != 0)
  28. printf("FAILED (\"%s\" != \"%s\")", host, expectedHost);
  29. else if (port != expectedPort)
  30. printf("FAILED (%d != %d)", port, expectedPort);
  31. else
  32. printf("OK");
  33. printf("\n");
  34. fflush(stdout);
  35. rfb::strFree(host);
  36. }
  37. int main(int argc, char** argv)
  38. {
  39. doTest(":5", "localhost", 5905);
  40. doTest("1.2.3.4", "1.2.3.4", 5900);
  41. doTest("1.2.3.4:5", "1.2.3.4", 5905);
  42. doTest("1.2.3.4:99", "1.2.3.4", 5999);
  43. doTest("1.2.3.4:100", "1.2.3.4", 100);
  44. doTest("1.2.3.4:5901", "1.2.3.4", 5901);
  45. doTest("1.2.3.4::5", "1.2.3.4", 5);
  46. doTest("1.2.3.4::99", "1.2.3.4", 99);
  47. doTest("1.2.3.4::5901", "1.2.3.4", 5901);
  48. doTest("[1.2.3.4]", "1.2.3.4", 5900);
  49. doTest("[1.2.3.4]:5", "1.2.3.4", 5905);
  50. doTest("[1.2.3.4]:100", "1.2.3.4", 100);
  51. doTest("[1.2.3.4]::5", "1.2.3.4", 5);
  52. doTest("[1.2.3.4]::100", "1.2.3.4", 100);
  53. // Ambigiuous. For now we'll keep the old behaviour...
  54. doTest("::1", "localhost", 1);
  55. doTest("2001:1234::20:1", "2001:1234::20:1", 5900);
  56. doTest("[::1]", "::1", 5900);
  57. doTest("[2001:1234::20:1]", "2001:1234::20:1", 5900);
  58. doTest("[2001:1234::20:1]:5", "2001:1234::20:1", 5905);
  59. doTest("[2001:1234::20:1]:99", "2001:1234::20:1", 5999);
  60. doTest("[2001:1234::20:1]:100", "2001:1234::20:1", 100);
  61. doTest("[2001:1234::20:1]:5901", "2001:1234::20:1", 5901);
  62. return 0;
  63. }