当前位置: 首页>>代码示例>>C++>>正文


C++ Strings::Append方法代码示例

本文整理汇总了C++中Strings::Append方法的典型用法代码示例。如果您正苦于以下问题:C++ Strings::Append方法的具体用法?C++ Strings::Append怎么用?C++ Strings::Append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Strings的用法示例。


在下文中一共展示了Strings::Append方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: address

// List all useful IPv4/IPv6 addresses (excluding localhost).
/* static */  Strings Address::ListAll(void) {
    Strings result;

#ifdef _POSIX
    /*
    POSIX doesn't provide a way to enumerate network interfaces,
    so use Linux getifaddrs(3).
    */

    ifaddrs* p_list;
    int const error = ::getifaddrs(&p_list);
    ASSERT(error == 0);
    for (ifaddrs* p_current = p_list; p_current != NULL; p_current = p_current->ifa_next) {
        unsigned flags = p_current->ifa_flags;
        ADDRESS_FAMILY const family = p_current->ifa_addr->sa_family;
        if ((flags & IFF_UP)
            && !(flags & IFF_LOOPBACK)
            && (family == AF_INET || family == AF_INET6))
        {
            Address const address(*(p_current->ifa_addr));
            if (!address.IsLocalHost()) {
                // not localhost
                String const address_text = address;
                result.Append(address_text);
            }
        }
    }

    ::freeifaddrs(p_list);

#elif defined(_QT)

    QList<QHostAddress> const list = QNetworkInterface::allAddresses();
    QList<QHostAddress>::const_iterator i_address;
    for (i_address = list.constBegin(); i_address != list.constEnd(); i_address++) {
        QHostAddress const q_address = *i_address;
        Address const address(q_address);
        if (!address.IsLocalHost()) {
            // not localhost
            String const address_text = address;
            result.Append(address_text);
        }
    }

#elif defined(_WINSOCK2)

    ULONG const flags = (GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST);
    PIP_ADAPTER_ADDRESSES p_list = NULL;
    ULONG list_bytes = 16000;  // initial size estimate
    while (p_list == NULL) {
         p_list = PIP_ADAPTER_ADDRESSES(new char[list_bytes]);
         ASSERT(p_list != NULL);

         ULONG const error_code = Win::GetAdaptersAddresses(
             AF_UNSPEC, flags, NULL, p_list, &list_bytes);
         if (error_code != NO_ERROR) {
             if (error_code == ERROR_NO_DATA) {
                 return result;
             }
             ASSERT(error_code == ERROR_BUFFER_OVERFLOW);
             delete p_list;
             p_list = NULL;
         }
    }

    // Go through the list and append useful IP addresses to the result.
    PIP_ADAPTER_ADDRESSES p_current = p_list;

    while (p_current != NULL) {
        // Only interested in unicast addresses.
        PIP_ADAPTER_UNICAST_ADDRESS p_unicast = p_current->FirstUnicastAddress;
        while (p_unicast != NULL) {
            if ((p_unicast->Flags & IP_ADAPTER_ADDRESS_TRANSIENT) == 0x0) {
                // not transient
                Win::PSOCKADDR const p_address = p_unicast->Address.lpSockaddr;
                Address const address(*p_address);
                if (!address.IsLocalHost()) {
                    // not localhost
                    String const address_text = address;
                    result.Append(address_text);
                }
            }
            p_unicast = p_unicast->Next;
        }
        p_current = p_current->Next;
    }

    delete p_list;

#endif  // defined(_WINSOCK2)

    return result;
}
开发者ID:stephengold,项目名称:gold-tiles,代码行数:94,代码来源:address.cpp


注:本文中的Strings::Append方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。