home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / pr / tests / getproto.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  3.2 KB  |  96 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. /*
  20.  *************************************************************************
  21.  *
  22.  * File: getproto.c
  23.  *
  24.  * A test program for PR_GetProtoByName and PR_GetProtoByNumber
  25.  *
  26.  *************************************************************************
  27.  */
  28.  
  29. #include "plstr.h"
  30. #include "plerror.h"
  31. #include "prinit.h"
  32. #include "prprf.h"
  33. #include "prnetdb.h"
  34. #include "prerror.h"
  35.  
  36. int main()
  37. {
  38.     PRFileDesc *prstderr = PR_GetSpecialFD(PR_StandardError);
  39.     PRBool failed = PR_FALSE;
  40.     PRProtoEnt proto;
  41.     char buf[2048];
  42.     PRStatus rv;
  43.  
  44.     PR_STDIO_INIT();
  45.     rv = PR_GetProtoByName("tcp", buf, sizeof(buf), &proto);
  46.     if (PR_FAILURE == rv) {
  47.         failed = PR_TRUE;
  48.         PL_FPrintError(prstderr, "PR_GetProtoByName failed");
  49.     }
  50.     else if (6 != proto.p_num) {
  51.         PR_fprintf(
  52.             prstderr,"tcp is usually 6, but is %d on this machine\n",
  53.             proto.p_num);
  54.     }
  55.     else PR_fprintf(prstderr, "tcp is protocol number %d\n", proto.p_num);
  56.  
  57.     rv = PR_GetProtoByName("udp", buf, sizeof(buf), &proto);
  58.     if (PR_FAILURE == rv) {
  59.         failed = PR_TRUE;
  60.         PL_FPrintError(prstderr, "PR_GetProtoByName failed");
  61.     }
  62.     else if (17 != proto.p_num) {
  63.         PR_fprintf(
  64.             prstderr, "udp is usually 17, but is %d on this machine\n",
  65.             proto.p_num);
  66.     }
  67.     else PR_fprintf(prstderr, "udp is protocol number %d\n", proto.p_num);
  68.  
  69.     rv = PR_GetProtoByNumber(6, buf, sizeof(buf), &proto);
  70.     if (PR_FAILURE == rv) {
  71.         failed = PR_TRUE;
  72.         PL_FPrintError(prstderr, "PR_GetProtoByNumber failed");
  73.     }
  74.     else if (PL_strcmp("tcp", proto.p_name)) {
  75.         PR_fprintf(
  76.             prstderr, "Protocol number 6 is usually tcp, but is %s"
  77.             " on this platform\n", proto.p_name);
  78.     }
  79.     else PR_fprintf(prstderr, "Protocol number 6 is %s\n", proto.p_name);
  80.  
  81.     rv = PR_GetProtoByNumber(17, buf, sizeof(buf), &proto);
  82.     if (PR_FAILURE == rv) {
  83.         failed = PR_TRUE;
  84.         PL_FPrintError(prstderr, "PR_GetProtoByNumber failed");
  85.     }
  86.     else if (PL_strcmp("udp", proto.p_name)) {
  87.         PR_fprintf(
  88.             prstderr, "Protocol number 17 is usually udp, but is %s"
  89.             " on this platform\n", proto.p_name);
  90.     }
  91.     else PR_fprintf(prstderr, "Protocol number 17 is %s\n", proto.p_name);
  92.  
  93.     PR_fprintf(prstderr, (failed) ? "FAILED\n" : "PASSED\n");
  94.     return (failed) ? 1 : 0;
  95. }
  96.