any help would be appreciated. Im developing a udp connection and i have a function that initialize the parameters of an address.
here is the code
void Socket::InitAddrInfoStruct (struct addrinfo *hints, bool socktype){
/* Setting addrinfo struct */
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_UNSPEC; // set to AF_INET to force IPv4
if(socktype == true)
hints.ai_socktype = SOCK_DGRAM; // set to SOCK_DGRAM to force UDP protocol type
else
hints.ai_socktype = SOCK_STREAM; // set to SOCK_STREAM to force TCP protocol type
hints.ai_flags = AI_PASSIVE; // use my IP
}
when i try to compile i got the following error:
request for member ‘ai_family’ in ‘hints’, which is of non-class type ‘addrinfo*’
can anyone help me on how i should add data to the struct hints?
The error is saying that
hintsis not of class type, and indeed its a pointer. You should access its members with->instead:or alternatively:
Also, as @Anders K. pointed out, your
memsetis probably wrong since you are invoking it with the size of a pointer. It should be:or alternatively: