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

programming question: how to get the addr of a sockaddr_storage?



Hola

[Is somewhere an ipv6 programming mailing list?]

I'm working on adapting ircu to be AF independent. One thing ircu
does is having a registry of recently-seen addresses so it can
throttle incoming connections from the same host.

To be able to do that i need to extract the addr from the sockaddr_storage
filled by getpeername.

Some ways i think it can be done but shouldn't be done:

int fd;
struct sockaddr_storage ss;
int len = sizeof(ss);
char sock_ip[1024];
struct addrinfo hints;
struct sockaddr *res;

getpeername(fd,&ss,&len);
getnameinfo((struct sockaddr*) &ss, sizeof(ss),
		(char*) sock_ip, sizeof(sock_ip),
		NULL, 0, NI_NUMERICHOST);
memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_NUMERICHOST;
hints.ai_family = ss.ai_family;
hints.ai_socktype = ss.ai_socktype;
getaddrinfo(sock_ip, NULL, &hints, &res);

And use res to compare if the just connected client is in the list of
recent tryers.

This is TOO complex to be the right way to do it.

Doing it by touching sin.port or sin6.port would breaking my goal (making
the program not ipv6 aware but AF independent)

As these doesn't seem to be right ways I wonder if there is one and
what is it?

Thanks,
					HoraPe
---
Horacio J. Peña
horape@compendium.com.ar
horape@uninet.edu
bofh@puntoar.net.ar
horape@hcdn.gov.ar



Reply to: