none
How to know through which network interface ip address is pinged? RRS feed

  • Question

  • Hi,

    I am progrmmatically pininging ip address using c++ in windows.

    I used the code from this link for pinging https://www.codeproject.com/Articles/647/Ping-for-Windows

    I am receiving reply from this function

    WSAAPI
    recvfrom(
        SOCKET s,
        char FAR * buf,
         int len,
        int flags,
        struct sockaddr FAR * from,
       int FAR * fromlen
        );

    From this function, How to know through which network interface I am receiving the reply or able to ping?

    Thanks.

    Friday, August 23, 2019 10:48 AM

All replies

  • How would you identify "network interface"?  What would you do with that information if you had it?

    Remember, you pinged a specific IP address, so your ping went OUT that interface.  You can use the routing tables to figure out which interface will be handling a given IP, but again I'm wondering what you'll do with that information.


    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Friday, August 23, 2019 8:44 PM
  • How would you identify "network interface"?  What would you do with that information if you had it?

    Remember, you pinged a specific IP address, so your ping went OUT that interface.  You can use the routing tables to figure out which interface will be handling a given IP, but again I'm wondering what you'll do with that information.


    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Hi,

    I need that information to use specific network intreface for a socket connection at client side.

    I dont know how to use the routing tables to figure out which interface will be handling a given IP for pinging.



    • Edited by sgrm123 Sunday, August 25, 2019 6:55 AM
    Sunday, August 25, 2019 6:54 AM
  • I need that information to use specific network intreface for a socket connection at client side.

    I'm sorry, but that doesn't make any sense.  You had to create a socket connection to do the ping to this host.  You can use the exact same process to create a socket for other types of communication to that same host.  You don't need to know the network interface.  The system will figure that out for you.

    What is your real goal here?  Are you just trying to set up a TCP connection to a host?


    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Sunday, August 25, 2019 6:46 PM