Posts

How to get ipv6 address in C language

Image
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...

Parameter passing mechanism of function call in C language

Image
The X86 instruction set started with the 16-bit 8086 and has experienced more than 40 years of development. The 64-bit X86-64 instruction set is now widely used. The registers have also changed from the previous 16-bit to the current 64-bit. The number of registers is also greatly increased. Of course gcc must also be constantly upgraded as the instruction set changes. In the 64-bit era, the parameter passing of C language in function calls has also undergone great changes. This article verifies this change by compiling C language programs into assembly language. Reading this article requires not only knowledge of C language, but also some knowledge of assembly language. All examples in this article are verified under Ubuntu 20.04, and the gcc version used is 9.4.0. 1. Parameter passing for calling functions in C language under 32-bit. In the 32-bit era, C language actually used the stack to pass parameters when calling functions. Before executing the call instruction, the parameters t...

Remote Boot: A simple embedded project development

Image
This article describes how to develop a program on an ARM device to power on a server remotely. It roughly introduces the development process of a simple embedded project through this example. It will not detail the principle of wake-on-lan and Magic Packet. 1. Overview This article introduces the development process of a simple embedded project. From requirements to practice, this article provides a comprehensive introduction to the entire process, and the equipment described in this article is easy to obtain and inexpensive. This article deals with the concepts of network programming under the C language of Linux, such as network broadcast, Magic Packet, NAT and reverse proxy. Readers can refer to other articles for some of the technical concepts covered in this article. This article may not be for beginners. 2. Requirement I have a server at home. Almost all my things are stored on this server. Whether at home or elsewhere, I need to connect to this server to do things. The server i...