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

  • Home
  • SEARCH
  • 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 5846643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:36:21+00:00 2026-05-22T12:36:21+00:00

I am working on implementing UpNP on C++, and I need to get the

  • 0

I am working on implementing UpNP on C++, and I need to get the local internal IP address assigned by the router to make the sockets works. The address I need is the one that appears on routers where it shows the computers connected to the router and the local IP assigned to each computer. I am using this:

PHOSTENT      Addr    = NULL;
char          Host[MAX_PATH];

if( gethostname(Host, sizeof(Host)) == 0 )
{
    Address = gethostbyname( Host );
    if( Address != NULL )
    {
        //*(struct in_addr *)Address->h_addr_list[0]) <- this is my address
    }
}

This works fine on the computer I am testing, but that computer has only one network card, so I was wondering if maybe when a computer has more than one card or network device, Address->h_addr_list[0] may not be the one I need and it could be in another index of that array.

Will [0] always retrieve the IP assigned by the router?

  • 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-22T12:36:21+00:00Added an answer on May 22, 2026 at 12:36 pm

    (Assuming winsock here, as per previous question)

    You shouldn’t assume that the first address is the correct one (as there may be multiple interfaces, and more than one may be active)

    I’d recommend enumerating addresses using either getaddrinfo with an empty pNodeName argument, or GetAdaptersAddresses.

    Both of these return a linked lists with your system’s registered addresses

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

Sidebar

Related Questions

I'm currently working on implementing Lua into one of the applications that I'm working
I am working on implementing a custom membership provider that works against an existing
I am working on implementing Zend Framework within an existing project that has a
I'm currently working on implementing a list-type structure at work, and I need it
I'm working on implementing a way to allow HTML in a field that I
I am working on implementing a function that would execute another function a few
I am working on implementing a JavaScript web bug that will be inserted into
I'm working on a implementing a SNMP into a GWT project. I need to
I've been working on implementing a pretty complex system in JavaScript that needs to
I am working on implementing the MSNP15 protocol in Python. I have verified that

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.