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