Chromium Code Reviews| Index: media/cast/test/utility/net_utility.cc |
| diff --git a/media/cast/test/utility/net_utility.cc b/media/cast/test/utility/net_utility.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..57899310facbd21cfaac63cf50c0e29817416c8e |
| --- /dev/null |
| +++ b/media/cast/test/utility/net_utility.cc |
| @@ -0,0 +1,39 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "media/cast/test/utility/net_utility.h" |
| + |
| +#include "base/basictypes.h" |
| +#include "net/base/net_errors.h" |
| +#include "net/udp/udp_socket.h" |
| + |
| +namespace media { |
| +namespace cast { |
| +namespace test { |
| + |
| +// TODO(hubbe): Move to /net/. |
| +net::IPEndPoint GetFreeLocalPort() { |
| + // Determine a unused UDP port for the in-process receiver to listen on. |
|
miu
2014/05/15 02:48:48
nit: IMHO, these 3 lines of comments would be more
hubbe
2014/05/16 01:04:45
Done.
|
| + // Method: Bind a UDP socket on port 0, and then check which port the |
| + // operating system assigned to it. |
| + net::IPAddressNumber localhost; |
| + localhost.push_back(127); |
| + localhost.push_back(0); |
| + localhost.push_back(0); |
| + localhost.push_back(1); |
| + scoped_ptr<net::UDPSocket> receive_socket( |
| + new net::UDPSocket(net::DatagramSocket::DEFAULT_BIND, |
| + net::RandIntCallback(), |
| + NULL, |
| + net::NetLog::Source())); |
| + receive_socket->AllowAddressReuse(); |
| + CHECK_EQ(net::OK, receive_socket->Bind(net::IPEndPoint(localhost, 0))); |
| + net::IPEndPoint endpoint; |
| + CHECK_EQ(net::OK, receive_socket->GetLocalAddress(&endpoint)); |
| + return endpoint; |
| +} |
| + |
| +} // namespace test |
| +} // namespace cast |
| +} // namespace media |