Results 1 to 15 of 15

Thread: broadcast ip interface on windows xp

  1. #1
    Join Date
    May 2007
    Posts
    9
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default broadcast ip interface on windows xp

    Why Chat example doesn't work on Windows XP? In Linux or W2K seems to work.

    The problem is the broadcast ip from interface:

    Qt Code:
    1. foreach (QNetworkInterface interface, QNetworkInterface::allInterfaces()) {
    2. foreach (QNetworkAddressEntry entry, interface.addressEntries()) {
    3. qDebug() << "IP: " << entry.ip().toString() <<
    4. "\nNetmask " << entry.netmask().toString() <<
    5. "\nBroadcast " << entry.broadcast().toString();
    6. }
    7. }
    To copy to clipboard, switch view to plain text mode 

    In Windows XP entry.broadcast() is Null in LAN ifaces also.

    Thx. Selu.

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: broadcast ip interface on windows xp

    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
    Last edited by marcel; 19th May 2007 at 04:59.

  3. The following user says thank you to marcel for this useful post:

    pawer (19th May 2007)

  4. #3
    Join Date
    May 2007
    Posts
    9
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: broadcast ip interface on windows xp

    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: ""

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: broadcast ip interface on windows xp

    Do you have the standard Windows firewall enabled?

  6. #5
    Join Date
    May 2007
    Posts
    9
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: broadcast ip interface on windows xp

    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.

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: broadcast ip interface on windows xp

    Did you run the application with administrative rights? Maybe your security level simply blocks access to broadcast?

  8. #7
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: broadcast ip interface on windows xp

    Quote Originally Posted by pawer View Post
    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

  9. #8
    Join Date
    May 2007
    Posts
    9
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: broadcast ip interface on windows xp

    In WinXP I run it with Administrator user in several machines and in Linux with an unpriviledged user. I'm going crazy

    Thanks. Selu

  10. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: broadcast ip interface on windows xp

    Linux doesn't forbid you from using broadcast while WinXP could. How do other Qt network examples behave? Do they work correctly?

  11. The following user says thank you to wysota for this useful post:

    pawer (19th May 2007)

  12. #10
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: broadcast ip interface on windows xp

    Open a "command prompt" ( console ) and type "ipconfig /all".
    See if all the information is correct and complete.

    Regards

  13. The following user says thank you to marcel for this useful post:

    pawer (19th May 2007)

  14. #11
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: broadcast ip interface on windows xp

    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

  15. The following user says thank you to marcel for this useful post:

    pawer (19th May 2007)

  16. #12
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: broadcast ip interface on windows xp

    This is how it's calculated by Qt, for Win2K

    Qt Code:
    1. // calculate the broadcast address
    2. quint32 ip = entry.ip().toIPv4Address();
    3. quint32 mask = entry.netmask().toIPv4Address();
    4. quint32 broadcast = (ip & mask) | (0xFFFFFFFFU & ~mask);
    To copy to clipboard, switch view to plain text mode 


    However, the funny thing is, that for WinXP, there is no such calculation:
    Qt Code:
    1. static QList<QNetworkInterfacePrivate *> interfaceListingWinXP()
    2. {
    3. QList<QNetworkInterfacePrivate *> interfaces;
    4. IP_ADAPTER_ADDRESSES staticBuf[2]; // 2 is arbitrary
    5. PIP_ADAPTER_ADDRESSES pAdapter = staticBuf;
    6. ULONG bufSize = sizeof staticBuf;
    7.  
    8. ULONG flags = GAA_FLAG_INCLUDE_ALL_INTERFACES |
    9. GAA_FLAG_INCLUDE_PREFIX |
    10. GAA_FLAG_SKIP_DNS_SERVER |
    11. GAA_FLAG_SKIP_MULTICAST;
    12. ULONG retval = ptrGetAdaptersAddresses(AF_UNSPEC, flags, NULL, pAdapter, &bufSize);
    13. if (retval == ERROR_BUFFER_OVERFLOW) {
    14. // need more memory
    15. pAdapter = (IP_ADAPTER_ADDRESSES *)qMalloc(bufSize);
    16.  
    17. // try again
    18. if (ptrGetAdaptersAddresses(AF_UNSPEC, flags, NULL, pAdapter, &bufSize) != ERROR_SUCCESS) {
    19. qFree(pAdapter);
    20. return interfaces;
    21. }
    22. } else if (retval != ERROR_SUCCESS) {
    23. // error
    24. return interfaces;
    25. }
    26.  
    27. // iterate over the list and add the entries to our listing
    28. for (PIP_ADAPTER_ADDRESSES ptr = pAdapter; ptr; ptr = ptr->Next) {
    29. QNetworkInterfacePrivate *iface = new QNetworkInterfacePrivate;
    30. interfaces << iface;
    31.  
    32. iface->index = 0;
    33. if (ptr->Length >= offsetof(IP_ADAPTER_ADDRESSES, Ipv6IfIndex))
    34. iface->index = ptr->Ipv6IfIndex;
    35. else if (ptr->IfIndex != 0)
    36. iface->index = ptr->IfIndex;
    37.  
    38. iface->flags = QNetworkInterface::CanBroadcast;
    39. if (ptr->OperStatus == IfOperStatusUp)
    40. iface->flags |= QNetworkInterface::IsUp | QNetworkInterface::IsRunning;
    41. if ((ptr->Flags & IP_ADAPTER_NO_MULTICAST) == 0)
    42. iface->flags |= QNetworkInterface::CanMulticast;
    43.  
    44. iface->name = QString::fromLocal8Bit(ptr->AdapterName);
    45. if (ptr->PhysicalAddressLength)
    46. iface->hardwareAddress = iface->makeHwAddress(ptr->PhysicalAddressLength,
    47. ptr->PhysicalAddress);
    48. else
    49. // loopback if it has no address
    50. iface->flags |= QNetworkInterface::IsLoopBack;
    51.  
    52. // The GetAdaptersAddresses call has an interesting semantic:
    53. // It can return a number N of addresses and a number M of prefixes.
    54. // But if you have IPv6 addresses, generally N > M.
    55. // I cannot find a way to relate the Address to the Prefix, aside from stopping
    56. // the iteration at the last Prefix entry and assume that it applies to all addresses
    57. // from that point on.
    58. PIP_ADAPTER_PREFIX pprefix = 0;
    59. if (ptr->Length >= offsetof(IP_ADAPTER_ADDRESSES, FirstPrefix))
    60. pprefix = ptr->FirstPrefix;
    61. for (PIP_ADAPTER_UNICAST_ADDRESS addr = ptr->FirstUnicastAddress; addr; addr = addr->Next) {
    62. entry.setIp(addressFromSockaddr(addr->Address.lpSockaddr));
    63. if (pprefix) {
    64. entry.setNetmask(netmaskFromPrefixLength(pprefix->PrefixLength, addr->Address.lpSockaddr->sa_family));
    65. pprefix = pprefix->Next ? pprefix->Next : pprefix;
    66. }
    67.  
    68. iface->addressEntries << entry;
    69. }
    70. }
    71.  
    72. if (pAdapter != staticBuf)
    73. qFree(pAdapter);
    74.  
    75. return interfaces;
    76. }
    To copy to clipboard, switch view to plain text mode 


    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

  17. The following user says thank you to marcel for this useful post:

    pawer (19th May 2007)

  18. #13
    Join Date
    May 2007
    Posts
    9
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: broadcast ip interface on windows xp

    Thanks. I'm going to try it out.

  19. #14
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: broadcast ip interface on windows xp

    I already told you:
    Qt Code:
    1. quint32 ip = entry.ip().toIPv4Address();
    2. quint32 mask = entry.netmask().toIPv4Address();
    3. quint32 broadcast = (ip & mask) | (0xFFFFFFFFU & ~mask);
    4. entry.setBroadcast(QHostAddress((broadcast)));
    To copy to clipboard, switch view to plain text mode 
    Actually the code is stolen from the Qt sources .

  20. The following user says thank you to marcel for this useful post:

    pawer (19th May 2007)

  21. #15
    Join Date
    May 2007
    Posts
    9
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: broadcast ip interface on windows xp

    This works perfectly, in Qt 4.3.0rc1 this is solved.

    Thanks.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.