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

  • SEARCH
  • Home
  • 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 8414953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:18:16+00:00 2026-06-10T01:18:16+00:00

if i call to function like inet_ntoa that return char*. Who is responsible to

  • 0

if i call to function like inet_ntoa that return char*.
Who is responsible to free the allocated memory?

My method look like this:

char* inet_aton_(unsigned int atonIp){
    in_addr sin_addr;
    sin_addr.s_addr = atonIp;
    return inet_ntoa(sin_addr);
}
  • 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-10T01:18:17+00:00Added an answer on June 10, 2026 at 1:18 am

    You should check the manual for that.

    $man inet_ntoa

    …
    The inet_ntoa() function converts the Internet host address in, given
    in network byte order, to a string in IPv4 dotted-decimal notation.
    The string is returned in a statically allocated buffer, which subse‐
    quent calls will overwrite.

    This means in your application you’ll have a statically allocated buffer, and you are responsible for what’s in there. Each call to inet_ntoa() in your application will override this area. If you need to keep for example two addresses you have to copy this data to another buffer. You are also responsible for using in a correct way in a threaded application, for example if you have two threads calling inet_ntoa at the same time you’ll either get wrong results or two seperate calls to inet_ntoa with different parameters will return the same result.

    You should also look into source code when you have this kind of questions. For example if you search for “inet_ntoa source”. You may encounter some examples; freebsd or ms. One example implementation is below (from freebsd).

    char *
    inet_ntoa(struct in_addr ina)
    {
        static char buf[4*sizeof "123"];
        unsigned char *ucp = (unsigned char *)&ina;
    
        sprintf(buf, "%d.%d.%d.%d",
            ucp[0] & 0xff,
            ucp[1] & 0xff,
            ucp[2] & 0xff,
            ucp[3] & 0xff);
        return buf;
    }
    

    As you can see it has a statically buffer allocated only for this purpose. This makes usage of inet_ntoa very easy since you don’t need to manage the buffer but also makes it not thread safe.

    Another thing, inet_ntoa is not a system call. It can be called a convenience function provided by inet library.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I call a function like this: call_facebook(103138046395999, samåkning.se, http://www.facebook.com/samakning, page); call_facebook(16089699074, Jag ska köra
In some classes I see a call to a function is like: $this->ClearError(); When
I currently call a function to filter some HTML in PHP like this FilterHTML($string)
I would like to have a function that can wrap any other function call.
Is it possible to call function-like-macros with less that all the parameters in linux?
Why when I call a function like this : function(request, **form.cleaned_data) I can send
function myfunction() { window.setTimeout(alert('I waited for you.'),700000000); } I call a function like this
How can I call a function like this with parameters applied to it? searchTimer
my problem is that I want to call a function like: $('div').doSomething('xyz'); and my
Why is it that if I call a seemingly synchronous Windows function like MessageBox()

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.