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 1958574
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T08:21:43+00:00 2026-05-17T08:21:43+00:00

I am writing a C library which involves telling other computers on the subnet

  • 0

I am writing a C library which involves telling other computers on the subnet to send me messages. Therefore I must announce to them my IP address. This library should work on Linux, OS X and Windows. Currently I’m thinking mostly about the POSIX layer.

Given that a computer can have more than one address (for example if it has more than one network interface),

  1. What’s the best way to find my default IP address (e.g. in the simplest most common case of a computer with a single connection to the subnet.) Currently I’m cycling through the system NICs using getifaddrs and returning the first one that is associated (with preference to non-loopback), but I think this is probably not adequate.

  2. What would be a good API for allowing users of the library to choose which interface to send on? I assume some sort of enumeration of the NICs and IPs of the computer, then selecting the NIC by name and finding its IP. This seems pretty complicated from a user standpoint though. Perhaps some way to determine the system’s route to the subnet by netmask, given the IP of another computer on the subnet? I have little idea how to do that, though.

For 2, we can eventually assume there may be a GUI or command-line option allowing users to choose the NIC, but in general I want to make it as easy as possible for it to automatically tell other computers how to direct UDP messages to it.

Any opinions appreciated, thanks!

  • 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-17T08:21:43+00:00Added an answer on May 17, 2026 at 8:21 am

    If you’re already communicating with other computers using IP, the packets will already be announcing a return address that the far end can use to determine where its messages should go.

    Attempting to deduce the right interface address to use and embedding it in a message isn’t a good idea for four reasons (probably more). First, you’re going to end up reimplementing all of the logic your OS does to figure out how to route outbound packets. Second, if the routing table changes between the time you make that decision and the time you actually need to connect to the other computers and tell them where to send traffic, you’ll be sending them the wrong address. Third, the destination computers may not always be on the same subnet, in which case none of the interfaces will match. Fourth, if the packets undergo any form of rewriting (e.g., NAT) between you and the destination, the software doing it will have no idea that it needs to dive into your packets and the systems at the far end won’t be using the right address.

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

Sidebar

Related Questions

I am writing a library in standard C++ which does the phonetic conversion. I
Let's say that I'm writing a library in C# and I don't know who
I am writing a C library that reads a file into memory. It skips
I am writing a .NET library that for various reasons cannot be registered in
I'm learning C# by writing a home library manager. I have a BookController that
Writing something like this using the loki library , typedef Functor<void> BitButtonPushHandler; throws a
I'm writing a C++ static library that needs to be shared among several applications,
I am writing a small matrix library in C++ for matrix operations. However, my
I'm writing some data acquisition software and need a gui plotting library that is
I'm writing a small and inadequate linear algebra library in C++ for a project

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.