本文整理汇总了C++中QHostAddress::setScopeId方法的典型用法代码示例。如果您正苦于以下问题:C++ QHostAddress::setScopeId方法的具体用法?C++ QHostAddress::setScopeId怎么用?C++ QHostAddress::setScopeId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QHostAddress
的用法示例。
在下文中一共展示了QHostAddress::setScopeId方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addressFromSockaddr
QT_BEGIN_NAMESPACE
static QHostAddress addressFromSockaddr(sockaddr *sa)
{
QHostAddress address;
if (!sa)
return address;
if (sa->sa_family == AF_INET)
address.setAddress(htonl(((sockaddr_in *)sa)->sin_addr.s_addr));
#ifndef QT_NO_IPV6
else if (sa->sa_family == AF_INET6) {
address.setAddress(((sockaddr_in6 *)sa)->sin6_addr.s6_addr);
int scope = ((sockaddr_in6 *)sa)->sin6_scope_id;
if (scope) {
#ifndef QT_NO_IPV6IFNAME
char scopeid[IFNAMSIZ];
if (::if_indextoname(scope, scopeid)) {
address.setScopeId(QLatin1String(scopeid));
} else
#endif
address.setScopeId(QString::number(scope));
}
}
#endif
return address;
}
示例2: addressFromSockaddr
QT_BEGIN_NAMESPACE
static QHostAddress addressFromSockaddr(sockaddr *sa, int ifindex = 0, const QString &ifname = QString())
{
QHostAddress address;
if (!sa)
return address;
if (sa->sa_family == AF_INET)
address.setAddress(htonl(((sockaddr_in *)sa)->sin_addr.s_addr));
else if (sa->sa_family == AF_INET6) {
address.setAddress(((sockaddr_in6 *)sa)->sin6_addr.s6_addr);
int scope = ((sockaddr_in6 *)sa)->sin6_scope_id;
if (scope && scope == ifindex) {
// this is the most likely scenario:
// a scope ID in a socket is that of the interface this address came from
address.setScopeId(ifname);
} else if (scope) {
#ifndef QT_NO_IPV6IFNAME
char scopeid[IFNAMSIZ];
if (::if_indextoname(scope, scopeid)) {
address.setScopeId(QLatin1String(scopeid));
} else
#endif
address.setScopeId(QString::number(uint(scope)));
}
}
return address;
}
示例3: WSANtohs
/*
Extracts the port and address from a sockaddr, and stores them in
\a port and \a addr if they are non-null.
*/
static inline void qt_socket_getPortAndAddress(SOCKET socketDescriptor, const qt_sockaddr *sa, quint16 *port, QHostAddress *address)
{
#if !defined (QT_NO_IPV6)
if (sa->a.sa_family == AF_INET6) {
const qt_sockaddr_in6 *sa6 = &sa->a6;
Q_IPV6ADDR tmp;
for (int i = 0; i < 16; ++i)
tmp.c[i] = sa6->sin6_addr.qt_s6_addr[i];
if (address) {
QHostAddress a;
a.setAddress(tmp);
a.setScopeId(QString::number(sa6->sin6_scope_id));
*address = a;
}
if (port)
WSANtohs(socketDescriptor, sa6->sin6_port, port);
} else
#endif
if (sa->a.sa_family == AF_INET) {
const sockaddr_in *sa4 = &sa->a4;
unsigned long addr;
WSANtohl(socketDescriptor, sa4->sin_addr.s_addr, &addr);
QHostAddress a;
a.setAddress(addr);
if (address)
*address = a;
if (port)
WSANtohs(socketDescriptor, sa4->sin_port, port);
}
}
示例4: addressFromSockaddr
static QHostAddress addressFromSockaddr(sockaddr *sa)
{
QHostAddress address;
if (!sa)
return address;
if (sa->sa_family == AF_INET)
address.setAddress(htonl(((sockaddr_in *)sa)->sin_addr.s_addr));
else if (sa->sa_family == AF_INET6) {
address.setAddress(((qt_sockaddr_in6 *)sa)->sin6_addr.qt_s6_addr);
int scope = ((qt_sockaddr_in6 *)sa)->sin6_scope_id;
if (scope)
address.setScopeId(QString::number(scope));
} else
qWarning("Got unknown socket family %d", sa->sa_family);
return address;
}
示例5: JingleTransport
Transport::Transport(JingleContent *content)
: JingleTransport(content)
{
QList<QHostAddress> addresses;
foreach (const QNetworkInterface &networkInterface, QNetworkInterface::allInterfaces()) {
if (networkInterface.flags() & QNetworkInterface::IsLoopBack)
continue;
foreach (const QNetworkAddressEntry &addressEntry, networkInterface.addressEntries()) {
QHostAddress address = addressEntry.ip();
if(address.protocol() == QAbstractSocket::IPv6Protocol && XMPP::Ice176::isIPv6LinkLocalAddress(address))
address.setScopeId(networkInterface.name());
addresses << address;
}
}
qSort(addresses.begin(), addresses.end(), addressLessThen);
QList<XMPP::Ice176::LocalAddress> localAddresses;
foreach (const QHostAddress &address, addresses) {
XMPP::Ice176::LocalAddress localAddress;
localAddress.addr = address;
localAddresses << localAddress;
}
示例6: sipReleaseType
static PyObject *meth_QHostAddress_setScopeId(PyObject *sipSelf, PyObject *sipArgs)
{
PyObject *sipParseErr = NULL;
{
const QString* a0;
int a0State = 0;
QHostAddress *sipCpp;
if (sipParseArgs(&sipParseErr, sipArgs, "BJ1", &sipSelf, sipType_QHostAddress, &sipCpp, sipType_QString,&a0, &a0State))
{
sipCpp->setScopeId(*a0);
sipReleaseType(const_cast<QString *>(a0),sipType_QString,a0State);
Py_INCREF(Py_None);
return Py_None;
}
}
/* Raise an exception if the arguments couldn't be parsed. */
sipNoMethod(sipParseErr, sipName_QHostAddress, sipName_setScopeId, doc_QHostAddress_setScopeId);
return NULL;
}
示例7: fromName
//.........这里部分代码省略.........
hints.ai_family = PF_UNSPEC;
#ifdef Q_ADDRCONFIG
hints.ai_flags = Q_ADDRCONFIG;
#endif
int result = getaddrinfo(aceHostname.constData(), 0, &hints, &res);
# ifdef Q_ADDRCONFIG
if (result == EAI_BADFLAGS) {
// if the lookup failed with AI_ADDRCONFIG set, try again without it
hints.ai_flags = 0;
result = getaddrinfo(aceHostname.constData(), 0, &hints, &res);
}
# endif
if (result == 0) {
addrinfo *node = res;
QList<QHostAddress> addresses;
while (node) {
#ifdef QHOSTINFO_DEBUG
qDebug() << "getaddrinfo node: flags:" << node->ai_flags << "family:" << node->ai_family << "ai_socktype:" << node->ai_socktype << "ai_protocol:" << node->ai_protocol << "ai_addrlen:" << node->ai_addrlen;
#endif
if (node->ai_family == AF_INET) {
QHostAddress addr;
addr.setAddress(ntohl(((sockaddr_in *) node->ai_addr)->sin_addr.s_addr));
if (!addresses.contains(addr))
addresses.append(addr);
}
#ifndef QT_NO_IPV6
else if (node->ai_family == AF_INET6) {
QHostAddress addr;
sockaddr_in6 *sa6 = (sockaddr_in6 *) node->ai_addr;
addr.setAddress(sa6->sin6_addr.s6_addr);
if (sa6->sin6_scope_id)
addr.setScopeId(QString::number(sa6->sin6_scope_id));
if (!addresses.contains(addr))
addresses.append(addr);
}
#endif
node = node->ai_next;
}
if (addresses.isEmpty() && node == 0) {
// Reached the end of the list, but no addresses were found; this
// means the list contains one or more unknown address types.
results.setError(QHostInfo::UnknownError);
results.setErrorString(tr("Unknown address type"));
}
results.setAddresses(addresses);
freeaddrinfo(res);
} else if (result == EAI_NONAME
|| result == EAI_FAIL
#ifdef EAI_NODATA
// EAI_NODATA is deprecated in RFC 3493
|| result == EAI_NODATA
#endif
) {
results.setError(QHostInfo::HostNotFound);
results.setErrorString(tr("Host not found"));
} else {
results.setError(QHostInfo::UnknownError);
results.setErrorString(QString::fromLocal8Bit(gai_strerror(result)));
}
#else
// Fall back to gethostbyname for platforms that don't define
// getaddrinfo. gethostbyname does not support IPv6, and it's not
示例8: SelectDefaultListen
//.........这里部分代码省略.........
if (ip.isInSubnet(privNet1) || ip.isInSubnet(privNet2) ||
ip.isInSubnet(privNet3))
{
LOG(VB_GENERAL, LOG_DEBUG,
QString("Adding '%1' to address list.")
.arg(PRETTYIP_(ip)));
naList_4.append(*qnai);
}
else if (ip.isInSubnet(kLinkLocal))
{
LOG(VB_GENERAL, LOG_DEBUG,
QString("Adding link-local '%1' to address list.")
.arg(PRETTYIP_(ip)));
naList_4.append(*qnai);
}
else
LOG(VB_GENERAL, LOG_DEBUG, QString("Skipping "
"non-private address during IPv4 autoselection: %1")
.arg(PRETTYIP_(ip)));
}
else
LOG(VB_GENERAL, LOG_DEBUG, QString("Skipping address: %1")
.arg(PRETTYIP_(ip)));
#if !defined(QT_NO_IPV6)
}
else
{
if (ip.isInSubnet(kLinkLocal6))
{
// set scope id for link local address
ip.setScopeId(qni->name());
qnai->setIp(ip);
}
if (naList_6.contains(*qnai))
// already defined, skip
continue;
else if ((!config_v6.isNull()) && (ip == config_v6))
{
// IPv6 address is defined, add it
LOG(VB_GENERAL, LOG_DEBUG,
QString("Adding BackendServerIP6 to address list."));
naList_6.append(*qnai);
v6IsSet = true;
}
else if (ip == QHostAddress::LocalHostIPv6)
{
// always listen on LocalHost
LOG(VB_GENERAL, LOG_DEBUG,
QString("Adding IPv6 loopback to address list."));
naList_6.append(*qnai);
if (!v6IsSet && (config_v6 == ip))
v6IsSet = true;
}
else if (ip.isInSubnet(kLinkLocal6) && allowLinkLocal)
{
// optionally listen on linklocal
// the next clause will enable it anyway if no IP address
// has been set
LOG(VB_GENERAL, LOG_DEBUG,
示例9: SendNotifyMsg
void UPnpNotifyTask::SendNotifyMsg( MSocketDevice *pSocket,
QString sNT,
QString sUDN )
{
QString sUSN;
if ( sUDN.length() > 0)
sUSN = sUDN + "::" + sNT;
else
sUSN = sNT;
QString sData = QString ( "Server: %1\r\n"
"NTS: %3\r\n"
"NT: %4\r\n"
"USN: %5\r\n"
"CACHE-CONTROL: max-age=%6\r\n"
"Content-Length: 0\r\n\r\n" )
.arg( HttpServer::GetServerVersion() )
.arg( GetNTSString() )
.arg( sNT )
.arg( sUSN )
.arg( m_nMaxAge );
LOG(VB_UPNP, LOG_INFO,
QString("UPnpNotifyTask::SendNotifyMsg : %1:%2 : %3 : %4")
.arg(pSocket->address().toString()) .arg(pSocket->port())
.arg(sNT) .arg(sUSN));
QMutexLocker qml(&m_mutex); // for addressList
// -------------------------------------------------------------------
// Refresh IP Address List in case of changes
// -------------------------------------------------------------------
QList<QHostAddress> addressList = UPnp::g_IPAddrList;
for ( QList<QHostAddress>::Iterator it = addressList.begin();
it != addressList.end();
++it )
{
if ((*it).toString().isEmpty())
{
LOG(VB_GENERAL, LOG_ERR,
"UPnpNotifyTask::SendNotifyMsg - NULL in address list");
continue;
}
QHostAddress ip = *it;
// Descope the Link Local address. The scope is only valid
// on the server sending the announcement, not the clients
// that receive it
ip.setScopeId(QString());
QString ipaddress = ip.toString();
// If this looks like an IPv6 address, then enclose it in []'s
if (ipaddress.contains(":"))
ipaddress = "[" + ipaddress + "]";
QString sHeader = QString("NOTIFY * HTTP/1.1\r\n"
"HOST: %1:%2\r\n"
"LOCATION: http://%3:%4/getDeviceDesc\r\n")
.arg(pSocket->address().toString()) .arg(pSocket->port())
.arg(ipaddress) .arg(m_nServicePort);
QString sPacket = sHeader + sData;
QByteArray scPacket = sPacket.toUtf8();
// ---------------------------------------------------------------
// Send Packet to Socket (Send same packet twice)
// ---------------------------------------------------------------
pSocket->writeBlock( scPacket, scPacket.length(),
pSocket->address(), pSocket->port() );
std::this_thread::sleep_for(std::chrono::milliseconds(random() % 250));
pSocket->writeBlock( scPacket, scPacket.length(),
pSocket->address(), pSocket->port() );
}
}
示例10: SendMsg
void UPnpSearchTask::SendMsg( MSocketDevice *pSocket,
QString sST,
QString sUDN )
{
QString sUSN;
if (( sUDN.length() > 0) && ( sUDN != sST ))
sUSN = sUDN + "::" + sST;
else
sUSN = sST;
QString sDate = MythDate::current().toString( "d MMM yyyy hh:mm:ss" );
QString sData = QString ( "CACHE-CONTROL: max-age=%1\r\n"
"DATE: %2\r\n"
"EXT:\r\n"
"Server: %3\r\n"
"ST: %4\r\n"
"USN: %5\r\n"
"Content-Length: 0\r\n\r\n" )
.arg( m_nMaxAge )
.arg( sDate )
.arg( HttpServer::GetServerVersion() )
.arg( sST )
.arg( sUSN );
#if 0
LOG(VB_UPNP, LOG_DEBUG, QString("UPnpSearchTask::SendMsg : %1 : %2 ")
.arg(sST) .arg(sUSN));
LOG(VB_UPNP, LOG_DEBUG,
QString("UPnpSearchTask::SendMsg m_PeerAddress = %1 Port=%2")
.arg(m_PeerAddress.toString()) .arg(m_nPeerPort));
#endif
for ( QList<QHostAddress>::Iterator it = m_addressList.begin();
it != m_addressList.end();
++it )
{
QString ipaddress;
// Avoid announcing the localhost address
if (*it == QHostAddress::LocalHost ||
*it == QHostAddress::LocalHostIPv6 ||
*it == QHostAddress::AnyIPv4 ||
*it == QHostAddress::AnyIPv6)
continue;
QHostAddress ip = *it;
// Descope the Link Local address. The scope is only valid
// on the server sending the announcement, not the clients
// that receive it
ip.setScopeId(QString());
// If this looks like an IPv6 address, then enclose it in []'s
if (ip.protocol() == QAbstractSocket::IPv6Protocol)
ipaddress = "[" + ip.toString() + "]";
else
ipaddress = ip.toString();
QString sHeader = QString ( "HTTP/1.1 200 OK\r\n"
"LOCATION: http://%1:%2/getDeviceDesc\r\n" )
.arg( ipaddress )
.arg( m_nServicePort);
QString sPacket = sHeader + sData;
QByteArray scPacket = sPacket.toUtf8();
// ------------------------------------------------------------------
// Send Packet to UDP Socket (Send same packet twice)
// ------------------------------------------------------------------
pSocket->writeBlock( scPacket, scPacket.length(), m_PeerAddress,
m_nPeerPort );
std::this_thread::sleep_for( std::chrono::milliseconds( random() % 250 ));
pSocket->writeBlock( scPacket, scPacket.length(), m_PeerAddress,
m_nPeerPort );
}
}