On Tue, Oct 12, 2004 at 09:53:26AM +0200, Emmanuel Dreyfus wrote:
> But that kills backward compatibility.
Why? I don't say you should use the UDP socket except for checking
if you can bind to the IP address of a specific peer which means
it is a local address.
> We could also check that the address is non local.
That's exactly what I'm suggesting, isn't it?
The implementation could look like this:
int
IsLocalAddress(const struct sockaddr *sa)
{
struct sockaddr_in sin;
struct sockaddr_in6 sin6;
socklen_t length;
int sfd, islocal;
switch (sa->sa_family) {
case AF_INET:
length = sizeof (sin);
(void) memcpy(&sin, sa, sizeof (sin));
sin.sin_port = 0;
sa = (struct sockaddr *)&sin;
break;
case AF_INET6:
length = sizeof (sin6);
(void) memcpy(&sin, sa, sizeof (sin));
sin6.sin6_port = 0;
sin6.sin6_flowinfo = 0;
sin6.sin6_scope_id = 0;
sa = (struct sockaddr *)&sin6;
break;
default:
/* error handling */
[...]
}
if ((sfd = socket(sa->sa_family, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
/* error handling */
[...]
}
if (bind(sfd, sa, length) < 0) {
if (errno != EADDRNOTAVAIL) {
/* error handling */
[...]
}
islocal = 0;
} else {
islocal = 1;
}
(void) close(sfd);
return (islocal);
}
Kind regards
--
Matthias Scheler http://scheler.de/~matthias/Message
Re: [milter-greylist] Re: syncing autowhitelisted entries between mx-hosts
2004-10-12 by Matthias Scheler
Attachments
- No local attachments were found for this message.