I have a struct sockaddr and need to make a struct addrinfo (specifically that, because that’s what some other API wants). The IP address may be IPv4 or IPv6. What’s the best way to handle that?
Share
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.
From man 3 getaddrinfo,
A
struct addrinfocontains more information than just astruct sockaddrdoes. Given astruct sockaddr_in, you can have some of this information (.ai_family = AF_INET, .ai_addrlen = sizeof(struct sockaddr_in)). Whether this is sufficient depends on what the other API is looking for.