1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/nsprpub/pr/tests/getproto.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,82 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* 1.10 + ************************************************************************* 1.11 + * 1.12 + * File: getproto.c 1.13 + * 1.14 + * A test program for PR_GetProtoByName and PR_GetProtoByNumber 1.15 + * 1.16 + ************************************************************************* 1.17 + */ 1.18 + 1.19 +#include "plstr.h" 1.20 +#include "plerror.h" 1.21 +#include "prinit.h" 1.22 +#include "prprf.h" 1.23 +#include "prnetdb.h" 1.24 +#include "prerror.h" 1.25 + 1.26 +int main(int argc, char **argv) 1.27 +{ 1.28 + PRFileDesc *prstderr = PR_GetSpecialFD(PR_StandardError); 1.29 + PRBool failed = PR_FALSE; 1.30 + PRProtoEnt proto; 1.31 + char buf[2048]; 1.32 + PRStatus rv; 1.33 + 1.34 + PR_STDIO_INIT(); 1.35 + rv = PR_GetProtoByName("tcp", buf, sizeof(buf), &proto); 1.36 + if (PR_FAILURE == rv) { 1.37 + failed = PR_TRUE; 1.38 + PL_FPrintError(prstderr, "PR_GetProtoByName failed"); 1.39 + } 1.40 + else if (6 != proto.p_num) { 1.41 + PR_fprintf( 1.42 + prstderr,"tcp is usually 6, but is %d on this machine\n", 1.43 + proto.p_num); 1.44 + } 1.45 + else PR_fprintf(prstderr, "tcp is protocol number %d\n", proto.p_num); 1.46 + 1.47 + rv = PR_GetProtoByName("udp", buf, sizeof(buf), &proto); 1.48 + if (PR_FAILURE == rv) { 1.49 + failed = PR_TRUE; 1.50 + PL_FPrintError(prstderr, "PR_GetProtoByName failed"); 1.51 + } 1.52 + else if (17 != proto.p_num) { 1.53 + PR_fprintf( 1.54 + prstderr, "udp is usually 17, but is %d on this machine\n", 1.55 + proto.p_num); 1.56 + } 1.57 + else PR_fprintf(prstderr, "udp is protocol number %d\n", proto.p_num); 1.58 + 1.59 + rv = PR_GetProtoByNumber(6, buf, sizeof(buf), &proto); 1.60 + if (PR_FAILURE == rv) { 1.61 + failed = PR_TRUE; 1.62 + PL_FPrintError(prstderr, "PR_GetProtoByNumber failed"); 1.63 + } 1.64 + else if (PL_strcmp("tcp", proto.p_name)) { 1.65 + PR_fprintf( 1.66 + prstderr, "Protocol number 6 is usually tcp, but is %s" 1.67 + " on this platform\n", proto.p_name); 1.68 + } 1.69 + else PR_fprintf(prstderr, "Protocol number 6 is %s\n", proto.p_name); 1.70 + 1.71 + rv = PR_GetProtoByNumber(17, buf, sizeof(buf), &proto); 1.72 + if (PR_FAILURE == rv) { 1.73 + failed = PR_TRUE; 1.74 + PL_FPrintError(prstderr, "PR_GetProtoByNumber failed"); 1.75 + } 1.76 + else if (PL_strcmp("udp", proto.p_name)) { 1.77 + PR_fprintf( 1.78 + prstderr, "Protocol number 17 is usually udp, but is %s" 1.79 + " on this platform\n", proto.p_name); 1.80 + } 1.81 + else PR_fprintf(prstderr, "Protocol number 17 is %s\n", proto.p_name); 1.82 + 1.83 + PR_fprintf(prstderr, (failed) ? "FAILED\n" : "PASSED\n"); 1.84 + return (failed) ? 1 : 0; 1.85 +}