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/. */
7 *************************************************************************
11 * A test program for PR_GetProtoByName and PR_GetProtoByNumber
13 *************************************************************************
23 int main(int argc
, char **argv
)
25 PRFileDesc
*prstderr
= PR_GetSpecialFD(PR_StandardError
);
26 PRBool failed
= PR_FALSE
;
32 rv
= PR_GetProtoByName("tcp", buf
, sizeof(buf
), &proto
);
33 if (PR_FAILURE
== rv
) {
35 PL_FPrintError(prstderr
, "PR_GetProtoByName failed");
37 else if (6 != proto
.p_num
) {
39 prstderr
,"tcp is usually 6, but is %d on this machine\n",
42 else PR_fprintf(prstderr
, "tcp is protocol number %d\n", proto
.p_num
);
44 rv
= PR_GetProtoByName("udp", buf
, sizeof(buf
), &proto
);
45 if (PR_FAILURE
== rv
) {
47 PL_FPrintError(prstderr
, "PR_GetProtoByName failed");
49 else if (17 != proto
.p_num
) {
51 prstderr
, "udp is usually 17, but is %d on this machine\n",
54 else PR_fprintf(prstderr
, "udp is protocol number %d\n", proto
.p_num
);
56 rv
= PR_GetProtoByNumber(6, buf
, sizeof(buf
), &proto
);
57 if (PR_FAILURE
== rv
) {
59 PL_FPrintError(prstderr
, "PR_GetProtoByNumber failed");
61 else if (PL_strcmp("tcp", proto
.p_name
)) {
63 prstderr
, "Protocol number 6 is usually tcp, but is %s"
64 " on this platform\n", proto
.p_name
);
66 else PR_fprintf(prstderr
, "Protocol number 6 is %s\n", proto
.p_name
);
68 rv
= PR_GetProtoByNumber(17, buf
, sizeof(buf
), &proto
);
69 if (PR_FAILURE
== rv
) {
71 PL_FPrintError(prstderr
, "PR_GetProtoByNumber failed");
73 else if (PL_strcmp("udp", proto
.p_name
)) {
75 prstderr
, "Protocol number 17 is usually udp, but is %s"
76 " on this platform\n", proto
.p_name
);
78 else PR_fprintf(prstderr
, "Protocol number 17 is %s\n", proto
.p_name
);
80 PR_fprintf(prstderr
, (failed
) ? "FAILED\n" : "PASSED\n");
81 return (failed
) ? 1 : 0;