nsprpub/pr/tests/getproto.c

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 /*
michael@0 7 *************************************************************************
michael@0 8 *
michael@0 9 * File: getproto.c
michael@0 10 *
michael@0 11 * A test program for PR_GetProtoByName and PR_GetProtoByNumber
michael@0 12 *
michael@0 13 *************************************************************************
michael@0 14 */
michael@0 15
michael@0 16 #include "plstr.h"
michael@0 17 #include "plerror.h"
michael@0 18 #include "prinit.h"
michael@0 19 #include "prprf.h"
michael@0 20 #include "prnetdb.h"
michael@0 21 #include "prerror.h"
michael@0 22
michael@0 23 int main(int argc, char **argv)
michael@0 24 {
michael@0 25 PRFileDesc *prstderr = PR_GetSpecialFD(PR_StandardError);
michael@0 26 PRBool failed = PR_FALSE;
michael@0 27 PRProtoEnt proto;
michael@0 28 char buf[2048];
michael@0 29 PRStatus rv;
michael@0 30
michael@0 31 PR_STDIO_INIT();
michael@0 32 rv = PR_GetProtoByName("tcp", buf, sizeof(buf), &proto);
michael@0 33 if (PR_FAILURE == rv) {
michael@0 34 failed = PR_TRUE;
michael@0 35 PL_FPrintError(prstderr, "PR_GetProtoByName failed");
michael@0 36 }
michael@0 37 else if (6 != proto.p_num) {
michael@0 38 PR_fprintf(
michael@0 39 prstderr,"tcp is usually 6, but is %d on this machine\n",
michael@0 40 proto.p_num);
michael@0 41 }
michael@0 42 else PR_fprintf(prstderr, "tcp is protocol number %d\n", proto.p_num);
michael@0 43
michael@0 44 rv = PR_GetProtoByName("udp", buf, sizeof(buf), &proto);
michael@0 45 if (PR_FAILURE == rv) {
michael@0 46 failed = PR_TRUE;
michael@0 47 PL_FPrintError(prstderr, "PR_GetProtoByName failed");
michael@0 48 }
michael@0 49 else if (17 != proto.p_num) {
michael@0 50 PR_fprintf(
michael@0 51 prstderr, "udp is usually 17, but is %d on this machine\n",
michael@0 52 proto.p_num);
michael@0 53 }
michael@0 54 else PR_fprintf(prstderr, "udp is protocol number %d\n", proto.p_num);
michael@0 55
michael@0 56 rv = PR_GetProtoByNumber(6, buf, sizeof(buf), &proto);
michael@0 57 if (PR_FAILURE == rv) {
michael@0 58 failed = PR_TRUE;
michael@0 59 PL_FPrintError(prstderr, "PR_GetProtoByNumber failed");
michael@0 60 }
michael@0 61 else if (PL_strcmp("tcp", proto.p_name)) {
michael@0 62 PR_fprintf(
michael@0 63 prstderr, "Protocol number 6 is usually tcp, but is %s"
michael@0 64 " on this platform\n", proto.p_name);
michael@0 65 }
michael@0 66 else PR_fprintf(prstderr, "Protocol number 6 is %s\n", proto.p_name);
michael@0 67
michael@0 68 rv = PR_GetProtoByNumber(17, buf, sizeof(buf), &proto);
michael@0 69 if (PR_FAILURE == rv) {
michael@0 70 failed = PR_TRUE;
michael@0 71 PL_FPrintError(prstderr, "PR_GetProtoByNumber failed");
michael@0 72 }
michael@0 73 else if (PL_strcmp("udp", proto.p_name)) {
michael@0 74 PR_fprintf(
michael@0 75 prstderr, "Protocol number 17 is usually udp, but is %s"
michael@0 76 " on this platform\n", proto.p_name);
michael@0 77 }
michael@0 78 else PR_fprintf(prstderr, "Protocol number 17 is %s\n", proto.p_name);
michael@0 79
michael@0 80 PR_fprintf(prstderr, (failed) ? "FAILED\n" : "PASSED\n");
michael@0 81 return (failed) ? 1 : 0;
michael@0 82 }

mercurial