本文整理汇总了C++中IPAddress::set方法的典型用法代码示例。如果您正苦于以下问题:C++ IPAddress::set方法的具体用法?C++ IPAddress::set怎么用?C++ IPAddress::set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPAddress
的用法示例。
在下文中一共展示了IPAddress::set方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Read
bool LUAIPAddress::Read(Exception& ex, lua_State *pState, int index, IPAddress& address,bool withDNS) {
if (lua_type(pState, index)==LUA_TSTRING) // lua_type because can be encapsulated in a lua_next
return withDNS ? address.setWithDNS(ex, lua_tostring(pState,index)) : address.set(ex, lua_tostring(pState,index));
if(lua_istable(pState,index)) {
bool isConst;
IPAddress* pOther = Script::ToObject<IPAddress>(pState, isConst, index);
if (pOther) {
address.set(*pOther);
return true;
}
SocketAddress* pAddress = Script::ToObject<SocketAddress>(pState, isConst, index);
if (pAddress) {
address.set(pAddress->host());
return true;
}
ServerConnection* pServer = Script::ToObject<ServerConnection>(pState, isConst, index);
if (pServer) {
address.set(pServer->address.host());
return true;
}
}
ex.set(Exception::NETADDRESS, "No valid IPAddress available to read");
return false;
}
示例2: Resolve
bool DNS::Resolve(Exception& ex, const char* address, HostEntry& host) {
IPAddress ip;
Exception ignore;
if (ip.set(ignore, address))
return HostByAddress(ex,ip,host);
return HostByName(ex, address, host);
}
示例3: setIntern
bool SocketAddress::setIntern(Exception& ex,const string& host, UInt16 port,bool resolveHost) {
IPAddress ip;
Exception ignore;
if (ip.set(ignore, host)) {
set(ip, port);
return true;
}
HostEntry entry;
if (!resolveHost) {
if (ignore)
ex.set(ignore);
return false;
}
if (!DNS::HostByName(ex, host, entry))
return false;
auto& addresses = entry.addresses();
if (addresses.size() > 0) {
// if we get both IPv4 and IPv6 addresses, prefer IPv4
for (const IPAddress& address : addresses) {
if (address.family() == IPAddress::IPv4) {
set(address, port);
return true;
}
}
set(addresses.front(), port);
return true;
}
ex.set(Exception::NETADDRESS, "No address found for the host ", host);
return false;
}
示例4:
ADD_TEST(DNSTest, HostByAddress) {
Exception ex;
HostEntry hostEntry;
IPAddress ip;
ip.set(ex, "80.122.195.86");
CHECK(!ex)
DNS::HostByAddress(ex, ip, hostEntry);
CHECK(!ex)
CHECK(hostEntry.name() == "mailhost.appinf.com");
CHECK(hostEntry.aliases().empty());
CHECK(hostEntry.addresses().size() >= 1);
CHECK(hostEntry.addresses().front().toString() == "80.122.195.86");
ip.set(ex, "10.0.244.253");
CHECK(!ex)
DNS::HostByAddress(ex, ip, hostEntry);
CHECK(ex)
}
示例5: build
bool SDP::build(Exception& ex, const char* text) {
SDPMedia* pMedia = NULL;
String::ForEach forEach([this,&pMedia,&ex](UInt32 index,const char* line){
if(strlen(line)==0 || line[1] != '=') {
ex.set(Exception::FORMATTING, "SDP line ",line," malformed, second byte isn't an equal sign");
return false;
}
UInt8 type = line[0];
line = String::TrimLeft(line);
// RFC 4566
switch(type) {
case 'v': // v= (protocol version)
version = String::ToNumber<UInt32>(ex, line);
break;
case 'o': { // o=<username> <sess-id> <sess-version> <nettype> <addrtype> <unicast-address>
String::ForEach forEach([&ex,this](UInt32 index, const char* value) {
switch (index) {
case 0:
user.assign(value);
break;
case 1:
sessionId = String::ToNumber<UInt32>(ex, value);
break;
case 2:
sessionVersion = String::ToNumber<UInt32>(ex, value);
break;
case 4:
unicastAddress.set(IPAddress::Wildcard(String::ICompare(value,"IP6")==0 ? IPAddress::IPv6 : IPAddress::IPv4));
break;
case 5:
unicastAddress.set(ex,value,unicastAddress.family());
break;
}
return !ex;
});
if(String::Split(line, " ", forEach, String::SPLIT_IGNORE_EMPTY | String::SPLIT_TRIM)<6)
ex.set(Exception::PROTOCOL, "SDP o line required 6 values (<username> <sess-id> <sess-version> <nettype> <addrtype> <unicast-address>)");
break;
}
case 's': // s= (session name)
sessionName = line;
break;
/// Optional lines
case 'i': // i=* (session information)
sessionInfos = line;
break;
case 'u': // u=* (URI of description)
uri = line;
break;
case 'e': // e=* (email address)
email = line;
break;
case 'p': // p=* (phone number)
phone = line;
break;
case 'c': { // c=* (connection information -- not required if included in all media)
IPAddress defaultAddress; // TODO defaultAddress is useless for what?
String::ForEach forEach([&ex,&defaultAddress, this](UInt32 index, const char* value) {
switch (index) {
case 1:
defaultAddress.set(IPAddress::Wildcard(String::ICompare(value,"IP6")==0 ? IPAddress::IPv6 : IPAddress::IPv4));
break;
case 2:
defaultAddress.set(ex,value,defaultAddress.family());
break;
}
return !ex;
});
if(String::Split(line, " ", forEach, String::SPLIT_IGNORE_EMPTY | String::SPLIT_TRIM)<3)
ex.set(Exception::PROTOCOL, "SDP c line required 3 values");
break;
}
case 'b': // b=* (zero or more bandwidth information lines)
// TODO useless?
break;
// One or more time descriptions ("t=" and "r=" lines; see below)
// t= (time the session is active)
// r=* (zero or more repeat times)
case 't':
// TODO useless?
break;
case 'r':
// TODO useless?
break;
case 'z': // z=* (time zone adjustments)
// TODO useless?
break;
case 'k': // k=* (encryption key)
encryptKey = line;
break;
case 'm': { // m=<name> <port> <proto> <fmt>
string name;
UInt16 port;
//.........这里部分代码省略.........
示例6: build
bool SDP::build(Exception& ex, const string& text) {
SDPMedia* pMedia = NULL;
vector<string> lines;
String::Split(text, "\r\n", lines, String::SPLIT_IGNORE_EMPTY | String::SPLIT_TRIM);
for(string& line : lines) {
if(line.empty() || line[1] != '=') {
ex.set(Exception::FORMATTING, "SDP line ",line," malformed, second byte isn't an equal sign");
return false;
}
UInt8 type = line[0];
line.erase(0,2);
String::Trim(line, String::TRIM_LEFT);
// RFC 4566
switch(type) {
case 'v': // v= (protocol version)
version = String::ToNumber<UInt32>(ex, line);
break;
case 'o': { // o=<username> <sess-id> <sess-version> <nettype> <addrtype> <unicast-address>
vector<string> fields;
String::Split(line, " ", fields, String::SPLIT_IGNORE_EMPTY | String::SPLIT_TRIM);
if (fields.size()!=6) {
ex.set(Exception::PROTOCOL, "fields.size()!=6");
break;
}
user = fields[0];
sessionId = String::ToNumber<UInt32>(ex, fields[1]);
if (ex)
break;
sessionVersion = String::ToNumber<UInt32>(ex, fields[2]);
if (ex)
break;
unicastAddress.set(ex,fields[5],fields[4]=="IP6" ? IPAddress::IPv6 : IPAddress::IPv4);
break;
}
case 's': // s= (session name)
sessionName = line;
break;
/// Optional lines
case 'i': // i=* (session information)
sessionInfos = line;
break;
case 'u': // u=* (URI of description)
uri = line;
break;
case 'e': // e=* (email address)
email = line;
break;
case 'p': // p=* (phone number)
phone = line;
break;
case 'c': { // c=* (connection information -- not required if included in all media)
vector<string> fields;
String::Split(line, " ", fields, String::SPLIT_IGNORE_EMPTY | String::SPLIT_TRIM);
if(fields.size()!=3) {
ex.set(Exception::PROTOCOL, "fields.size()!=3");
break;
}
IPAddress defaultAddress; // TODO defaultAddress is useless for what?
defaultAddress.set(ex,fields[2], fields[1] == "IP6" ? IPAddress::IPv6 : IPAddress::IPv4);
break;
}
case 'b': // b=* (zero or more bandwidth information lines)
// TODO useless?
break;
// One or more time descriptions ("t=" and "r=" lines; see below)
// t= (time the session is active)
// r=* (zero or more repeat times)
case 't':
// TODO useless?
break;
case 'r':
// TODO useless?
break;
case 'z': // z=* (time zone adjustments)
// TODO useless?
break;
case 'k': // k=* (encryption key)
encryptKey = line;
break;
case 'm': { // m=<name> <port> <proto> <fmt>
vector<string> values;
String::Split(line, " ", values, String::SPLIT_IGNORE_EMPTY | String::SPLIT_TRIM);
if (values.size()<4) {
ex.set(Exception::PROTOCOL , "values.size()<4");
break;
}
UInt16 val = String::ToNumber<UInt16>(ex, values[1]);
if (ex)
break;
//.........这里部分代码省略.........