Changeset 9502

Show
Ignore:
Timestamp:
09/05/08 03:10:47
Author:
eb
Message:

usrp2 can now be opened without running as root

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • usrp2/trunk/host/lib/Makefile.am

    r9501 r9502  
    3535        ethernet.cc \ 
    3636        find.cc \ 
     37        open_usrp2_socket.cc \ 
    3738        pktfilter.cc \ 
    3839        ring.cc \ 
  • usrp2/trunk/host/lib/ethernet.cc

    r9409 r9502  
    2323#include "ethernet.h" 
    2424#include "pktfilter.h" 
     25#include <open_usrp2_socket.h> 
    2526 
    2627#include <iostream> 
     
    4546  open_packet_socket (std::string ifname, int protocol) 
    4647  { 
     48#if 0     
    4749    if (protocol == 0) 
    4850      protocol = htons(ETH_P_ALL); 
    4951     
    5052    int fd = socket (PF_PACKET, SOCK_RAW, protocol); 
     53#else 
     54    int fd = usrp2::open_usrp2_socket(); 
     55#endif 
     56 
    5157    if (fd == -1){ 
    5258      fprintf (stderr, "%s: socket: %s\n", ifname.c_str(), strerror (errno)); 
  • usrp2/trunk/host/lib/usrp2_socket_opener.cc

    r9501 r9502  
    7979 
    8080bool 
    81 reset_eids () 
     81reset_eids() 
    8282{ 
    83   if (setgid (getgid ()) < 0){ 
    84     perror ("setguid"); 
     83  if (setgid(getgid()) < 0){ 
     84    perror("setguid"); 
    8585    return false; 
    8686  } 
    8787 
    88   if (setuid (getuid ()) < 0){ 
    89     perror ("setuid"); 
     88  if (setuid(getuid()) < 0){ 
     89    perror("setuid"); 
    9090    return false; 
    9191  } 
     
    116116 
    117117  // open the raw socket 
    118   int socket_fd = socket (PF_PACKET, SOCK_RAW, htons(0xBEEF)); 
     118  int socket_fd = socket(PF_PACKET, SOCK_RAW, htons(0xBEEF)); 
    119119  if (socket_fd == -1){ 
    120120    perror("socket(PF_PACKET, SOCK_RAW, htons(0xBEEF))"); 
    121121    // printf("errno = %d\n", errno); 
    122122    if (errno == EACCES || errno == ESPIPE){ 
    123       fprintf (stderr, "usrp2_socket_opener must be setuid root to open the socket using SOCK_RAW.\n"); 
    124       fprintf (stderr, "Running as root, please execute:  \n"); 
    125       fprintf (stderr, "  # chown root usrp2_socket_opener\n"); 
    126       fprintf (stderr, "  # chmod u+s usrp2_socket_opener\n"); 
     123      fprintf(stderr, "usrp2_socket_opener must be setuid root to open the socket using SOCK_RAW.\n"); 
     124      fprintf(stderr, "Running as root, please execute:  \n"); 
     125      fprintf(stderr, "  # chown root usrp2_socket_opener\n"); 
     126      fprintf(stderr, "  # chmod u+s usrp2_socket_opener\n"); 
    127127    } 
    128128    exit(2);