希望在Iphone 上设置Socket(TCP/Unicast)发送的packet的TTL值,
但是听说IOS禁止设定,并且把默认值定为64.
不知各位大牛有没有这方面的经验。
例如,用下面的代码设定可以行得通么?或者需要别的方法?
Normal 0 false false false EN-US JA X-NONE
Source Code:
===================
- (IBAction)setTTLValue:(id)sender
{
int ttl = [textField.text intValue];
NSLog(@"setTTLvalue function is calledwith the TTL %d ", ttl);
int s;
const int port = 4000;
if ((s=socket(AF_INET, SOCK_STREAM, 0))!=-1)
{
NSLog(@"Created the socket");
//Bind the socket
[font="]
struct sockaddr_in sAddr;
memset((char*)&(sAddr), 0 , sizeof(sAddr));
sAddr.sin_family = AF_INET;
sAddr.sin_addr.s_addr = inet_addr("192.168.1.20");
sAddr.sin_port = htons(port);
if(bind(s, (struct sockaddr*)&sAddr, sizeof(sAddr))!=-1)
{
int oldTTL;
socklen_t opLen = sizeof(oldTTL);
if(getsockopt(s, IPPROTO_IP, IP_TTL, (char*) &oldTTL, &opLen)!=-1)
{
NSLog(@"setTTLvalue - Server Socketfunction oldTTL %d ", oldTTL);
if(setsockopt(s, IPPROTO_IP, IP_TTL, (char*)&ttl, sizeof(ttl)) !=-1)
{
if(getsockopt(s, IPPROTO_IP, IP_TTL, (char*) &oldTTL, &opLen)!=-1)
{
NSLog(@"setTTLvalue - Server Socketfunction newSetTTL %d ", oldTTL);
}
}
}
}
else {
NSLog(@"Binding of the server socketfailed ");
}
}
else
{
NSLog(@"Creation of the server socketfailed ");
}
//Client Socket
int clientSocket;
if ((clientSocket=socket(AF_INET, SOCK_STREAM, 0))!=-1)
{
int oldTTL;
socklen_t opLen = sizeof(oldTTL);
if(getsockopt(clientSocket, IPPROTO_IP, IP_TTL, (char*) &oldTTL, &opLen)!=-1)
{
NSLog(@"setTTLvalue - Client Socketfunction oldTTL %d ", oldTTL);
if(setsockopt(clientSocket, IPPROTO_IP, IP_TTL, (char*)&ttl, sizeof(ttl)) !=-1)
{
if(getsockopt(clientSocket, IPPROTO_IP, IP_TTL, (char*) &oldTTL, &opLen)!=-1)
{
NSLog(@"setTTLvalue - Client Socketfunction newSetTTL %d ", oldTTL);
}
}
}
}
}
--
FROM 210.57.19.*