Reputation: 197
I'm not really familiar with the connection protocols.
I'm using the following code to examine connect() so I can get the hostname:
#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];
}
can I use the "same" code to get the hostname if I hook into sendto() (so I can examine UDP)?
thanks in advance.
Upvotes: 0
Views: 1710
Reputation: 19477
You should be able to do so because sendto()
is passed a struct sockaddr
just as you are using in your example code.
When you "hook" sendto()
I assume you will do so with a macro which affects only your own source code -- as opposed to something like an intermediating driver.
The DNS name resolution depends on sending UDP packets, so if you were to "hook" sendto()
at a low enough level, your solution would recurse infinitely as it looked up the hostnames for outgoing DNS lookup packets...
Upvotes: 1