1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef NET_BASE_NET_PORT_UTIL_
6 #define NET_BASE_NET_PORT_UTIL_
10 #include "base/basictypes.h"
11 #include "net/base/net_export.h"
15 // Checks if |port| is in the valid range (0 to 65535, though 0 is technically
16 // reserved). Should be used before casting a port to a uint16_t.
17 NET_EXPORT
bool IsPortValid(int port
);
19 // Returns true if the port is in the range [0, 1023]. These ports are
20 // registered by IANA and typically need root access to listen on.
21 bool IsWellKnownPort(int port
);
23 // Checks if the port is allowed for the specified scheme. Ports set as allowed
24 // with SetExplicitlyAllowedPorts() or by using ScopedPortException() will be
25 // considered allowed for any scheme.
26 NET_EXPORT
bool IsPortAllowedForScheme(int port
, const std::string
& url_scheme
);
28 // Returns the number of explicitly allowed ports; for testing.
29 NET_EXPORT_PRIVATE
size_t GetCountOfExplicitlyAllowedPorts();
31 NET_EXPORT
void SetExplicitlyAllowedPorts(const std::string
& allowed_ports
);
33 class NET_EXPORT ScopedPortException
{
35 explicit ScopedPortException(int port
);
36 ~ScopedPortException();
41 DISALLOW_COPY_AND_ASSIGN(ScopedPortException
);
46 #endif // NET_BASE_NET_PORT_UTIL_