title: How do I read buffer data retrieved from sysctlbyname() in iPhone?
body: <p>I'm trying to get TCP open port list in iphone by using sysctlbyname().</p>
  
  <pre><code> sysctlbyname(const char *name, void *oldp, size_t *oldlenp, void *newp,
       size_t newlen);
  </code></pre>
  
  <p>.</p>
  
  <pre><code> #include &lt;sys/sysctl.h&gt;
  
   size_t len = 0;
   if (sysctlbyname("net.inet.tcp.pcblist", 0, &amp;len, 0, 0) &lt; 0) {
        perror("sysctlbyname");
   } else {
        char *buf = malloc(len);
        //printf("%d",sizeof(buf));
        sysctlbyname("net.inet.tcp.pcblist", buf, &amp;len, 0, 0);
        NSData *data = [NSData dataWithBytesNoCopy:buf length:len];
        NSLog(@"data = %@", data);
  
        //printf("%d",sizeof(buf));
        //printf("%s",buf);
   }
  </code></pre>
  
  <p>The information is copied into the buffer specified by oldp.</p>
  
  <p>OUTPUT::</p>
  
  <pre><code>data = &lt;18000000 34000000 d8160000 00000000 7d760000 00000000 0c020000 00000000 00000000 00000000 00000000 0050c598 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 c2160000 00000000 40008000 00000000 01400000
  </code></pre>
  
  <p>Buffer is filled with data here.but I'm unable to print the data in readable format.converting this data into NSString won't help as internally buffer has its own structure.</p>
  
  <p>Anyone knows how to obtain TCP open port list as output from this data?</p>
  
  <p>Thanks.</p>