You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.3 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. #include "p2p/base/stun_server.h"
  12. #include "rtc_base/async_udp_socket.h"
  13. #include "rtc_base/socket_address.h"
  14. #include "rtc_base/socket_server.h"
  15. #include "rtc_base/thread.h"
  16. using cricket::StunServer;
  17. int main(int argc, char* argv[]) {
  18. if (argc != 2) {
  19. std::cerr << "usage: stunserver address" << std::endl;
  20. return 1;
  21. }
  22. rtc::SocketAddress server_addr;
  23. if (!server_addr.FromString(argv[1])) {
  24. std::cerr << "Unable to parse IP address: " << argv[1];
  25. return 1;
  26. }
  27. rtc::Thread* pthMain = rtc::Thread::Current();
  28. rtc::AsyncUDPSocket* server_socket =
  29. rtc::AsyncUDPSocket::Create(pthMain->socketserver(), server_addr);
  30. if (!server_socket) {
  31. std::cerr << "Failed to create a UDP socket" << std::endl;
  32. return 1;
  33. }
  34. StunServer* server = new StunServer(server_socket);
  35. std::cout << "Listening at " << server_addr.ToString() << std::endl;
  36. pthMain->Run();
  37. delete server;
  38. return 0;
  39. }