title: raw socket access as normal user on linux 2.4
body: <p>In an embedded system (2.4 kernel) I need raw socket access to the eth0 interface from a process <em>not</em> running as root. </p>
  
  <p>I tried to address this problem by setting the CAP_NET_RAW capability from the command line and programmatically using cap_set_proc(), both with no success. It seems that I do not have the permission to do so, in the program I get an EPERM error, on the command line</p>
  
  <blockquote>
    <p>Failed to set cap's on process `1586': (Operation not permitted)</p>
  </blockquote>
  
  <p>Is there an easier way to do what I want? If not, what steps are necessary to successfully set the CAP_NET_RAW capability?</p>
  
  <p>EDIT: I have root access, but running the process permanently as root is no option. The version of libcap is 1.10, there is no 'setcap' binary, but a 'setpcaps'.</p>
  
  <p>EDIT - answering George Skoptsov:</p>
  
  <p>If I get you right, your suggestion is to start a process with setuid, then set the CAP_NET_RAW capability and then drop the privileges. I tried this with the following code, but it does not seem to work, even though the caps command do not return errors. With the seteuid() commented out, raw access works, but only since the process is running as root then:</p>
  
  <pre><code>cap_t caps = cap_get_proc();
  cap_value_t cap_list[1];
  cap_list[0] = CAP_NET_RAW;
  if (cap_set_flag(caps, CAP_EFFECTIVE, 1, cap_list, CAP_SET) == -1)
  {
      printf("cap_set_flag error");
  }
  if (cap_set_proc(caps) == -1)
  {
      printf("cap_set_proc error");
  }
  
  if (seteuid(getuid()) != 0) 
  {
      printf("seteuid error");
  }
  
  function_that_needs_raw_access();
  </code></pre>
  
  <p>Thanks for your help.
  Chris</p>