Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9082371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:32:34+00:00 2026-06-16T20:32:34+00:00

ip=ntohl(*(uint32_t*)PQgetvalue(result, i, 0)); What is the meaning of this code segment? My guess is

  • 0
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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T20:32:36+00:00Added an answer on June 16, 2026 at 8:32 pm

    According to the docs:

    For most queries, the value returned by PQgetvalue is a null-terminated ASCII
    string representation of the attribute value. But if PQbinaryTuples() is TRUE,
    the value returned by PQgetvalue is the binary representation of the type 
    in the internal format of the backend server
    

    I guess PQbinaryTuples is true there.

    PQGetvalue() returns a char * as per the docs. (uint32_t *) will turn that char * 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 finally ntohl will 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:

    // Get value from database as a char *
    char *in_database = PQgetvalue(result, i, 0);
    // Convert the pointer to char to a pointer to an unsigned, 32bit integer
    uint32_t *ptr = (uint32_t *) in_database;
    // Dereference that pointer to obtain the actually stored value
    uint32_t stored_value = *ptr;
    // Turn that value to a native integer for the CPU
    uint32_t ip = ntohl(stored_value);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got all of this code from the beej guide so all of the
ntohl takes a uint32_t . I have messages with many different members (of type
I get which client send message to server with this code; recvfrom(s, buf, BUFLEN,
I am getting this warning: cast to pointer from integer of different size when
I will use this code as an example: typedef struct __attribute__((aligned(XXX),packed)) { uint16_t type;
so I'm getting this warning: initialization makes integer from pointer without a cast in
Not sure how else to put that, but I'll start off with a code
Im trying to change from big endian to little endian on a double. One
I am writing a Wireshark dissector plugin for a protocol that does not hton
I'm trying to extract tcp payload from a packet , and here's a minimal

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.