Subject: Re: IPV6 raw socket denies bind(2)

From: Brian Haley <[email-masked]>
Date: Wed, 27 Oct 2010 19:54:54 -0400

On 10/27/2010 06:01 PM, Jan Engelhardt wrote:
> int main(void)
> {
> 	struct sockaddr_in6 src = {};
> 	int sk;
> 
> 	sk = socket(AF_INET6, SOCK_RAW, IPPROTO_UDP);
> 	memset(&src, 0, sizeof(src));
> 	inet_pton(AF_INET6, "::1", &src);
> 	src.sin6_family = AF_INET6;
> 
> 	if (bind(sk, (void *)&src, sizeof(src)) < 0) {
> 		perror("bind");
> 		abort();
> 	}
> 	return 0;
> }

You're trashing the sockaddr, try this patch:

< 	inet_pton(AF_INET6, "::1", &src);
---
> 	inet_pton(AF_INET6, "::1", &src.sin6_addr);

-Brian