getproto.c (2605B)
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 * 9 * File: getproto.c 10 * 11 * A test program for PR_GetProtoByName and PR_GetProtoByNumber 12 * 13 ************************************************************************* 14 */ 15 16 #include "plstr.h" 17 #include "plerror.h" 18 #include "prinit.h" 19 #include "prprf.h" 20 #include "prnetdb.h" 21 #include "prerror.h" 22 23 int main(int argc, char** argv) { 24 PRFileDesc* prstderr = PR_GetSpecialFD(PR_StandardError); 25 PRBool failed = PR_FALSE; 26 PRProtoEnt proto; 27 char buf[2048]; 28 PRStatus rv; 29 30 rv = PR_GetProtoByName("tcp", buf, sizeof(buf), &proto); 31 if (PR_FAILURE == rv) { 32 failed = PR_TRUE; 33 PL_FPrintError(prstderr, "PR_GetProtoByName failed"); 34 } else if (6 != proto.p_num) { 35 PR_fprintf(prstderr, "tcp is usually 6, but is %d on this machine\n", 36 proto.p_num); 37 } else { 38 PR_fprintf(prstderr, "tcp is protocol number %d\n", proto.p_num); 39 } 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 } else if (17 != proto.p_num) { 46 PR_fprintf(prstderr, "udp is usually 17, but is %d on this machine\n", 47 proto.p_num); 48 } else { 49 PR_fprintf(prstderr, "udp is protocol number %d\n", proto.p_num); 50 } 51 52 rv = PR_GetProtoByNumber(6, buf, sizeof(buf), &proto); 53 if (PR_FAILURE == rv) { 54 failed = PR_TRUE; 55 PL_FPrintError(prstderr, "PR_GetProtoByNumber failed"); 56 } else if (PL_strcmp("tcp", proto.p_name)) { 57 PR_fprintf(prstderr, 58 "Protocol number 6 is usually tcp, but is %s" 59 " on this platform\n", 60 proto.p_name); 61 } else { 62 PR_fprintf(prstderr, "Protocol number 6 is %s\n", proto.p_name); 63 } 64 65 rv = PR_GetProtoByNumber(17, buf, sizeof(buf), &proto); 66 if (PR_FAILURE == rv) { 67 failed = PR_TRUE; 68 PL_FPrintError(prstderr, "PR_GetProtoByNumber failed"); 69 } else if (PL_strcmp("udp", proto.p_name)) { 70 PR_fprintf(prstderr, 71 "Protocol number 17 is usually udp, but is %s" 72 " on this platform\n", 73 proto.p_name); 74 } else { 75 PR_fprintf(prstderr, "Protocol number 17 is %s\n", proto.p_name); 76 } 77 78 PR_fprintf(prstderr, (failed) ? "FAILED\n" : "PASSED\n"); 79 return (failed) ? 1 : 0; 80 }