| |

VerySource

 Forgot password?
 Register
Search
View: 711|Reply: 2

Obtaining the local IP address (urgent)

[Copy link]

4

Threads

7

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-3-14 14:00:01
| Show all posts |Read mode
I would like to ask how to get the local IP address in the form of IPv6, I have already installed IPv6.
I wrote some, but it's definitely wrong, please help me change it.
char hostname [128] = {0};
struct hostent * inaddrs;
string m_strSourceAddr;
if (gethostname (hostname, 128) == 0)
{
inaddrs = gethostbyname (hostname);
}
m_strSourceAddr = inaddrs-> h_addr_list [0];
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-7-28 15:00:01
| Show all posts
What you wrote seems to be wrong, I suggest you check the information, such as struct sockaddr_in6 {
short sin6_family;
u_short sin6_port;
u_long sin6_flowinfo;
struct in6_addr sin6_addr;
u_long sin6_scope_id;
};
There is also the getnameinfo function. I have not written
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-7-29 12:45:01
| Show all posts
The function you used is wrong, getaddrinfo(xxx)

Check out the introduction on msnd.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list