In any case your structure should look like this:
struct addrinfo {
int ai_flags;
int ai_family;
int ai_socktype;
int ai_protocol;
socklen_t ai_addrlen;
struct sockaddr *ai_addr;
char *ai_canonname;
// notice the lack of `ai_next`
};
Then if you really want to keep the linked list you should either use std::forward_list
or std::list
(doubly linked list):
std::forward_list<addrinfo> list;
otherwise if you want to use an std::vector
(which from your example usage would fit nicely) you would just need to change it to:
std::vector<addrinfo> vector;