2004.09.07, Tue - inet

xiaoxiao2021-03-06  43

CHAR FAR * inet_ntoa (struct in_addr in); this function can convert the IPv4 address data into a string.

Looking at this function, I always feel some awkward. I want to return to the form of a string for a general Win32 API. It should be similar to this:

Returntype SomeFunction (LPTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTER] I wrote the following code for testing:

Struct in_addr ip; ip.s_un.s_addr = 0x12345678; Char * Str = INET_NTOA (IP); MessageBox (NULL, STR, "IP", 0); IP.S_UN.S_ADDR = 0x87654321; INET_NTOA (IP); MessageBox (null , STR, "IP", 0); the result of the execution is the content of the memory space points to the STR. In this way, the implementation of this function should be this:

Char far * inet_ntoa (struct in_addr in) {static char strret [16]; // ... return strret;} Honor said that this code is not scientific enough, the coupling of external code is not very good, and waste memory .

转载请注明原文地址:https://www.9cbs.com/read-119417.html

New Post(0)