Boost asio socket multicast send data with a specific ethernet interface












-1















boost::asio::ip::address_v4 local_interface = 
boost::asio::ip::address_v4::from_string(ip);
boost::asio::ip::multicast::outbound_interface option(local_interface);
sock.set_option(option); //set interface


It does not work! I used wireshark to capture data, but the data source interface is not the local_interface, why??? and How to make it working?










share|improve this question























  • struct in_addr interface_addr; interface_addr.S_un.S_addr = inet_addr(ip.c_str()); if (-1 == setsockopt(sock.native_handle(), IPPROTO_IP, IP_MULTICAST_IF, (char*)&interface_addr, sizeof(interface_addr))) { LOG_INFO("setsockopt IP_MULTICAST_IF error!"); }

    – Eric Xu
    Nov 22 '18 at 7:51











  • set IP_MULTICAST_IF also invalid!

    – Eric Xu
    Nov 22 '18 at 7:52











  • Can you please provide MCVE? Not sure what you are trying to achieve.

    – karastojko
    Nov 22 '18 at 7:53











  • io_service io; ip::udp::socket sock(io); ip::udp::endpoint endpoint_group(ip::address::from_string(group_ip), port); sock.open(ip::udp::v4()); sock.set_option(boost::asio::socket_base::send_buffer_size(1024*1024)); sock.set_option(ip::multicast::enable_loopback(false)); sock.set_option(ip::multicast::outbound_interface(ip::address::from_string(ip).to_v4()));

    – Eric Xu
    Nov 22 '18 at 11:46











  • I have two computers, both have 2 network cards. I set the specific interface on one success, the other is invalid. but my friend used libuv library to set on the host success. The libuv inside use setsockopt set IP_MULTICAST_IF. I use setsockopt ,but failed! I suspect there's something wrong with the system?

    – Eric Xu
    Nov 22 '18 at 11:54


















-1















boost::asio::ip::address_v4 local_interface = 
boost::asio::ip::address_v4::from_string(ip);
boost::asio::ip::multicast::outbound_interface option(local_interface);
sock.set_option(option); //set interface


It does not work! I used wireshark to capture data, but the data source interface is not the local_interface, why??? and How to make it working?










share|improve this question























  • struct in_addr interface_addr; interface_addr.S_un.S_addr = inet_addr(ip.c_str()); if (-1 == setsockopt(sock.native_handle(), IPPROTO_IP, IP_MULTICAST_IF, (char*)&interface_addr, sizeof(interface_addr))) { LOG_INFO("setsockopt IP_MULTICAST_IF error!"); }

    – Eric Xu
    Nov 22 '18 at 7:51











  • set IP_MULTICAST_IF also invalid!

    – Eric Xu
    Nov 22 '18 at 7:52











  • Can you please provide MCVE? Not sure what you are trying to achieve.

    – karastojko
    Nov 22 '18 at 7:53











  • io_service io; ip::udp::socket sock(io); ip::udp::endpoint endpoint_group(ip::address::from_string(group_ip), port); sock.open(ip::udp::v4()); sock.set_option(boost::asio::socket_base::send_buffer_size(1024*1024)); sock.set_option(ip::multicast::enable_loopback(false)); sock.set_option(ip::multicast::outbound_interface(ip::address::from_string(ip).to_v4()));

    – Eric Xu
    Nov 22 '18 at 11:46











  • I have two computers, both have 2 network cards. I set the specific interface on one success, the other is invalid. but my friend used libuv library to set on the host success. The libuv inside use setsockopt set IP_MULTICAST_IF. I use setsockopt ,but failed! I suspect there's something wrong with the system?

    – Eric Xu
    Nov 22 '18 at 11:54
















-1












-1








-1


0






boost::asio::ip::address_v4 local_interface = 
boost::asio::ip::address_v4::from_string(ip);
boost::asio::ip::multicast::outbound_interface option(local_interface);
sock.set_option(option); //set interface


It does not work! I used wireshark to capture data, but the data source interface is not the local_interface, why??? and How to make it working?










share|improve this question














boost::asio::ip::address_v4 local_interface = 
boost::asio::ip::address_v4::from_string(ip);
boost::asio::ip::multicast::outbound_interface option(local_interface);
sock.set_option(option); //set interface


It does not work! I used wireshark to capture data, but the data source interface is not the local_interface, why??? and How to make it working?







c++ boost multicast asio






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 '18 at 6:15









Eric XuEric Xu

243




243













  • struct in_addr interface_addr; interface_addr.S_un.S_addr = inet_addr(ip.c_str()); if (-1 == setsockopt(sock.native_handle(), IPPROTO_IP, IP_MULTICAST_IF, (char*)&interface_addr, sizeof(interface_addr))) { LOG_INFO("setsockopt IP_MULTICAST_IF error!"); }

    – Eric Xu
    Nov 22 '18 at 7:51











  • set IP_MULTICAST_IF also invalid!

    – Eric Xu
    Nov 22 '18 at 7:52











  • Can you please provide MCVE? Not sure what you are trying to achieve.

    – karastojko
    Nov 22 '18 at 7:53











  • io_service io; ip::udp::socket sock(io); ip::udp::endpoint endpoint_group(ip::address::from_string(group_ip), port); sock.open(ip::udp::v4()); sock.set_option(boost::asio::socket_base::send_buffer_size(1024*1024)); sock.set_option(ip::multicast::enable_loopback(false)); sock.set_option(ip::multicast::outbound_interface(ip::address::from_string(ip).to_v4()));

    – Eric Xu
    Nov 22 '18 at 11:46











  • I have two computers, both have 2 network cards. I set the specific interface on one success, the other is invalid. but my friend used libuv library to set on the host success. The libuv inside use setsockopt set IP_MULTICAST_IF. I use setsockopt ,but failed! I suspect there's something wrong with the system?

    – Eric Xu
    Nov 22 '18 at 11:54





















  • struct in_addr interface_addr; interface_addr.S_un.S_addr = inet_addr(ip.c_str()); if (-1 == setsockopt(sock.native_handle(), IPPROTO_IP, IP_MULTICAST_IF, (char*)&interface_addr, sizeof(interface_addr))) { LOG_INFO("setsockopt IP_MULTICAST_IF error!"); }

    – Eric Xu
    Nov 22 '18 at 7:51











  • set IP_MULTICAST_IF also invalid!

    – Eric Xu
    Nov 22 '18 at 7:52











  • Can you please provide MCVE? Not sure what you are trying to achieve.

    – karastojko
    Nov 22 '18 at 7:53











  • io_service io; ip::udp::socket sock(io); ip::udp::endpoint endpoint_group(ip::address::from_string(group_ip), port); sock.open(ip::udp::v4()); sock.set_option(boost::asio::socket_base::send_buffer_size(1024*1024)); sock.set_option(ip::multicast::enable_loopback(false)); sock.set_option(ip::multicast::outbound_interface(ip::address::from_string(ip).to_v4()));

    – Eric Xu
    Nov 22 '18 at 11:46











  • I have two computers, both have 2 network cards. I set the specific interface on one success, the other is invalid. but my friend used libuv library to set on the host success. The libuv inside use setsockopt set IP_MULTICAST_IF. I use setsockopt ,but failed! I suspect there's something wrong with the system?

    – Eric Xu
    Nov 22 '18 at 11:54



















struct in_addr interface_addr; interface_addr.S_un.S_addr = inet_addr(ip.c_str()); if (-1 == setsockopt(sock.native_handle(), IPPROTO_IP, IP_MULTICAST_IF, (char*)&interface_addr, sizeof(interface_addr))) { LOG_INFO("setsockopt IP_MULTICAST_IF error!"); }

– Eric Xu
Nov 22 '18 at 7:51





struct in_addr interface_addr; interface_addr.S_un.S_addr = inet_addr(ip.c_str()); if (-1 == setsockopt(sock.native_handle(), IPPROTO_IP, IP_MULTICAST_IF, (char*)&interface_addr, sizeof(interface_addr))) { LOG_INFO("setsockopt IP_MULTICAST_IF error!"); }

– Eric Xu
Nov 22 '18 at 7:51













set IP_MULTICAST_IF also invalid!

– Eric Xu
Nov 22 '18 at 7:52





set IP_MULTICAST_IF also invalid!

– Eric Xu
Nov 22 '18 at 7:52













Can you please provide MCVE? Not sure what you are trying to achieve.

– karastojko
Nov 22 '18 at 7:53





Can you please provide MCVE? Not sure what you are trying to achieve.

– karastojko
Nov 22 '18 at 7:53













io_service io; ip::udp::socket sock(io); ip::udp::endpoint endpoint_group(ip::address::from_string(group_ip), port); sock.open(ip::udp::v4()); sock.set_option(boost::asio::socket_base::send_buffer_size(1024*1024)); sock.set_option(ip::multicast::enable_loopback(false)); sock.set_option(ip::multicast::outbound_interface(ip::address::from_string(ip).to_v4()));

– Eric Xu
Nov 22 '18 at 11:46





io_service io; ip::udp::socket sock(io); ip::udp::endpoint endpoint_group(ip::address::from_string(group_ip), port); sock.open(ip::udp::v4()); sock.set_option(boost::asio::socket_base::send_buffer_size(1024*1024)); sock.set_option(ip::multicast::enable_loopback(false)); sock.set_option(ip::multicast::outbound_interface(ip::address::from_string(ip).to_v4()));

– Eric Xu
Nov 22 '18 at 11:46













I have two computers, both have 2 network cards. I set the specific interface on one success, the other is invalid. but my friend used libuv library to set on the host success. The libuv inside use setsockopt set IP_MULTICAST_IF. I use setsockopt ,but failed! I suspect there's something wrong with the system?

– Eric Xu
Nov 22 '18 at 11:54







I have two computers, both have 2 network cards. I set the specific interface on one success, the other is invalid. but my friend used libuv library to set on the host success. The libuv inside use setsockopt set IP_MULTICAST_IF. I use setsockopt ,but failed! I suspect there's something wrong with the system?

– Eric Xu
Nov 22 '18 at 11:54














1 Answer
1






active

oldest

votes


















0














WSOCK32.DLL WS2_32.DLL both exist in a program. We can set VS project linker input: Ignore specific default libraries(the WSOCK32.DLL).






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53424890%2fboost-asio-socket-multicast-send-data-with-a-specific-ethernet-interface%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    WSOCK32.DLL WS2_32.DLL both exist in a program. We can set VS project linker input: Ignore specific default libraries(the WSOCK32.DLL).






    share|improve this answer




























      0














      WSOCK32.DLL WS2_32.DLL both exist in a program. We can set VS project linker input: Ignore specific default libraries(the WSOCK32.DLL).






      share|improve this answer


























        0












        0








        0







        WSOCK32.DLL WS2_32.DLL both exist in a program. We can set VS project linker input: Ignore specific default libraries(the WSOCK32.DLL).






        share|improve this answer













        WSOCK32.DLL WS2_32.DLL both exist in a program. We can set VS project linker input: Ignore specific default libraries(the WSOCK32.DLL).







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 28 '18 at 7:07









        Eric XuEric Xu

        243




        243
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53424890%2fboost-asio-socket-multicast-send-data-with-a-specific-ethernet-interface%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith