michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: ************************************************************************* michael@0: * michael@0: * File: getproto.c michael@0: * michael@0: * A test program for PR_GetProtoByName and PR_GetProtoByNumber michael@0: * michael@0: ************************************************************************* michael@0: */ michael@0: michael@0: #include "plstr.h" michael@0: #include "plerror.h" michael@0: #include "prinit.h" michael@0: #include "prprf.h" michael@0: #include "prnetdb.h" michael@0: #include "prerror.h" michael@0: michael@0: int main(int argc, char **argv) michael@0: { michael@0: PRFileDesc *prstderr = PR_GetSpecialFD(PR_StandardError); michael@0: PRBool failed = PR_FALSE; michael@0: PRProtoEnt proto; michael@0: char buf[2048]; michael@0: PRStatus rv; michael@0: michael@0: PR_STDIO_INIT(); michael@0: rv = PR_GetProtoByName("tcp", buf, sizeof(buf), &proto); michael@0: if (PR_FAILURE == rv) { michael@0: failed = PR_TRUE; michael@0: PL_FPrintError(prstderr, "PR_GetProtoByName failed"); michael@0: } michael@0: else if (6 != proto.p_num) { michael@0: PR_fprintf( michael@0: prstderr,"tcp is usually 6, but is %d on this machine\n", michael@0: proto.p_num); michael@0: } michael@0: else PR_fprintf(prstderr, "tcp is protocol number %d\n", proto.p_num); michael@0: michael@0: rv = PR_GetProtoByName("udp", buf, sizeof(buf), &proto); michael@0: if (PR_FAILURE == rv) { michael@0: failed = PR_TRUE; michael@0: PL_FPrintError(prstderr, "PR_GetProtoByName failed"); michael@0: } michael@0: else if (17 != proto.p_num) { michael@0: PR_fprintf( michael@0: prstderr, "udp is usually 17, but is %d on this machine\n", michael@0: proto.p_num); michael@0: } michael@0: else PR_fprintf(prstderr, "udp is protocol number %d\n", proto.p_num); michael@0: michael@0: rv = PR_GetProtoByNumber(6, buf, sizeof(buf), &proto); michael@0: if (PR_FAILURE == rv) { michael@0: failed = PR_TRUE; michael@0: PL_FPrintError(prstderr, "PR_GetProtoByNumber failed"); michael@0: } michael@0: else if (PL_strcmp("tcp", proto.p_name)) { michael@0: PR_fprintf( michael@0: prstderr, "Protocol number 6 is usually tcp, but is %s" michael@0: " on this platform\n", proto.p_name); michael@0: } michael@0: else PR_fprintf(prstderr, "Protocol number 6 is %s\n", proto.p_name); michael@0: michael@0: rv = PR_GetProtoByNumber(17, buf, sizeof(buf), &proto); michael@0: if (PR_FAILURE == rv) { michael@0: failed = PR_TRUE; michael@0: PL_FPrintError(prstderr, "PR_GetProtoByNumber failed"); michael@0: } michael@0: else if (PL_strcmp("udp", proto.p_name)) { michael@0: PR_fprintf( michael@0: prstderr, "Protocol number 17 is usually udp, but is %s" michael@0: " on this platform\n", proto.p_name); michael@0: } michael@0: else PR_fprintf(prstderr, "Protocol number 17 is %s\n", proto.p_name); michael@0: michael@0: PR_fprintf(prstderr, (failed) ? "FAILED\n" : "PASSED\n"); michael@0: return (failed) ? 1 : 0; michael@0: }