title: C: getting hostname from TCP and UDP socket?
body: <p>I'm not really familiar with the connection protocols.</p>
  
  <p>I'm using the following code to examine connect() so I can get the hostname:</p>
  
  <pre><code>#ifndef   NI_MAXHOST
  #define   NI_MAXHOST 1025
  #endif
  
  int error;
  
   char hostname[NI_MAXHOST] = "";
  
  
   error = getnameinfo(serv_addr, addrlen, hostname, NI_MAXHOST, NULL, 0, 0);
  
   if (error !=0) {
    ALogTCP(@"coudldn't resolve hostname or internal connect");
    [pool release];
    return orig__connect(sockfd, serv_addr, addrlen);
    }
  
  
   if (error == 0) {
    ALogTCP(@"hostname: %s", hostname);
    NSString *hostFirst = [NSString stringWithCString:hostname];
  }
  </code></pre>
  
  <p>can I use the "same" code to get the hostname if I hook into sendto() (so I can examine UDP)?</p>
  
  <p>thanks in advance.</p>