title: How to get socket structure using socket fd associated with it in user space?
body: <p>I have socket fd, I want to get the socket to which this fd is bound to.<br>
  my code is </p>
  
  <pre><code>   create_socket(int nl_groups)
     {
      int s;
      struct sockaddr_nl nladdr;
  
      if((   s = socket    (AF_NETLINK,    SOCK_RAW,     NETLINK_GENERIC)) &lt; 0)
      return s;
  
      memset (&amp;nladdr, 0, sizeof nladdr);`enter code here`
      nladdr.nl_family = AF_NETLINK;
      nladdr.nl_pid = 0;
      nladdr.nl_groups = nl_groups;
      if (bind(s, (struct sockaddr*)&amp;nladdr, sizeof(nladdr)) &lt; 0) {
      close(s);
      return -1;
      }
      return s;
  }
  </code></pre>
  
  <p>I saw in kernel space we can use struct <code>socket * sockfd_lookup  (int fd, int * err);</code><br>
  this returns the socket object pointer,<br>
  But I want to know how can we get socket in user space.</p>
  
  <p>Many thanks in advance</p>