if I make a system call, say
struct hostent * gethostbyaddr (const char *addr, int len, int family );
and it returns a struct*, do i need to copy the struct to somewhere I “own” instead of using the pointer directly?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
The documentation of
gethostbyaddrreads (see Notes section):It means that you need to copy the struct if you want to be sure that it won’t be overwritten by subsequent calls to
gethostbyaddr.But you really need to consider using
getaddrinfosincegethostbyaddris obsolete. Withgetaddrinfoyou will not be asking this question because you’ll need to allocate memory for the result yourself.