summaryrefslogtreecommitdiffstats
path: root/media/cast/test/utility/net_utility.cc
blob: c146d9ab59a99dbb0d32f6b50827ec16e16f627d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// 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_server_socket.h"

namespace media {
namespace cast {
namespace test {

// TODO(hubbe): Move to /net/.
net::IPEndPoint GetFreeLocalPort() {
  net::IPAddressNumber localhost;
  localhost.push_back(127);
  localhost.push_back(0);
  localhost.push_back(0);
  localhost.push_back(1);
  scoped_ptr<net::UDPServerSocket> receive_socket(
      new net::UDPServerSocket(NULL, net::NetLog::Source()));
  receive_socket->AllowAddressReuse();
  CHECK_EQ(net::OK, receive_socket->Listen(net::IPEndPoint(localhost, 0)));
  net::IPEndPoint endpoint;
  CHECK_EQ(net::OK, receive_socket->GetLocalAddress(&endpoint));
  return endpoint;
}

}  // namespace test
}  // namespace cast
}  // namespace media