how get gateway in qt?



  • I need to get gateway address. Function preparing adress must work on windows, linux, android and mb iOS. It is necessary to find address of router, that is connected to user.
    What can suggest me?
    my search turned only to topics that are written 3-4 years ago and methods dont work yet



  • i can use route -n, but how use it in my programm...hmmm....



  • @valeriy said:

    I need to get gateway address.

    As far as I know, Qt does not provide any specific functionality for that.

    There's actually quite a lot of complexity behind your simply-stated requirement. On most platforms, "the gateway" choice can depend on any and all properties of the connection being requested, but most commonly at least:

    • the chosen (automatically or explicit) network interface ;
    • the destination address.

    And in many cases, there's actually a list of available gateway addresses (often weighted) for any given combination, not just one.

    So it really does depend on what you're trying to do, how detailed / accurate you need to be, and how much variation you need to support. But regardless, you'll need a fair bit of platform-specific code to get a true gateway address.

    It is necessary to find address of router, that is connected to user.

    This sounds like you might interested in the super-simplistic home-user-attached-to-an-internet-router scenario (even that scenario gets complicated if, for example, they're using a VPN for work). In that case, depending on what you're trying to achieve, you might consider using a discovery protocol, like ICMP (or DLNA?) to detect the home router instead? At least that would not be platform dependant.

    Good luck! :)



  • @Paul-Colby
    thanks for answer)

    Realy, i need programm to automatically detected router address for different platform.
    i found IRD Protocol, but how use it? :D
    can you help me?)


  • Qt Champions 2016

    @Paul-Colby said:

    like ICMP (or DLNA?) to detect the home router instead? At least that would not be platform dependant.

    I can't see how this wouldn't be platform dependent. How do you compose ICMP message without platform specific API?



  • @kshegunov said:

    I can't see how this wouldn't be platform dependent. How do you compose ICMP message without platform specific API?

    Oh, sorry. Yeah, you're right. I was (mistakenly) assuming that ICMP was on top of UDP, which Qt can handle natively. But since ICMP is actually a lower level protocol, it would indeed require platform-dependent code.

    Cheers.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.