I am a bit confused at least. getaddrinfo() call 'updates' a pointer to a addrinfo struct, all is well when I am going to use the addrinfo in the same scope (that function) but what happens if I copy the struct to another one (by assigning it).
Please help me understand the undergoing basics (not seeking advice for alternative approaches).
Correct me if I am wrong: a) getaddrinfo() requires a pointer to struct-pointer to addrinfo. b) getaddrinfo creates a addrinfo struct in the current function scope and updates the pointer required in a)
Now my real question: i would like to store that addrinfo somewhere else. Using an assigning to an other pointer does not do a deep copy, and after the function all the pointers become invalid?
Better give an extremely simplified example:
void GetAddrInfo(struct addrinfo *update)
{
struct addrinfo *res;
getaddrinfo(xx,xx,xx,&res);
//is this save? After this 'scope' ends all pointed fields are invalid?
//this doesn't copy the linked list ai_next.
*update=*res;
}
Directly using &update on getaddrinfo seems to not work because the problem remains: the original struct get destroyed after the function scope ends.
Anyone able to give me more insight here (please explain what gets created where and destroyed where, stack, heap all info is welcome)