Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6721829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:22:31+00:00 2026-05-26T09:22:31+00:00

My website can be accessed using any of 2 different static IPs (IPv4). Is

  • 0

My website can be accessed using any of 2 different static IPs (IPv4).

Is it possible to open a TCP connection to another server, specifying which of the 2 IPs to use as a return address ?

x.x.x.x (my server) => z.z.z.z (destination server)
y.y.y.y (my server) => z.z.z.z (destination server)

Error-checking, etc. in this example has been omitted for simplicity sakes :

struct addrinfo hints, *result;
hints.ai_flags = 0;
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
hints.ai_addrlen = 0;
hints.ai_canonname = NULL;
hints.ai_addr = NULL;
hints.ai_next = NULL;

getaddrinfo(domain, "80", &hints, &result);

socket(result->ai_family, result->ai_socktype, result->ai_protocol);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:22:32+00:00Added an answer on May 26, 2026 at 9:22 am

    Like @hochl says, you use the bind system call:

    struct sockaddr_in sin = { 0 };
    int sock;
    
    /* Create a socket address, with a specific port and (local) ipnumber */
    sin.sin_family = AF_INET;
    sin.sin_port = htons(80);
    inet_aton("1.2.3.4", &sin.sin_addr);
    
    /* Create socket */
    sock = socket(AF_INET, SOCK_STREAM, 0);
    
    /* Bind socket to the local address */
    bind(sock, (struct sockaddr *) &sin, sizeof(sin));
    
    /* Now connect to remote server... */
    /* connect(...) */
    

    It should be noted that use of inet_aton is normally discouraged, in favor of inet_pton.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a website I can create an HTML final four bracket? Or is
On my website users can keyword search and find desired results. (Just a simple
hii I want attractive buttons for my website how can i do that
With LINQ to SQL in a ASP.NET MVC website I can display objects (records)
I am trying to implement an internal search for my website that can point
How can MVC website benefit from the new parallelism features in .net 4? don't
can anyone recommend a website crawler that can show me all of the links
how can I save a java applet from a website so I can run
I run a website where users can post items (e.g. pictures). The items are
I have a website where people can upload documents, and view them later at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.