How to get ipv6 address in C language
It is impossible to get an ipv6 address by using the usual method of getting the IP address of ipv4. This article introduces three methods for getting the ipv6 address using the C language. Each method provides the complete source code. All examples in this article are tested under ubuntu 20.04, gcc version 9.4.0. 1. How to get the IP address of ipv4 Whether to get an IP address for ipv4 or an address for ipv6, the application needs to communicate with the kernel. ioctl is a common method for communicating with the kernel, and is also a common method for getting the IP address of ipv4. The following code demonstrates how to use ioctl to get the IP addresses of all interfaces on the computer: But using ioctl can't get ipv6 address. Even if we create an AF_INET6 socket, the ioctl still only returns ipv4 information. We can try the following code. The result of running this code on my computer looks like this: Figure 1: ioctl cannot get ipv6 address We see that no matter wha...