View Full Version : broadcast ip interface on windows xp
pawer
18th May 2007, 23:01
Why Chat example doesn't work on Windows XP? In Linux or W2K seems to work.
The problem is the broadcast ip from interface:
foreach (QNetworkInterface interface, QNetworkInterface::allInterfaces()) {
foreach (QNetworkAddressEntry entry, interface.addressEntries()) {
qDebug() << "IP: " << entry.ip().toString() <<
"\nNetmask " << entry.netmask().toString() <<
"\nBroadcast " << entry.broadcast().toString();
}
}
In Windows XP entry.broadcast() is Null in LAN ifaces also.
Thx. Selu.
marcel
19th May 2007, 05:54
Make sure you don't have any blocking software( antivirus, etc ) on WinXp.
Also, are you using by anychance IPv6? Because you don't have a broadcast addr there ( it's multicast ).
Regards
pawer
19th May 2007, 12:59
I've unistalled Nod32, but seems equal.
This is the output for WinXP:
Starting program: C:\chat/release\chat.exe
---Type <return> to continue, or q <return> to quit---
warning: iface: "{E48D2691-0A73-4F6F-BD24-3851400ED148}"
warning: IP: "192.168.0.3"
Mask: "255.255.255.0"
Broadcast: ""
warning: iface: "MS TCP Loopback interface"
warning: IP: "127.0.0.1"
Mask: ""
Broadcast: ""
wysota
19th May 2007, 13:08
Do you have the standard Windows firewall enabled?
pawer
19th May 2007, 13:37
It does the same. I think it's not a problem of firewalling, if I put QHostAddress::Broadcast it communicates well. In my Linux desktop the output is this:
"lo"
IP: "127.0.0.1"
Netmask "255.0.0.0"
Broadcast ""
IP: "0:0:0:0:0:0:0:1"
Netmask "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF"
Broadcast ""
"eth0"
IP: "192.168.0.2"
Netmask "255.255.255.0"
Broadcast "192.168.0.255"
IP: "FE80:0:0:0:211:D8FF:FE0D:A1C3"
Netmask "FFFF:FFFF:FFFF:FFFF:0:0:0:0"
Broadcast ""
Thanks. Selu.
wysota
19th May 2007, 14:48
Did you run the application with administrative rights? Maybe your security level simply blocks access to broadcast?
marcel
19th May 2007, 14:58
I've unistalled Nod32, but seems equal.
This is the output for WinXP:
Hmm...
I'm not saying that Nod32 is bad software( hey, it's romanian :)), but I have had problems before with it, after uninstalling it. Problems like connecting to the internet. I think it happened twice.
I didn't find a real solution either. I just reinstalled Windows( it wasn't my computer :) ).
I'm not saying you should reinstall also, but dig a little deeper.
Regards
pawer
19th May 2007, 15:12
In WinXP I run it with Administrator user in several machines and in Linux with an unpriviledged user. I'm going crazy :eek:
Thanks. Selu
wysota
19th May 2007, 15:16
Linux doesn't forbid you from using broadcast while WinXP could. How do other Qt network examples behave? Do they work correctly?
marcel
19th May 2007, 15:37
Open a "command prompt" ( console :) ) and type "ipconfig /all".
See if all the information is correct and complete.
Regards
marcel
19th May 2007, 15:45
How about computing the broadcast address yourself?
You have the IP addr and the subnet mask.
As far as I know, taking the binary representations of the two, the broadcast is:
bradcast = (~subnet) | ip;
Just saying...
Regards
marcel
19th May 2007, 15:58
This is how it's calculated by Qt, for Win2K
// calculate the broadcast address
quint32 ip = entry.ip().toIPv4Address();
quint32 mask = entry.netmask().toIPv4Address();
quint32 broadcast = (ip & mask) | (0xFFFFFFFFU & ~mask);
However, the funny thing is, that for WinXP, there is no such calculation:
static QList<QNetworkInterfacePrivate *> interfaceListingWinXP()
{
QList<QNetworkInterfacePrivate *> interfaces;
IP_ADAPTER_ADDRESSES staticBuf[2]; // 2 is arbitrary
PIP_ADAPTER_ADDRESSES pAdapter = staticBuf;
ULONG bufSize = sizeof staticBuf;
ULONG flags = GAA_FLAG_INCLUDE_ALL_INTERFACES |
GAA_FLAG_INCLUDE_PREFIX |
GAA_FLAG_SKIP_DNS_SERVER |
GAA_FLAG_SKIP_MULTICAST;
ULONG retval = ptrGetAdaptersAddresses(AF_UNSPEC, flags, NULL, pAdapter, &bufSize);
if (retval == ERROR_BUFFER_OVERFLOW) {
// need more memory
pAdapter = (IP_ADAPTER_ADDRESSES *)qMalloc(bufSize);
// try again
if (ptrGetAdaptersAddresses(AF_UNSPEC, flags, NULL, pAdapter, &bufSize) != ERROR_SUCCESS) {
qFree(pAdapter);
return interfaces;
}
} else if (retval != ERROR_SUCCESS) {
// error
return interfaces;
}
// iterate over the list and add the entries to our listing
for (PIP_ADAPTER_ADDRESSES ptr = pAdapter; ptr; ptr = ptr->Next) {
QNetworkInterfacePrivate *iface = new QNetworkInterfacePrivate;
interfaces << iface;
iface->index = 0;
if (ptr->Length >= offsetof(IP_ADAPTER_ADDRESSES, Ipv6IfIndex))
iface->index = ptr->Ipv6IfIndex;
else if (ptr->IfIndex != 0)
iface->index = ptr->IfIndex;
iface->flags = QNetworkInterface::CanBroadcast;
if (ptr->OperStatus == IfOperStatusUp)
iface->flags |= QNetworkInterface::IsUp | QNetworkInterface::IsRunning;
if ((ptr->Flags & IP_ADAPTER_NO_MULTICAST) == 0)
iface->flags |= QNetworkInterface::CanMulticast;
iface->name = QString::fromLocal8Bit(ptr->AdapterName);
if (ptr->PhysicalAddressLength)
iface->hardwareAddress = iface->makeHwAddress(ptr->PhysicalAddressLength,
ptr->PhysicalAddress);
else
// loopback if it has no address
iface->flags |= QNetworkInterface::IsLoopBack;
// The GetAdaptersAddresses call has an interesting semantic:
// It can return a number N of addresses and a number M of prefixes.
// But if you have IPv6 addresses, generally N > M.
// I cannot find a way to relate the Address to the Prefix, aside from stopping
// the iteration at the last Prefix entry and assume that it applies to all addresses
// from that point on.
PIP_ADAPTER_PREFIX pprefix = 0;
if (ptr->Length >= offsetof(IP_ADAPTER_ADDRESSES, FirstPrefix))
pprefix = ptr->FirstPrefix;
for (PIP_ADAPTER_UNICAST_ADDRESS addr = ptr->FirstUnicastAddress; addr; addr = addr->Next) {
QNetworkAddressEntry entry;
entry.setIp(addressFromSockaddr(addr->Address.lpSockaddr));
if (pprefix) {
entry.setNetmask(netmaskFromPrefixLength(pprefix->PrefixLength, addr->Address.lpSockaddr->sa_family));
pprefix = pprefix->Next ? pprefix->Next : pprefix;
}
iface->addressEntries << entry;
}
}
if (pAdapter != staticBuf)
qFree(pAdapter);
return interfaces;
}
These are taken from qnetworkinterface_win.cpp.
I'm using Qt 4.2.2.
I suggest doing as for Win2k to get the broadcast.
Regards
pawer
19th May 2007, 15:59
Thanks. I'm going to try it out.
marcel
19th May 2007, 16:01
I already told you:
quint32 ip = entry.ip().toIPv4Address();
quint32 mask = entry.netmask().toIPv4Address();
quint32 broadcast = (ip & mask) | (0xFFFFFFFFU & ~mask);
entry.setBroadcast(QHostAddress((broadcast)));
Actually the code is stolen from the Qt sources :).
pawer
19th May 2007, 16:49
This works perfectly, in Qt 4.3.0rc1 this is solved.
Thanks.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.