Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Receive UDP packet from multiple default gateway

Receive UDP packet from multiple default gateway

Scheduled Pinned Locked Moved C / C++ / MFC
c++sysadmin
7 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Shanky4
    wrote on last edited by
    #1

    Hi,

    I am writing an application to receive a data from adapter. Adapter is brodcasting UDP data.
    So in my case I have two adapter which is connected to same router having following IP information -

    1. Adapter 1 :-
      IP : 192.168.1.32
      Default Gateway : 192.168.1.1
      Subnet Mask : 255.255.255.0
    2. Adapter 2 :-
      IP : 192.168.4.33
      Default Gateway : 192.168.4.1
      Subnet Mask : 255.255.255.0

    Here is the router detail :

    Default Gateway : 192.168.1.1
    Subnet Mask : 255.255.255.0

    PC is also connected to same router.
    Application written in C++ is configure to receive data from any IP address.
    m_nFamily = AF_INET;
    m_nType = SOCK_DGRAM;
    m_nProtocol = IPPROTO_UDP;
    m_SockAddr.sin_addr.s_addr = INADDR_ANY;
    m_SockAddr.sin_family = AF_INET;

    In my case I can receive data coming from Adapter 1 but can not receive data coming from Adapter 2.
    But the data coming from both the adapter I can see in Wireshark.

    Work around to receive data from Adapter 2 : To receive data from adapter 2, I need to change the wireless network connection property for IPV4 and need to change "obtain IP address automatically" to "Use the following address":
    Used following data to configure manually :
    IP : 192.168.4.31
    Default Gateway : 192.168.4.1
    Subnet Mask : 255.255.255.0

    But after doing this application don't see the message coming from adapter 1.
    But the data from both the adapter can be seen in wireshark.

    My goal is to receive data from both the adapter simultaneously.

    L J 2 Replies Last reply
    0
    • S Shanky4

      Hi,

      I am writing an application to receive a data from adapter. Adapter is brodcasting UDP data.
      So in my case I have two adapter which is connected to same router having following IP information -

      1. Adapter 1 :-
        IP : 192.168.1.32
        Default Gateway : 192.168.1.1
        Subnet Mask : 255.255.255.0
      2. Adapter 2 :-
        IP : 192.168.4.33
        Default Gateway : 192.168.4.1
        Subnet Mask : 255.255.255.0

      Here is the router detail :

      Default Gateway : 192.168.1.1
      Subnet Mask : 255.255.255.0

      PC is also connected to same router.
      Application written in C++ is configure to receive data from any IP address.
      m_nFamily = AF_INET;
      m_nType = SOCK_DGRAM;
      m_nProtocol = IPPROTO_UDP;
      m_SockAddr.sin_addr.s_addr = INADDR_ANY;
      m_SockAddr.sin_family = AF_INET;

      In my case I can receive data coming from Adapter 1 but can not receive data coming from Adapter 2.
      But the data coming from both the adapter I can see in Wireshark.

      Work around to receive data from Adapter 2 : To receive data from adapter 2, I need to change the wireless network connection property for IPV4 and need to change "obtain IP address automatically" to "Use the following address":
      Used following data to configure manually :
      IP : 192.168.4.31
      Default Gateway : 192.168.4.1
      Subnet Mask : 255.255.255.0

      But after doing this application don't see the message coming from adapter 1.
      But the data from both the adapter can be seen in wireshark.

      My goal is to receive data from both the adapter simultaneously.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Have you tried binding your socket to the specific IP addresses?

      S 1 Reply Last reply
      0
      • L Lost User

        Have you tried binding your socket to the specific IP addresses?

        S Offline
        S Offline
        Shanky4
        wrote on last edited by
        #3

        Thanks for going through it. I did not try to bind the socket with specific IP address. Also this is not a requirement for me. I will give a try just to verify if it is possible but my intention is to receive data from all the adapter connected to same netwoek(router). Earlier I am using DHCP so that time it was not a problem for me cause all the adapter was getting the same default gateway but now I am switching to static where user can put any IP address with different default gateway.

        S 1 Reply Last reply
        0
        • S Shanky4

          Thanks for going through it. I did not try to bind the socket with specific IP address. Also this is not a requirement for me. I will give a try just to verify if it is possible but my intention is to receive data from all the adapter connected to same netwoek(router). Earlier I am using DHCP so that time it was not a problem for me cause all the adapter was getting the same default gateway but now I am switching to static where user can put any IP address with different default gateway.

          S Offline
          S Offline
          Shanky4
          wrote on last edited by
          #4

          Also as I can see the data in wireshark, looks like PC is receiving this data but it is not reaching to application

          L 1 Reply Last reply
          0
          • S Shanky4

            Also as I can see the data in wireshark, looks like PC is receiving this data but it is not reaching to application

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            You will receive messages on the socket that you have created, which will bind to the first adapter. If you wish to receive on both then you need two sockets one bound to each IP address.

            1 Reply Last reply
            0
            • S Shanky4

              Hi,

              I am writing an application to receive a data from adapter. Adapter is brodcasting UDP data.
              So in my case I have two adapter which is connected to same router having following IP information -

              1. Adapter 1 :-
                IP : 192.168.1.32
                Default Gateway : 192.168.1.1
                Subnet Mask : 255.255.255.0
              2. Adapter 2 :-
                IP : 192.168.4.33
                Default Gateway : 192.168.4.1
                Subnet Mask : 255.255.255.0

              Here is the router detail :

              Default Gateway : 192.168.1.1
              Subnet Mask : 255.255.255.0

              PC is also connected to same router.
              Application written in C++ is configure to receive data from any IP address.
              m_nFamily = AF_INET;
              m_nType = SOCK_DGRAM;
              m_nProtocol = IPPROTO_UDP;
              m_SockAddr.sin_addr.s_addr = INADDR_ANY;
              m_SockAddr.sin_family = AF_INET;

              In my case I can receive data coming from Adapter 1 but can not receive data coming from Adapter 2.
              But the data coming from both the adapter I can see in Wireshark.

              Work around to receive data from Adapter 2 : To receive data from adapter 2, I need to change the wireless network connection property for IPV4 and need to change "obtain IP address automatically" to "Use the following address":
              Used following data to configure manually :
              IP : 192.168.4.31
              Default Gateway : 192.168.4.1
              Subnet Mask : 255.255.255.0

              But after doing this application don't see the message coming from adapter 1.
              But the data from both the adapter can be seen in wireshark.

              My goal is to receive data from both the adapter simultaneously.

              J Offline
              J Offline
              Jochen Arndt
              wrote on last edited by
              #6

              You may use the SOCK_RAW type to get all packets and not only those that match the network mask of your adapter. Maybe this CP article is helpful: A Little Sniffer that Uses WSA Sockets (Windows Sockets)[^].

              S 1 Reply Last reply
              0
              • J Jochen Arndt

                You may use the SOCK_RAW type to get all packets and not only those that match the network mask of your adapter. Maybe this CP article is helpful: A Little Sniffer that Uses WSA Sockets (Windows Sockets)[^].

                S Offline
                S Offline
                Shanky4
                wrote on last edited by
                #7

                Thanks for your valuable suggestion. I am trying all this, I will update you once I will collect the result.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups