⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 host.cc

📁 本人收集整理的一份c/c++跨平台网络库
💻 CC
字号:
#include <string>#include <iostream>#include <cassert>#include <errno.h>#ifdef POSIXextern "C" {#include <sys/utsname.h>}#endif // POSIX#include "host.h"#include "logging.h"#include "network.h"#include "socket.h"#if defined(_MSC_VER) && _MSC_VER < 1300namespace std {  using ::strerror;  using ::exit;}#endifnamespace utils_base {namespace {void FatalError(const std::string& name, int err) {  PLOG(LERROR, err) << name;  std::exit(1);}}#ifdef POSIXstd::string GetHostName() {  struct utsname nm;  if (uname(&nm) < 0)    FatalError("uname", errno);  return std::string(nm.nodename);}#endif#ifdef WIN32std::string GetHostName() {  // TODO: fix this  return "cricket";}#endif// Records information about the local host.Host* gLocalHost = 0;const Host& LocalHost() {  if (!gLocalHost) {    std::vector<Network*>* networks = new std::vector<Network*>;    NetworkManager::CreateNetworks(*networks);#ifdef WIN32    // This is sort of problematic... one part of the code (the unittests) wants    // 127.0.0.1 to be present and another part (port allocators) don't.  Right    // now, they use different APIs, so we can have different behavior.  But    // there is something wrong with this.    networks->push_back(new Network("localhost",                                    SocketAddress::StringToIP("127.0.0.1")));#endif    gLocalHost = new Host(GetHostName(), networks);    assert(gLocalHost->networks().size() > 0);  }  return *gLocalHost;}} // namespace utils_base

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -