title: How to read /proc/self/net/tcp?
body: <p>My program's <code>/proc/5812/net/tcp/</code> file looks like this:</p>
  <pre><code>sl  local_address rem_address   st tx_queue rx_queue tr tm-&gt;when retrnsmt   uid  timeout inode                                                     
     0: 3500007F:0035 00000000:0000 0A 00000000:00000000 00:00000000 00000000   101        0 20861 1 ffff8ac807696040 100 0 0 10 5                     
     1: 0100007F:0277 00000000:0000 0A 00000000:00000000 00:00000000 00000000     0        0 23685 1 ffff8ac80721abc0 100 0 0 10 0                     
     2: 0F0AA8C0:982C 84B5FA8E:01BB 06 00000000:00000000 03:0000083D 00000000     0        0 0 3 ffff8ac8068f11f0                                      
     3: 0F0AA8C0:8816 42B5FA8E:01BB 06 00000000:00000000 03:00001139 00000000     0        0 0 3 ffff8ac8068f1c98                                      
     4: 0F0AA8C0:BBA4 A213D9AC:01BB 06 00000000:00000000 03:00001521 00000000     0        0 0 3 ffff8ac8068f18b8                                      
     5: 0F0AA8C0:8CEC E2D03AD8:01BB 06 00000000:00000000 03:0000119D 00000000     0        0 0 3 ffff8ac8068f1aa8                                      
     6: 0F0AA8C0:8F16 45816597:01BB 01 00000000:00000000 00:00000000 00000000  1000        0 60827 1 ffff8ac756b6b480 51 4 30 10 -1                    
  </code></pre>
  <p>Can anyone please pin point how to translate just one line is above data</p>
  <p>I like to know what is this</p>
  <pre><code>   0: 3500007F:0035 00000000:0000 0A 00000000:00000000 00:00000000 00000000   101        0 20861 1 ffff8ac807696040 100 0 0 10 5                     
  </code></pre>
  <p>In above?
  What is remote address?
  What is local address
  what is st?
  what is tx_queue?
  what is rx_queue?
  what is tr?
  what is tm-&gt;when
  what is retrnmt
  And why uid is prited as 3 numbers, since I am running this process as sudo so I believe user is just one and NOT three uid's should be printed
  what is timeout?
  it shows inode so can I get file descriptor from this and any of the above <code>what is</code>?</p>
  <p>And if My program is opening single socket connection and thats the only fd that in program that I coded then how to get that socket fd?</p>
  <p>This is my simple client code that creates client socket to connect to 192.168.10.15 through TUN0 interface that assign tun0 to socket with help of ifreq and setsockopt..</p>
  <p>I need any one please look at the above text and rows and please help me understand, How to interpret the above and accomplish what I am at</p>
  <p>This is my C client program creating single socket,</p>
  <pre><code>#include &lt;netdb.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include &lt;sys/socket.h&gt;
  #include &lt;sys/ioctl.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;net/if.h&gt;
  #include &lt;arpa/inet.h&gt;
  #include &lt;errno.h&gt;
  
  #define MAX 80
  #define PORT 80 
  #define SA struct sockaddr
  void func(int sockfd)
  {
      char buff[MAX];
      int n;
      for (;;) {
          bzero(buff, sizeof(buff));
          printf(&quot;Enter the string : &quot;);
          n = 0;
          while ((buff[n++] = getchar()) != '\n')
              ;
          write(sockfd, buff, sizeof(buff));
          bzero(buff, sizeof(buff));
          read(sockfd, buff, sizeof(buff));
          printf(&quot;From Server : %s&quot;, buff);
          if ((strncmp(buff, &quot;exit&quot;, 4)) == 0) {
              printf(&quot;Client Exit...\n&quot;);
              break;
          }
      }
  }
  
  int main()
  {
      int sockfd, connfd;
      struct sockaddr_in servaddr, cli;
  
      sockfd = socket(AF_INET, SOCK_STREAM, 0);
  struct ifreq ifr;
  printf(&quot;%d\n&quot;,sockfd);
      // Bind to a specific network interface (and optionally a specific local port)
      /*struct sockaddr_in localaddr;
      localaddr.sin_family = AF_INET;
  
      localaddr.sin_family = AF_INET;
          localaddr.sin_addr.s_addr = inet_addr(&quot;192.168.10.17&quot;);//htonl(INADDR_ANY);//inet_addr(&quot;192.168.10.17&quot;); //you can give your server IP here
      localaddr.sin_port = htons(5001); //your port here
     
      
      bind(sockfd, (struct sockaddr *)&amp;localaddr, sizeof(localaddr));
      */
      
      memset(&amp;ifr, 0, sizeof(ifr));
      snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), &quot;tun0&quot;);
      if (setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE, (void *)&amp;ifr, sizeof(ifr)) &lt; 0) {
          printf(&quot;errno  = %d\n&quot;,errno);
          printf(&quot;error socopt\n&quot;);
      }
      
  
      // Connect to the remote server
      struct sockaddr_in remoteaddr;
      remoteaddr.sin_family = AF_INET;
      remoteaddr.sin_addr.s_addr = inet_addr(&quot;192.168.10.15&quot;);
      remoteaddr.sin_port = htons(80);
      
      //printf(&quot;%d\n&quot;,o);
      int o=connect(sockfd, (struct sockaddr *)&amp;remoteaddr, sizeof(remoteaddr));
      printf(&quot;connect %d\n&quot;,o);
      // socket create and varification
  /*  sockfd = socket(AF_INET, SOCK_STREAM, 0);
      if (sockfd == -1) {
          printf(&quot;socket creation failed...\n&quot;);
          exit(0);
      }
      else
          printf(&quot;Socket successfully created..\n&quot;);
  
      bzero(&amp;servaddr, sizeof(servaddr));*/
  
      // assign IP, PORT*/
  /*  servaddr.sin_family = AF_INET;
      servaddr.sin_addr.s_addr = inet_addr(&quot;192.168.10.15&quot;);
      servaddr.sin_port = htons(80);*/
      
      
      // connect the client socket to server socket
  
      // function for chat
      func(sockfd);
  
      // close the socket
      close(sockfd);
  }
  </code></pre>