How to make an outgtoing TCP connection through specified netwrok interface?












0















Is there a way to implement in C program a next feature: it's need to making outgoing TCP connections through specified network interface? as example:



eth0 - 172.16.0.1
eth1 - 192.168.1.1



In some case I'm need to make outgoing connections from source address 172.16.0.1, and under some other circumstances from 192.168.1.1.



Is this possible ?
Is this can be achieved with bind() routine?



TIA.










share|improve this question























  • Maybe stackoverflow.com/q/14478167/5830574

    – PerlDuck
    Feb 17 at 10:23











  • Thanks, useful topic. But I'm don't need to bind a listening socket but socket for outgoing connection.

    – Ruslan R. Laishev
    Feb 17 at 10:45











  • Doesn't make a difference. See stackoverflow.com/q/335607/5830574 They also suggest setsockopt().

    – PerlDuck
    Feb 17 at 10:54











  • Ok. Thanks again. I just will check it with test code ...

    – Ruslan R. Laishev
    Feb 17 at 11:06











  • setsockopt(#3, SO_BINDTODEVICE, enp0s3:1)->19 - it;s looks like that BINDTODEV is no works for the pseudo-interfaces.

    – Ruslan R. Laishev
    Feb 17 at 12:07


















0















Is there a way to implement in C program a next feature: it's need to making outgoing TCP connections through specified network interface? as example:



eth0 - 172.16.0.1
eth1 - 192.168.1.1



In some case I'm need to make outgoing connections from source address 172.16.0.1, and under some other circumstances from 192.168.1.1.



Is this possible ?
Is this can be achieved with bind() routine?



TIA.










share|improve this question























  • Maybe stackoverflow.com/q/14478167/5830574

    – PerlDuck
    Feb 17 at 10:23











  • Thanks, useful topic. But I'm don't need to bind a listening socket but socket for outgoing connection.

    – Ruslan R. Laishev
    Feb 17 at 10:45











  • Doesn't make a difference. See stackoverflow.com/q/335607/5830574 They also suggest setsockopt().

    – PerlDuck
    Feb 17 at 10:54











  • Ok. Thanks again. I just will check it with test code ...

    – Ruslan R. Laishev
    Feb 17 at 11:06











  • setsockopt(#3, SO_BINDTODEVICE, enp0s3:1)->19 - it;s looks like that BINDTODEV is no works for the pseudo-interfaces.

    – Ruslan R. Laishev
    Feb 17 at 12:07
















0












0








0


1






Is there a way to implement in C program a next feature: it's need to making outgoing TCP connections through specified network interface? as example:



eth0 - 172.16.0.1
eth1 - 192.168.1.1



In some case I'm need to make outgoing connections from source address 172.16.0.1, and under some other circumstances from 192.168.1.1.



Is this possible ?
Is this can be achieved with bind() routine?



TIA.










share|improve this question














Is there a way to implement in C program a next feature: it's need to making outgoing TCP connections through specified network interface? as example:



eth0 - 172.16.0.1
eth1 - 192.168.1.1



In some case I'm need to make outgoing connections from source address 172.16.0.1, and under some other circumstances from 192.168.1.1.



Is this possible ?
Is this can be achieved with bind() routine?



TIA.







networking sockets tcp-ip






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Feb 17 at 9:34









Ruslan R. LaishevRuslan R. Laishev

13




13













  • Maybe stackoverflow.com/q/14478167/5830574

    – PerlDuck
    Feb 17 at 10:23











  • Thanks, useful topic. But I'm don't need to bind a listening socket but socket for outgoing connection.

    – Ruslan R. Laishev
    Feb 17 at 10:45











  • Doesn't make a difference. See stackoverflow.com/q/335607/5830574 They also suggest setsockopt().

    – PerlDuck
    Feb 17 at 10:54











  • Ok. Thanks again. I just will check it with test code ...

    – Ruslan R. Laishev
    Feb 17 at 11:06











  • setsockopt(#3, SO_BINDTODEVICE, enp0s3:1)->19 - it;s looks like that BINDTODEV is no works for the pseudo-interfaces.

    – Ruslan R. Laishev
    Feb 17 at 12:07





















  • Maybe stackoverflow.com/q/14478167/5830574

    – PerlDuck
    Feb 17 at 10:23











  • Thanks, useful topic. But I'm don't need to bind a listening socket but socket for outgoing connection.

    – Ruslan R. Laishev
    Feb 17 at 10:45











  • Doesn't make a difference. See stackoverflow.com/q/335607/5830574 They also suggest setsockopt().

    – PerlDuck
    Feb 17 at 10:54











  • Ok. Thanks again. I just will check it with test code ...

    – Ruslan R. Laishev
    Feb 17 at 11:06











  • setsockopt(#3, SO_BINDTODEVICE, enp0s3:1)->19 - it;s looks like that BINDTODEV is no works for the pseudo-interfaces.

    – Ruslan R. Laishev
    Feb 17 at 12:07



















Maybe stackoverflow.com/q/14478167/5830574

– PerlDuck
Feb 17 at 10:23





Maybe stackoverflow.com/q/14478167/5830574

– PerlDuck
Feb 17 at 10:23













Thanks, useful topic. But I'm don't need to bind a listening socket but socket for outgoing connection.

– Ruslan R. Laishev
Feb 17 at 10:45





Thanks, useful topic. But I'm don't need to bind a listening socket but socket for outgoing connection.

– Ruslan R. Laishev
Feb 17 at 10:45













Doesn't make a difference. See stackoverflow.com/q/335607/5830574 They also suggest setsockopt().

– PerlDuck
Feb 17 at 10:54





Doesn't make a difference. See stackoverflow.com/q/335607/5830574 They also suggest setsockopt().

– PerlDuck
Feb 17 at 10:54













Ok. Thanks again. I just will check it with test code ...

– Ruslan R. Laishev
Feb 17 at 11:06





Ok. Thanks again. I just will check it with test code ...

– Ruslan R. Laishev
Feb 17 at 11:06













setsockopt(#3, SO_BINDTODEVICE, enp0s3:1)->19 - it;s looks like that BINDTODEV is no works for the pseudo-interfaces.

– Ruslan R. Laishev
Feb 17 at 12:07







setsockopt(#3, SO_BINDTODEVICE, enp0s3:1)->19 - it;s looks like that BINDTODEV is no works for the pseudo-interfaces.

– Ruslan R. Laishev
Feb 17 at 12:07












0






active

oldest

votes











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
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%2faskubuntu.com%2fquestions%2f1118926%2fhow-to-make-an-outgtoing-tcp-connection-through-specified-netwrok-interface%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Ask Ubuntu!


  • 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%2faskubuntu.com%2fquestions%2f1118926%2fhow-to-make-an-outgtoing-tcp-connection-through-specified-netwrok-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

How to make a Squid Proxy server?

Is this a new Fibonacci Identity?

19世紀