LOCAL_CREDS are broken ?

Gleb Smirnoff glebius at FreeBSD.org
Wed Sep 11 15:10:46 UTC 2013


On Thu, Aug 29, 2013 at 11:48:41AM -0700, Yuri wrote:
Y> The example below breaks with "Protocol not available"
Y> But what is wrong? Isn't this the correct usage?
Y> LOCAL_CREDS are only handled in kern/uipc_usrreq.c for AF_LOCAL, so it 
Y> isn't clear why this doesn't work.
Y> 
Y> --- example.c ---
Y> #include <sys/types.h>
Y> #include <sys/socket.h>
Y> #include <stdio.h>
Y> #include <stdlib.h>
Y> #include <sys/un.h>
Y> 
Y> main() {
Y>    int sock;
Y>    int error;
Y>    int oval = 1;
Y> 
Y>    error = socket(AF_LOCAL, SOCK_SEQPACKET, 0);
Y>    if (error == -1) {perror("socket"); exit(-1);}
Y>    sock = error;
Y> 
Y>    error = setsockopt(sock, SOL_SOCKET, LOCAL_CREDS, &oval, sizeof(oval));
Y>    if (error) {perror("setsockopt"); exit(-1);}
Y> }

Alfred is right, we should add uipc_ctloutput() as method for
SOCK_SEQPACKET on local sockets.

But your code actually fails because you request SOL_SOCKET
level.

LOCAL_CREDS is protocol level option, not socket.

socket(AF_LOCAL, SOCK_DGRAM, 0);
setsockopt(sock, 0, LOCAL_CREDS, &oval, sizeof(oval));

P.S. I will look at issue with SOCK_SEQPACKET.
According to manual page, it should work.

-- 
Totus tuus, Glebius.


More information about the freebsd-net mailing list