本文整理汇总了C++中IPAddress函数的典型用法代码示例。如果您正苦于以下问题:C++ IPAddress函数的具体用法?C++ IPAddress怎么用?C++ IPAddress使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IPAddress函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _address
Arc::Socket::Socket( unsigned int socket )
#endif // WINDOWS
: _address(),
_port(),
_type(INVALID_SOCKET_TYPE),
_socket(socket),
_error(false),
_errorMsg()
{
char buf[INET_ADDRSTRLEN] = "";
struct sockaddr_in name;
socklen_t len = sizeof(name);
int res;
res = getpeername(socket, (struct sockaddr *)&name, &len);
if (res == 0)
{
inet_ntop(AF_INET, &name.sin_addr, buf, sizeof buf);
}
else
{
setError("getpeername() failed");
cleanup();
}
_address = IPAddress(inet_ntoa(name.sin_addr));
_port = name.sin_port;
_type = SOCKET_TYPE_TCP; // TODO: Get actual socket type when UDP is implemented
}
示例2: millis
// if this is the first time calling now() or after 6 hours an NTP update is perfomed
// warn: now() should be called within 50 days from the last call
// warn: loses about 3 seconds every 10 hours
DateTime MTD_FLASHMEM DateTime::now()
{
uint32_t currentMillis = millis();
uint32_t locLastMillis = lastMillis();
uint32_t diff = (currentMillis < locLastMillis) ? (0xFFFFFFFF - locLastMillis + currentMillis) : (currentMillis - locLastMillis);
if (locLastMillis == 0 || diff > 6 * 3600 * 1000)
{
if (lastDateTime().getFromNTPServer())
{
lastMillis() = currentMillis;
return lastDateTime();
}
}
DateTime result;
result.setUnixDateTime( lastDateTime().getUnixDateTime() + (diff / 1000) );
if (s_defaultNTPServer == IPAddress(0, 0, 0, 0))
{
// NTP synchronizatin is disabled. Take care for millis overflow.
if (diff > 10 * 24 * 3600 * 1000) // past 10 days?
{
// reset millis counter to avoid overflow (actually it overflows after 50 days)
lastMillis() = currentMillis;
lastDateTime() = result;
}
}
return result;
}
示例3: DEBUG_WIFI_GENERIC
int ESP8266WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResult, uint32_t timeout_ms)
{
ip_addr_t addr;
aResult = static_cast<uint32_t>(0);
if(aResult.fromString(aHostname)) {
// Host name is a IP address use it!
DEBUG_WIFI_GENERIC("[hostByName] Host: %s is a IP!\n", aHostname);
return 1;
}
DEBUG_WIFI_GENERIC("[hostByName] request IP for: %s\n", aHostname);
err_t err = dns_gethostbyname(aHostname, &addr, &wifi_dns_found_callback, &aResult);
if(err == ERR_OK) {
aResult = IPAddress(&addr);
} else if(err == ERR_INPROGRESS) {
_dns_lookup_pending = true;
delay(timeout_ms);
_dns_lookup_pending = false;
// will return here when dns_found_callback fires
if(aResult.isSet()) {
err = ERR_OK;
}
}
if(err != 0) {
DEBUG_WIFI_GENERIC("[hostByName] Host: %s lookup error: %d!\n", aHostname, (int)err);
} else {
DEBUG_WIFI_GENERIC("[hostByName] Host: %s IP: %s\n", aHostname, aResult.toString().c_str());
}
return (err == ERR_OK) ? 1 : 0;
}
示例4: begin
int EthernetClass::begin(uint8_t *mac_address)
{
static DhcpClass s_dhcp;
_dhcp = &s_dhcp;
// Initialise the basic info
W5100.init();
W5100.setMACAddress(mac_address);
W5100.setIPAddress(IPAddress(0,0,0,0).raw_address());
// Now try to get our config info from a DHCP server
int ret = _dhcp->beginWithDHCP(mac_address);
if(ret == 1)
{
// We've successfully found a DHCP server and got our configuration info, so set things
// accordingly
W5100.setIPAddress(_dhcp->getLocalIp().raw_address());
W5100.setGatewayIp(_dhcp->getGatewayIp().raw_address());
W5100.setSubnetMask(_dhcp->getSubnetMask().raw_address());
_dnsServerAddress = _dhcp->getDnsServerIp();
}
return ret;
}
示例5: getaddrinfo
IPAddresses Dns::Resolve(const std::string& host) {
IPAddresses list;
addrinfo hints = { 0 }, *addresses;
//hints.ai_family = AF_UNSPEC;
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
getaddrinfo(host.c_str(), NULL, &hints, &addresses);
for (addrinfo *p = addresses; p != NULL; p = p->ai_next) {
#ifdef _WIN32
//wchar_t straddr[35];
//char straddr[512];
//DWORD len;
//WSAAddressToStringA(p->ai_addr, p->ai_addrlen, NULL, straddr, &len);
char* straddr = inet_ntoa(((sockaddr_in*)p->ai_addr)->sin_addr);
#else
char straddr[512];
inet_ntop(p->ai_family, &((sockaddr_in*)p->ai_addr)->sin_addr, straddr, sizeof(straddr));
#endif
list.push_back(IPAddress(straddr));
}
return list;
}
示例6: begin
int EthernetClass::begin(uint8_t *mac_address, unsigned long timeout, unsigned long responseTimeout)
{
static DhcpClass s_dhcp;
_dhcp = &s_dhcp;
// Initialise the basic info
W5100.init();
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
W5100.setMACAddress(mac_address);
W5100.setIPAddress(IPAddress(0,0,0,0).raw_address());
SPI.endTransaction();
// Now try to get our config info from a DHCP server
int ret = _dhcp->beginWithDHCP(mac_address, timeout, responseTimeout);
if(ret == 1)
{
// We've successfully found a DHCP server and got our configuration info, so set things
// accordingly
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
W5100.setIPAddress(_dhcp->getLocalIp().raw_address());
W5100.setGatewayIp(_dhcp->getGatewayIp().raw_address());
W5100.setSubnetMask(_dhcp->getSubnetMask().raw_address());
SPI.endTransaction();
_dnsServerAddress = _dhcp->getDnsServerIp();
}
return ret;
}
示例7: IPAddress
bool
MessageUtilities::RetrieveOriginatingAddress(std::shared_ptr<Message> pMessage, String &hostName, IPAddress &address)
//---------------------------------------------------------------------------()
// DESCRIPTION:
// Tries to determine the IP address / host this email originally comes from.
//---------------------------------------------------------------------------()
{
hostName = "";
address = IPAddress();
// Extract Received headers from the message.
std::shared_ptr<MimeHeader> pHeader = GetMessageHeader_(pMessage);
std::list<String> receivedHeaders;
AnsiString sHeaderName = "Received";
std::vector<MimeField> &lstFields = pHeader->Fields();
auto iter = lstFields.begin();
auto iterEnd = lstFields.end();
for (; iter != iterEnd; iter++)
{
MimeField& fd = *iter;
if (sHeaderName.CompareNoCase(fd.GetName()) == 0)
{
receivedHeaders.push_back(fd.GetValue());
}
}
return RetrieveOriginatingAddress(receivedHeaders, hostName, address);
}
示例8: sizeof
Jatta::Network::IPAddress Jatta::Network::SocketTCP::GetIP()
{
struct sockaddr_storage _Addr;
socklen_t _Length = sizeof(_Addr);
getpeername(sock, (struct sockaddr*)&_Addr, &_Length);
if (_Addr.ss_family == AF_INET) // ipv4
{
return IPAddress((UInt32)((struct sockaddr_in*)&_Addr)->sin_addr.s_addr);
}
else // ipv6
{
UInt64 address[2];
memcpy(&address, &((struct sockaddr_in6*)&_Addr)->sin6_addr, sizeof(address));
return IPAddress(address);
}
}
示例9: getResponses
bool MDNS::processQueries() {
uint16_t n = udp->parsePacket();
if (n > 0) {
buffer->read(udp);
udp->flush();
uint16_t responses = getResponses();
buffer->clear();
if (responses > 0) {
writeResponses(responses);
}
if (buffer->available() > 0)
{
//Serial.println("buffer->available()");
udp->beginPacket(IPAddress(224, 0, 0, 251), MDNS_PORT);
buffer->write(udp);
udp->endPacket();
}
}
return n > 0;
}
示例10: sizeof
void SocketImpl::getOption(int level, int option, IPAddress& value)
{
char buffer[IPAddress::MAX_ADDRESS_LENGTH];
pil_socklen_t len = sizeof(buffer);
getRawOption(level, option, buffer, len);
value = IPAddress(buffer, len);
}
示例11: self
IPAddress IPAddress::operator ~ () const
{
if (family() == IPv4)
{
IPv4AddressImpl self(this->pImpl()->addr());
return IPAddress((~self).addr(), sizeof(struct in_addr));
}
#if defined(POCO_HAVE_IPv6)
else if (family() == IPv6)
{
const IPv6AddressImpl self(pImpl()->addr(), pImpl()->scope());
const IPv6AddressImpl r = ~self;
return IPAddress(r.addr(), sizeof(struct in6_addr), r.scope());
}
#endif
else throw Poco::InvalidArgumentException("Invalid or unsupported address family passed to IPAddress()");
}
示例12: IPAddress
IPAddress FishinoUDP::remoteIP()
{
IPAddress ip;
bool res = Fishino.udpRemoteIP(_sock, ip);
if(!res)
return IPAddress(0, 0, 0, 0);
return ip;
}
示例13: startAP
void startAP()
{
WifiAccessPoint.enable(true);
WifiAccessPoint.config("Sming InternetOfThings", "", AUTH_OPEN);
// Optional: Change IP addresses (and disable DHCP)
WifiAccessPoint.setIP(IPAddress(192, 168, 4, 1));
}
示例14: sizeof
IPAddress IPAddress::AsIPv6Address() const {
if (family_ != AF_INET) {
return *this;
}
in6_addr v6addr = kV4MappedPrefix;
::memcpy(&v6addr.s6_addr[12], &u_.ip4.s_addr, sizeof(u_.ip4.s_addr));
return IPAddress(v6addr);
}
示例15: IPFromString
bool IPFromString(const std::string& str, IPAddress* out) {
if (!out) {
return false;
}
in_addr addr;
if (::inet_pton(AF_INET, str.c_str(), &addr) == 0) {
in6_addr addr6;
if (::inet_pton(AF_INET6, str.c_str(), &addr6) == 0) {
*out = IPAddress();
return false;
}
*out = IPAddress(addr6);
} else {
*out = IPAddress(addr);
}
return true;
}