本文整理汇总了C++中NetworkAddress类的典型用法代码示例。如果您正苦于以下问题:C++ NetworkAddress类的具体用法?C++ NetworkAddress怎么用?C++ NetworkAddress使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NetworkAddress类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: target
bool TargetParser::targetsEncompassLAN()
{
InetAddress localIP = env->getLocalIPAddress();
for(std::list<InetAddress>::iterator it = parsedIPs.begin(); it != parsedIPs.end(); ++it)
{
InetAddress target((*it));
if(target == localIP)
return true;
}
for(std::list<NetworkAddress>::iterator it = parsedIPBlocks.begin(); it != parsedIPBlocks.end(); ++it)
{
NetworkAddress cur = (*it);
InetAddress lowerBorder = cur.getLowerBorderAddress();
InetAddress upperBorder = cur.getUpperBorderAddress();
for(InetAddress cur = lowerBorder; cur <= upperBorder; cur++)
{
if(cur == localIP)
return true;
}
}
return false;
}
示例2: NetworkUDPBroadCast
/* Broadcast to all ips */
static void NetworkUDPBroadCast(NetworkUDPSocketHandler *socket)
{
for (NetworkAddress *addr = _broadcast_list.Begin(); addr != _broadcast_list.End(); addr++) {
Packet p(PACKET_UDP_CLIENT_FIND_SERVER);
DEBUG(net, 4, "[udp] broadcasting to %s", addr->GetHostname());
socket->SendPacket(&p, addr, true, true);
}
}
示例3: Listen
/**
* Start listening on the given host and port.
* @return true if at least one port is listening
*/
bool NetworkUDPSocketHandler::Listen()
{
/* Make sure socket is closed */
this->Close();
for (NetworkAddress *addr = this->bind.Begin(); addr != this->bind.End(); addr++) {
addr->Listen(SOCK_DGRAM, &this->sockets);
}
return this->sockets.Length() != 0;
}
示例4: NetworkFindBroadcastIPs
/**
* Find the IPv4 broadcast addresses; IPv6 uses a completely different
* strategy for broadcasting.
* @param broadcast the list of broadcasts to write into.
*/
void NetworkFindBroadcastIPs(NetworkAddressList *broadcast)
{
NetworkFindBroadcastIPsInternal(broadcast);
/* Now display to the debug all the detected ips */
DEBUG(net, 3, "Detected broadcast addresses:");
int i = 0;
for (NetworkAddress *addr = broadcast->Begin(); addr != broadcast->End(); addr++) {
addr->SetPort(NETWORK_DEFAULT_PORT);
DEBUG(net, 3, "%d) %s", i++, addr->GetHostname());
}
}
示例5:
NetworkAddress * Block::findAddress (int centraldNum, const char *blockName)
{
std::list < NetworkAddress * >::iterator addr_iter;
for (addr_iter = blockAddress.begin (); addr_iter != blockAddress.end (); addr_iter++)
{
NetworkAddress *addr = (*addr_iter);
if (addr->isAddress (centraldNum, blockName))
{
return addr;
}
}
return NULL;
}
示例6: deleteAddress
void Block::deleteAddress (int p_centrald_num, const char *p_name)
{
std::list < NetworkAddress * >::iterator addr_iter;
for (addr_iter = blockAddress.begin (); addr_iter != blockAddress.end (); addr_iter++)
{
NetworkAddress *addr = (*addr_iter);
if (addr->isAddress (p_centrald_num, p_name))
{
blockAddress.erase (addr_iter);
delete addr;
return;
}
}
}
示例7: resolve_host
DTerr DeviceNetworkSockets::resolve_host (NetworkAddress &ip, const std::string &host, DTushort port)
{
std::string real_host = Globals::substitute_global(host);
struct addrinfo hints, *res;
// get address info
::bzero(&hints, sizeof(hints));
#if defined(DT3_USE_IPV6) && DT3_USE_IPV6
hints.ai_family = AF_UNSPEC;
#else
hints.ai_family = AF_INET;
#endif
hints.ai_socktype = SOCK_STREAM;
DTint err = ::getaddrinfo( (host.size() == 0) ? NULL : real_host.c_str(), MoreStrings::cast_to_string(port).c_str(), &hints, &res);
if (err != 0) {
return DT3_ERR_NET_UNKNOWN;
}
// save the results for freeing later
if (res != NULL) {
ip.set_network_address(address_to_string(res->ai_addr));
::freeaddrinfo(res);
return DT3_ERR_NONE;
} else {
::freeaddrinfo(res);
return DT3_ERR_NET_UNKNOWN;
}
}
示例8: NetworkUDPQueryServer
/**
* Query a specific server.
* @param address The address of the server.
* @param manually Whether the address was entered manually.
*/
void NetworkUDPQueryServer(NetworkAddress address, bool manually)
{
NetworkUDPQueryServerInfo *info = new NetworkUDPQueryServerInfo(address, manually);
if (address.IsResolved() || !ThreadObject::New(NetworkUDPQueryServerThread, info)) {
NetworkUDPQueryServerThread(info);
}
}
示例9: lock
void
TCPSocket::connect(const NetworkAddress& addr)
{
{
Lock lock(&m_mutex);
// fail on attempts to reconnect
if (m_socket == nullptr || m_connected) {
sendConnectionFailedEvent("busy");
return;
}
try {
if (ARCH->connectSocket(m_socket, addr.getAddress())) {
sendEvent(m_events->forIDataSocket().connected());
onConnected();
}
else {
// connection is in progress
m_writable = true;
}
}
catch (XArchNetwork& e) {
throw XSocketConnect(e.what());
}
}
setJob(newJob());
}
示例10: tcp_accept
DTerr DeviceNetworkSockets::tcp_accept (NetworkSocket &connection_socket, NetworkAddress &ip, const NetworkSocket &listen_socket)
{
if (listen_socket.is_empty())
return DT3_ERR_NONE;
DTint listen_socket_raw = *reinterpret_cast<DTint*>(listen_socket.network_socket_data());
struct sockaddr_storage sast;
struct sockaddr *sa = (struct sockaddr *) &sast;
socklen_t sas = sizeof(sast);
DTint connection_socket_raw = ::accept(listen_socket_raw, (sockaddr *) sa, &sas);
if (connection_socket_raw < 0) {
if (errno == EWOULDBLOCK) {
return DT3_ERR_NET_WOULD_BLOCK;
}
LOG_MESSAGE << "TCPAccept: accept: " << strerror(errno) << " (" << (DTuint) errno << ")";
return DT3_ERR_NET_UNKNOWN;
}
// set up non-blocking reads and writes
DTint val = ::fcntl(connection_socket_raw, F_GETFL, 0);
::fcntl(connection_socket_raw, F_SETFL, val | O_NONBLOCK);
connection_socket.set_network_socket_data((DTubyte*) &connection_socket_raw, sizeof(connection_socket_raw));
ip.set_network_address(address_to_string( (const struct sockaddr *) sa));
return DT3_ERR_NONE;
}
示例11: bindSocket
bool NetworkSocket::bindSocket(const NetworkAddress &Address)
{
s32 Result = bind(
Socket_,
(sockaddr*)&(Address.getSocketAddress()),
sizeof(sockaddr_in)
);
/* Check for error */
if (Result != NO_ERROR)
{
io::Log::error("Could not bind server to port " + io::stringc(Address.getPort()));
return false;
}
return true;
}
示例12: start
void Node::start(const NetworkAddress &localAddress)
{
if(nullptr!=mComms) {
qDebug()<<"comms.start "<<localAddress.toString();
mComms->start(localAddress);
} else {
qWarning()<<"ERROR: No comms";
}
}
示例13: catch
void
TCPSocket::bind(const NetworkAddress& addr)
{
try {
ARCH->bindSocket(m_socket, addr.getAddress());
}
catch (XArchNetworkAddressInUse& e) {
throw XSocketAddressInUse(e.what());
}
catch (XArchNetwork& e) {
throw XSocketBind(e.what());
}
}
示例14: Bind
bool TCPConnection::Bind(const NetworkAddress &local)
{
if(!handle) { return false; }
long v = 1;
if(setsockopt(handle, SOL_SOCKET, SO_REUSEADDR, (char*)&v, sizeof(long))) {
return false;
}
if(bind(handle, (struct sockaddr*)&local.addr, local.Length())) {
return false;
}
laddr = local;
bound = true;
return true;
}
示例15: Connect
bool TCPConnection::Connect(const NetworkAddress &remote)
{
if(!handle) { return false; }
long v = 1;
if(setsockopt(handle, SOL_SOCKET, SO_REUSEADDR, (char*)&v, sizeof(long))) {
return false;
}
if(connect(handle, (struct sockaddr*)&remote.addr, remote.Length())) {
return false;
}
raddr = remote;
state = SCS_CONNECTED;
bound = true;
return true;
}