getproto.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. /*
  6. *************************************************************************
  7. *
  8. * File: getproto.c
  9. *
  10. * A test program for PR_GetProtoByName and PR_GetProtoByNumber
  11. *
  12. *************************************************************************
  13. */
  14. #include "plstr.h"
  15. #include "plerror.h"
  16. #include "prinit.h"
  17. #include "prprf.h"
  18. #include "prnetdb.h"
  19. #include "prerror.h"
  20. int main(int argc, char **argv)
  21. {
  22. PRFileDesc *prstderr = PR_GetSpecialFD(PR_StandardError);
  23. PRBool failed = PR_FALSE;
  24. PRProtoEnt proto;
  25. char buf[2048];
  26. PRStatus rv;
  27. PR_STDIO_INIT();
  28. rv = PR_GetProtoByName("tcp", buf, sizeof(buf), &proto);
  29. if (PR_FAILURE == rv) {
  30. failed = PR_TRUE;
  31. PL_FPrintError(prstderr, "PR_GetProtoByName failed");
  32. }
  33. else if (6 != proto.p_num) {
  34. PR_fprintf(
  35. prstderr,"tcp is usually 6, but is %d on this machine\n",
  36. proto.p_num);
  37. }
  38. else {
  39. PR_fprintf(prstderr, "tcp is protocol number %d\n", proto.p_num);
  40. }
  41. rv = PR_GetProtoByName("udp", buf, sizeof(buf), &proto);
  42. if (PR_FAILURE == rv) {
  43. failed = PR_TRUE;
  44. PL_FPrintError(prstderr, "PR_GetProtoByName failed");
  45. }
  46. else if (17 != proto.p_num) {
  47. PR_fprintf(
  48. prstderr, "udp is usually 17, but is %d on this machine\n",
  49. proto.p_num);
  50. }
  51. else {
  52. PR_fprintf(prstderr, "udp is protocol number %d\n", proto.p_num);
  53. }
  54. rv = PR_GetProtoByNumber(6, buf, sizeof(buf), &proto);
  55. if (PR_FAILURE == rv) {
  56. failed = PR_TRUE;
  57. PL_FPrintError(prstderr, "PR_GetProtoByNumber failed");
  58. }
  59. else if (PL_strcmp("tcp", proto.p_name)) {
  60. PR_fprintf(
  61. prstderr, "Protocol number 6 is usually tcp, but is %s"
  62. " on this platform\n", proto.p_name);
  63. }
  64. else {
  65. PR_fprintf(prstderr, "Protocol number 6 is %s\n", proto.p_name);
  66. }
  67. rv = PR_GetProtoByNumber(17, buf, sizeof(buf), &proto);
  68. if (PR_FAILURE == rv) {
  69. failed = PR_TRUE;
  70. PL_FPrintError(prstderr, "PR_GetProtoByNumber failed");
  71. }
  72. else if (PL_strcmp("udp", proto.p_name)) {
  73. PR_fprintf(
  74. prstderr, "Protocol number 17 is usually udp, but is %s"
  75. " on this platform\n", proto.p_name);
  76. }
  77. else {
  78. PR_fprintf(prstderr, "Protocol number 17 is %s\n", proto.p_name);
  79. }
  80. PR_fprintf(prstderr, (failed) ? "FAILED\n" : "PASSED\n");
  81. return (failed) ? 1 : 0;
  82. }