# Socket Options Error



## perleo (Feb 3, 2011)

I've been testing some code and using ktrace to debug. The following error is occurring, 


```
setsockopt -1 errno 22 Invalid argument
```

it is linked the following line of code.


```
int on = 1;
setsockopt(sockfd, IPPROTO_IPV6, IPV6_DSTOPTS, &on, sizeof(on));
```

sockfd is working fine as the rest of the application works and network traffic flows (over IPv6).

Testing on FreeBSD 7.3-RELEASE GENERIC i386

Is this a bug or am I missing something?


----------



## expl (Feb 3, 2011)

What kind of socket is it?

This option is only allowed to be set on SOCK_DGRAM or SOCK_RAW socket.


----------



## SirDice (Feb 3, 2011)

Looks fine but ip6(4) says:



> IPV6_DSTOPTS int *
> Get or set whether the destination options from subsequent packets will be provided as ancillary data along with the payload in subsequent recvmsg(2) calls.  The option is stored in the following structure in the ancillary data returned:
> 
> ```
> ...


----------



## perleo (Feb 3, 2011)

expl said:
			
		

> What kind of socket is it?
> 
> This option is only allowed to be set on SOCK_DGRAM or SOCK_RAW socket.



I've tried it with SOCK_DGRAM and it still happens. 

@SirDice I'm compiling and running the code as root.


----------

