Home | History | Annotate | Download | only in utility
      1 // Copyright 2014 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.
      4 
      5 #include "media/cast/test/utility/net_utility.h"
      6 
      7 #include "base/basictypes.h"
      8 #include "net/base/net_errors.h"
      9 #include "net/udp/udp_socket.h"
     10 
     11 namespace media {
     12 namespace cast {
     13 namespace test {
     14 
     15 // TODO(hubbe): Move to /net/.
     16 net::IPEndPoint GetFreeLocalPort() {
     17   net::IPAddressNumber localhost;
     18   localhost.push_back(127);
     19   localhost.push_back(0);
     20   localhost.push_back(0);
     21   localhost.push_back(1);
     22   scoped_ptr<net::UDPSocket> receive_socket(
     23       new net::UDPSocket(net::DatagramSocket::DEFAULT_BIND,
     24                          net::RandIntCallback(),
     25                          NULL,
     26                          net::NetLog::Source()));
     27   receive_socket->AllowAddressReuse();
     28   CHECK_EQ(net::OK, receive_socket->Bind(net::IPEndPoint(localhost, 0)));
     29   net::IPEndPoint endpoint;
     30   CHECK_EQ(net::OK, receive_socket->GetLocalAddress(&endpoint));
     31   return endpoint;
     32 }
     33 
     34 }  // namespace test
     35 }  // namespace cast
     36 }  // namespace media
     37