USRP2 Sockets


#1

I’ve been looking over the GNU Radio code and I can’t seem to figure
what is
being done in /usrp2/host/lib/open_usrp2_socket.cc file. Specifically,
lines 97 through to 128.

What I think is happening is that a pair of connected sockets is created
(97) then a process is forked (102). So, the child process has it’s own
pair of sockets? Are sockfd[0] in each process connected? That would
explain why sockfd[1] is closed (114) immediately after the fork, but it
would not explain the need for socketpair to begin with.

So, my questions are: why is socketpair needed? What is the fork doing?
And, why is the socket closed right after the fork?

Any help is appreciated.
Devin


#2

On Wed, Apr 15, 2009 at 04:20:20PM -0400, devin kelly wrote:

So, my questions are: why is socketpair needed? What is the fork doing?
And, why is the socket closed right after the fork?

Any help is appreciated.
Devin

This code allows us to open a SOCK_RAW socket without being root by
using a setuid-root helper program, usrp2_socket_opener. The setuid
program opens the socket on our behalf and passes it back to us
through the socket pair using the socket capability feature.

Look at the code for the helper program, usrp2_socket_opener.c
and read the man pages for each system call to see what’s going on.

Eric


#3

So, just to help me understand, let’s say that running as root wasn’t a
problem. Like, if you didn’t have to be root to open a raw socket.

Would that mean that the open_usrp2_socket() function would just look
like
this

usrp2::open_usrp2_socket() {

    int fd = socket(PF_PACKET, SOCK_RAW, htons(0xBEEF);
    return fd;

}

and you wouldn’t need the helper program, usrp2_socket_opener.cc? But,
you
would still need the read_fd(…) and write_fd(…) functions right?

Thanks again for the help.
Devin


#4

On Thu, Apr 16, 2009 at 02:33:56PM -0400, devin kelly wrote:

}

and you wouldn’t need the helper program, usrp2_socket_opener.cc?

That’s right.

But, you would still need the read_fd(…) and write_fd(…) functions right?

No, they’re only used to make the fd transfer between the helper
program and the app happen.

Thanks again for the help.

You’re welcome.

Eric