[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

(usagi-users 01315) using getaddrinfo



Hello.  I have a small program that I am trying to change to use PF
independent networking code.  I have successfully changed the program to
use getaddrinfo, and everything works, except for a specific detail.

The second parameter to getaddrinfo is a string that refers to a service
listed in /etc/services.  What do I do if the port I am talking to may
not be listed in /etc/services?  I have an integer that refers to the
port, and nothing else.  I can pass NULL as the second parameter, but at
some point I will have to specify the port in the ai_addr field of the
return value.  What's the right way to do that?

Here is the relevant chunk of code:

	error = getaddrinfo(remote_host, NULL, &hints, &head);
	if (error) {
		perror(gai_strerror(error));
        }
	else {
                res = head;
                while (res) {
                        ((struct sockaddr_in6*) res->ai_addr)->sin6_port = port;
                        sock_fd = socket(res->ai_family, res->ai_socktype, 
                                         res->ai_protocol);

Obviously, I should not be doing
((struct sockaddr_in6*) res->ai_addr)->sin6_port = port;
if I want this to be PF independent.

I am sorry if this is a basic question or a FAQ.  I have tried to find
an answer, but it eludes me.

Thanks.
noah