ip=ntohl(*(uint32_t*)PQgetvalue(result, i, 0));
What is the meaning of this code segment?
My guess is that this code takes an input from PostgreSQL database (its type is uint32_t) and converts it to IP format (e.g. 192.168.x.x)
Is my guess correct? If not, what does it mean?
Note: According to http://linux.die.net/man/3/ntohl:
The
ntohl()function converts the unsigned integer netlong from network byte order to host byte order.
Also, could somebody explain what *(uint32_t*) does?
According to the docs:
I guess
PQbinaryTuplesis true there.PQGetvalue()returns achar *as per the docs.(uint32_t *)will turn thatchar *into a pointer to an unsinged 32 bit integer, the*before that will dereference this to get the actual value (an unsigned, 32bit integer), and finallyntohlwill convert that into a native 32bit integer for the platform, which presumably means that the original storing format is in network order.If we were to “split” that code, that would give: