1 /* 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 #include <iostream> 11 12 #include "p2p/base/stun_server.h" 13 #include "rtc_base/async_udp_socket.h" 14 #include "rtc_base/socket_address.h" 15 #include "rtc_base/socket_server.h" 16 #include "rtc_base/thread.h" 17 18 using cricket::StunServer; 19 main(int argc,char * argv[])20int main(int argc, char* argv[]) { 21 if (argc != 2) { 22 std::cerr << "usage: stunserver address" << std::endl; 23 return 1; 24 } 25 26 rtc::SocketAddress server_addr; 27 if (!server_addr.FromString(argv[1])) { 28 std::cerr << "Unable to parse IP address: " << argv[1]; 29 return 1; 30 } 31 32 rtc::Thread* pthMain = rtc::Thread::Current(); 33 34 rtc::AsyncUDPSocket* server_socket = 35 rtc::AsyncUDPSocket::Create(pthMain->socketserver(), server_addr); 36 if (!server_socket) { 37 std::cerr << "Failed to create a UDP socket" << std::endl; 38 return 1; 39 } 40 41 StunServer* server = new StunServer(server_socket); 42 43 std::cout << "Listening at " << server_addr.ToString() << std::endl; 44 45 pthMain->Run(); 46 47 delete server; 48 return 0; 49 } 50