Debian Codegraph @

nsprpub/pr/tests/getproto.c

raw
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 PR_STDIO_INIT();
31 rv = PR_GetProtoByName("tcp", buf, sizeof(buf), &proto);
32 if (PR_FAILURE == rv) {
33 failed = PR_TRUE;
34 PL_FPrintError(prstderr, "PR_GetProtoByName failed");
35 } else if (6 != proto.p_num) {
36 PR_fprintf(prstderr, "tcp is usually 6, but is %d on this machine\n",
37 proto.p_num);
38 } else {
39 PR_fprintf(prstderr, "tcp is protocol number %d\n", proto.p_num);
40 }
41
42 rv = PR_GetProtoByName("udp", buf, sizeof(buf), &proto);
43 if (PR_FAILURE == rv) {
44 failed = PR_TRUE;
45 PL_FPrintError(prstderr, "PR_GetProtoByName failed");
46 } else if (17 != proto.p_num) {
47 PR_fprintf(prstderr, "udp is usually 17, but is %d on this machine\n",
48 proto.p_num);
49 } else {
50 PR_fprintf(prstderr, "udp is protocol number %d\n", proto.p_num);
51 }
52
53 rv = PR_GetProtoByNumber(6, buf, sizeof(buf), &proto);
54 if (PR_FAILURE == rv) {
55 failed = PR_TRUE;
56 PL_FPrintError(prstderr, "PR_GetProtoByNumber failed");
57 } else if (PL_strcmp("tcp", proto.p_name)) {
58 PR_fprintf(prstderr,
59 "Protocol number 6 is usually tcp, but is %s"
60 " on this platform\n",
61 proto.p_name);
62 } else {
63 PR_fprintf(prstderr, "Protocol number 6 is %s\n", proto.p_name);
64 }
65
66 rv = PR_GetProtoByNumber(17, buf, sizeof(buf), &proto);
67 if (PR_FAILURE == rv) {
68 failed = PR_TRUE;
69 PL_FPrintError(prstderr, "PR_GetProtoByNumber failed");
70 } else if (PL_strcmp("udp", proto.p_name)) {
71 PR_fprintf(prstderr,
72 "Protocol number 17 is usually udp, but is %s"
73 " on this platform\n",
74 proto.p_name);
75 } else {
76 PR_fprintf(prstderr, "Protocol number 17 is %s\n", proto.p_name);
77 }
78
79 PR_fprintf(prstderr, (failed) ? "FAILED\n" : "PASSED\n");
80 return (failed) ? 1 : 0;
81 }