本文整理汇总了C++中IpAddress类的典型用法代码示例。如果您正苦于以下问题:C++ IpAddress类的具体用法?C++ IpAddress怎么用?C++ IpAddress使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IpAddress类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: isIpAllowed
bool I_IpServerTransport::isIpAllowed(const IpAddress &ip) const
{
ReadLock readLock(mReadWriteMutex);
if (!mAllowedIps.empty())
{
for (std::size_t i=0; i<mAllowedIps.size(); ++i)
{
if (ip.matches(mAllowedIps[i].first, mAllowedIps[i].second))
{
return true;
}
}
return false;
}
if (!mDisallowedIps.empty())
{
for (std::size_t i=0; i<mDisallowedIps.size(); ++i)
{
if (ip.matches(mDisallowedIps[i].first, mDisallowedIps[i].second))
{
return false;
}
}
return true;
}
return true;
}
示例2: connect
YETI_Result HttpTcpConnector::connect(const HttpUrl & url,
HttpClient & client,
const HttpProxyAddress * proxy,
bool reuse, HttpClient::Connection *& connection)
{
connection = NULL;
const char * server_hostname;
YETI_UInt16 server_port;
if (proxy) {
server_hostname = (const char *)proxy->get_hostname();
server_port = proxy->get_port();
} else {
server_hostname = (const char *)url.get_host();
server_port = url.get_port();
}
IpAddress address;
YETI_CHECK_FINE(address.resolve_name(server_hostname, client.get_config().m_name_resolver_timeout_));
YETI_LOG_FINE_2("TCP connector will connect to %s : %d", server_hostname, server_port);
TcpClientSocket * tcp_socket = new TcpClientSocket();
SocketReference socket(tcp_socket, true);
tcp_socket->set_read_timeout(client.get_config().m_io_timeout_);
tcp_socket->set_write_timeout(client.get_config().m_io_timeout_);
SocketAddress socket_address(address, server_port);
YETI_CHECK_FINE(tcp_socket->connect(socket_address, client.get_config().m_connection_timeout_));
HttpSimpleConnection * _connection = new HttpSimpleConnection();
_connection->m_socket_ = socket;
connection = _connection;
tcp_socket->get_input_stream(_connection->m_inputstream_);
tcp_socket->get_output_stream(_connection->m_outputstream_);
return YETI_SUCCESS;
}
示例3: decodeMasterPacket
void ClusterMembership::decodeMasterPacket(const char *buf, int len,
const IpAddress & src)
{
// NOTE: Should we check the src address as being
// the master we know and love?
if (len < 21) {
// packet is too small to be a valid master packet.
return;
}
int numnodes = (int) (buf[20]);
// A master announcement is only helpful if there is at least
// one node in it, and fewer than the max
if ((numnodes < 1) || (numnodes > MaxNodes)) {
return;
}
// We need 12 bytes per node
if (len < (21 + (12 * numnodes))) {
// too small for the number of nodes.
return;
}
int newLower = 0;
int newUpper = 0;
const char *nodebuf = (buf + 21);
for (int i=0; i< numnodes; i++) {
int offset = (i * 12);
IpAddress ip;
ip.copyFromInAddr((struct in_addr *) (nodebuf+offset));
if (ip == localaddr) {
newLower = ntohl(*(int *)(nodebuf + offset + 4));
newUpper = ntohl(*(int *)(nodebuf + offset + 8));
}
}
setNewLocalBoundaries(newLower, newUpper);
}
示例4: Expect
void TcpClient::connect(const IpAddress& address, NetPort port, const Duration& timeout, const Duration& pause)
{
Expect(address.isValid(), Throw(InvalidParameter, "Invalid IpAddress"));
Expect(port != NetPort_Any, Throw(InvalidParameter, "Invalid NetPort"));
int ret;
Clock clock;
Socket::create(address.getProtocol());
prv::SockAddrBuffer buffer(address, port);
clock.start();
do
{
ret = ::connect(getHandler(), buffer.getSockAddr(), buffer.getLength());
if(ret != 0)
{
std::this_thread::sleep_for(std::chrono::milliseconds(static_cast<long long>(pause.asMilliseconds())));
}
}while(ret != 0 && clock.getElapsedTime() < timeout);
Expect(ret == 0, Throw(InternalError, "Failed to connect to the remote host"));
}
示例5: main
int main(int argc, char* argv[])
{
InitModuleObjects();
EnableSEHtoExceptionMapping();
if (argc<6)
{
usage();
return 0;
}
try
{
const char *filename = argv[1];
Owned<IDaliCapabilityCreator> cc = createDaliCapabilityCreator();
cc->setSystemID(argv[2]);
cc->setServerPassword(argv[3]);
for (unsigned i=4;i<argc;i++) {
const char *cmd = argv[i++];
if (i==argc)
break;
const char *param = argv[i];
if (stricmp(cmd,"THORWIDTH")==0) {
cc->setLimit(DCR_ThorSlave,atoi(param));
}
else if (stricmp(cmd,"DALINODE")==0) {
StringBuffer mac;
if (strchr(param,'.')) { // must be ip
IpAddress ip;
ip.set(param);
if (!getMAC(ip,mac)) {
printf("ERROR: could mot get MAC address for %s\n",param);
return 1;
}
}
else
mac.append(param);
cc->addCapability(DCR_DaliServer,mac.str());
}
else {
printf("ERROR: unknown command %s\n",cmd);
return 1;
}
}
StringBuffer results;
cc->save(results);
Owned<IFile> ifile = createIFile(filename);
Owned<IFileIO> ifileio = ifile->open(IFOcreate);
ifileio->write(0,results.length(),results.str());
printf("Dali Capabilities sucessfully exported to %s\n", filename);
}
catch (IException *e)
{
EXCLOG(e);
e->Release();
}
releaseAtoms();
return 0;
}
示例6: sendMsgBlock
bool Proxy::sendMsgBlock(MsgBlockType type, const IpAddress &remote_ip,
const void *data, unsigned len)
{
//cout << "> type=" << type << " remote_ip=" << remote_ip
// << " len=" << len << endl;
if (!con.isConnected() || (state != STATE_CONNECTED))
{
return false;
}
int msg_len = MSG_HEADER_SIZE + len;
uint8_t msg_buf[msg_len];
uint8_t *msg_ptr = msg_buf;
// Store the message type
*msg_ptr++ = static_cast<uint8_t>(type);
// Store the proxied remote IP address if set
in_addr_t remote_ip_addr = 0;
if (!remote_ip.isEmpty())
{
remote_ip_addr = remote_ip.ip4Addr().s_addr;
}
*msg_ptr++ = remote_ip_addr & 0xff;
*msg_ptr++ = (remote_ip_addr >> 8) & 0xff;
*msg_ptr++ = (remote_ip_addr >> 16) & 0xff;
*msg_ptr++ = (remote_ip_addr >> 24) & 0xff;
// Store the message data length
*msg_ptr++ = len & 0xff;
*msg_ptr++ = (len >> 8) & 0xff;
*msg_ptr++ = (len >> 16) & 0xff;
*msg_ptr++ = (len >> 24) & 0xff;
// Store the message data
memcpy(msg_ptr, data, len);
// Send the message
int ret = con.write(msg_buf, msg_len);
if (ret == -1)
{
char errstr[256];
errstr[0] = 0;
strerror_r(errno, errstr, sizeof(errstr));
cerr << "*** ERROR: Error while writing message to EchoLink proxy: "
<< errstr << endl;
reset();
}
else if (ret != msg_len)
{
cerr << "*** ERROR: Could not write all data to EchoLink proxy\n";
reset();
}
return true;
} /* Proxy::sendMsgBlock */
示例7: writeIp
bool Configurator::writeIp (std::ostream &stream, const IpAddress &address)
{
if (!writeInt(stream, address.family()))
return false;
if (!stream.write(reinterpret_cast<const char *>(address.data()), address.size()) || !stream.good())
return false;
return true;
}
示例8: Listen
SocketState TcpServer::Listen(const IpAddress& address, unsigned int queueSize)
{
NazaraAssert(address.IsValid(), "Invalid address");
Open(address.GetProtocol());
SocketState state = SocketImpl::Listen(m_handle, address, queueSize, &m_lastError);
if (state == SocketState_Bound)
m_boundAddress = SocketImpl::QuerySocketAddress(m_handle);
UpdateState(state);
return state;
}
示例9: ForEach
//For every ECLWatchVisible dropzones, read: dropZoneName, directory, and, if available, computer.
//For every Servers/Server in ECLWatchVisible dropzones, read: directory,
// server name, and hostname(or IP). Create dropzone("@name", "@directory", "@computer",
// "@netAddress", "@linux", "@sourceNode") tree into pSoftware.
void CFileSpraySoapBindingEx::appendDropZones(double clientVersion, IConstEnvironment* env, const char* dfuwuidSourcePartIP, IPropertyTree* softwareTree)
{
Owned<IConstDropZoneInfoIterator> dropZoneItr = env->getDropZoneIterator();
ForEach(*dropZoneItr)
{
IConstDropZoneInfo& dropZoneInfo = dropZoneItr->query();
if (!dropZoneInfo.isECLWatchVisible()) //This code is used by ECLWatch. So, skip the DZs not for ECLWatch.
continue;
SCMStringBuffer dropZoneName, directory, computerName;
dropZoneInfo.getName(dropZoneName);
dropZoneInfo.getDirectory(directory);
if (!dropZoneName.length() || !directory.length())
continue;
bool isLinux = getPathSepChar(directory.str()) == '/' ? true : false;
Owned<IConstDropZoneServerInfoIterator> dropZoneServerItr = dropZoneInfo.getServers();
ForEach(*dropZoneServerItr)
{
IConstDropZoneServerInfo& dropZoneServer = dropZoneServerItr->query();
StringBuffer name, server, networkAddress;
dropZoneServer.getName(name);
dropZoneServer.getServer(server);
if (name.isEmpty() || server.isEmpty())
continue;
IPropertyTree* dropZone = softwareTree->addPropTree("DropZone", createPTree());
dropZone->setProp("@name", dropZoneName.str());
dropZone->setProp("@computer", name.str());
dropZone->setProp("@directory", directory.str());
if (isLinux)
dropZone->setProp("@linux", "true");
IpAddress ipAddr;
ipAddr.ipset(server.str());
ipAddr.getIpText(networkAddress);
if (!ipAddr.isNull())
{
dropZone->addProp("@netAddress", networkAddress);
if (!isEmptyString(dfuwuidSourcePartIP))
{
IpAddress ip(dfuwuidSourcePartIP);
if (ip.ipequals(ipAddr))
dropZone->addProp("@sourceNode", "1");
}
}
}
}
}
示例10: Send
bool UdpSocket::Send(const IpAddress& to, const void* buffer, std::size_t size, std::size_t* sent)
{
NazaraAssert(to.IsValid(), "Invalid ip address");
NazaraAssert(to.GetProtocol() == m_protocol, "IP Address has a different protocol than the socket");
NazaraAssert(buffer && size > 0, "Invalid buffer");
int byteSent;
if (!SocketImpl::SendTo(m_handle, buffer, static_cast<int>(size), to, &byteSent, &m_lastError))
return false;
if (sent)
*sent = byteSent;
return true;
}
示例11: SendMultiple
/*!
* \brief Sends multiple buffers as one datagram
* \return true If data were sent
*
* \param to Destination IpAddress (must match socket protocol)
* \param buffers A pointer to an array of NetBuffer containing buffers and size data
* \param size Number of NetBuffer to send
* \param sent Optional argument to get the number of bytes sent
*/
bool UdpSocket::SendMultiple(const IpAddress& to, const NetBuffer* buffers, std::size_t bufferCount, std::size_t* sent)
{
NazaraAssert(to.IsValid(), "Invalid ip address");
NazaraAssert(to.GetProtocol() == m_protocol, "IP Address has a different protocol than the socket");
NazaraAssert(buffers && bufferCount > 0, "Invalid buffer");
int byteSent;
if (!SocketImpl::SendMultiple(m_handle, buffers, bufferCount, to, &byteSent, &m_lastError))
return false;
if (sent)
*sent = byteSent;
return true;
}
示例12:
void
Acceptor::helpStop()
{
Socket client;
if ( client.CreateTcpSocket() )
{
IpAddress addr;
addr.Init( _T("127.0.0.1"), m_socket->GetAddress().GetPort() );
(void)client.Connect( m_socket->GetAddress() );
(void)client.Connect( addr );
}
}
示例13: NazaraAssert
SocketState SocketImpl::Listen(SocketHandle handle, const IpAddress& address, unsigned queueSize, SocketError* error)
{
NazaraAssert(handle != InvalidHandle, "Invalid handle");
NazaraAssert(address.IsValid(), "Invalid address");
IpAddressImpl::SockAddrBuffer nameBuffer;
int bufferLength = IpAddressImpl::ToSockAddr(address, nameBuffer.data());
if (bind(handle, reinterpret_cast<const sockaddr*>(&nameBuffer), bufferLength) == SOCKET_ERROR)
{
if (error)
*error = TranslateWSAErrorToSocketError(WSAGetLastError());
return SocketState_NotConnected;
}
if (listen(handle, queueSize) == SOCKET_ERROR)
{
if (error)
*error = TranslateWSAErrorToSocketError(WSAGetLastError());
return SocketState_NotConnected;
}
if (error)
*error = SocketError_NoError;
return SocketState_Bound;
}
示例14: connect
void TcpClientBase::connect(const IpAddress& remote_ip, uint16_t remote_port)
{
con->setRemoteAddr(remote_ip);
remote_host = remote_ip.toString();
con->setRemotePort(remote_port);
connect();
} /* TcpClientBase::connect */
示例15: send
Socket::Status UdpSocket::send(const void* data, std::size_t size, const IpAddress& remoteAddress, unsigned short remotePort)
{
// Create the internal socket if it doesn't exist
create();
// Make sure that all the data will fit in one datagram
if (size > MaxDatagramSize)
{
err() << "Cannot send data over the network "
<< "(the number of bytes to send is greater than cpp3ds::UdpSocket::MaxDatagramSize)" << std::endl;
return Error;
}
// Build the target address
sockaddr_in address = priv::SocketImpl::createAddress(remoteAddress.toInteger(), remotePort);
// Send the data (unlike TCP, all the data is always sent in one call)
int sent = sendto(getHandle(), static_cast<const char*>(data), static_cast<int>(size), 0, reinterpret_cast<sockaddr*>(&address), sizeof(address));
// Check for errors
if (sent < 0)
return priv::SocketImpl::getErrorStatus();
return Done;
}