sin.sin_addr = ip;
sin.sin_port = htons(61440);
sin.sin_family = AF_INET;
if ((bind(hsocket,sa,sizeof(sin))) < 0)
{
printf( "can't bind udp port 61440!\n");
return 0;
}
sin.sin_addr = ptp;
printf("Activating connection...\n");
workwell = 0;
keepalive:
errorcount = 0;
while(1)
{
sendlen = sendto(hsocket,&c1,8,MSG_NOSIGNAL,sa,sizeof(sin));
if(sendlen < 0 || errorcount >= 5)
{
printf("socket error! reinit...\n");
close(hsocket);
goto init;
}
if(waitdata(hsocket,1000*1000))
{
fromlen = sizeof(sin);
recvlen = recvfrom(hsocket,&c2,sizeof(c2),0,sa,&fromlen);
ip = sin.sin_addr;
break;
}
else
{
errorcount++;
printf("recv2 timed out\n");
}
}
memset(&c3,0,96);
c3.sign = 7;
c3.len = 96;
c3.id = 3;
c3.code1 = c2.code1;
c3.unk1 = 0x2000200;
c3.code0 = c2.code0;
c3.check = 0x1312fc7;
c3.unk2 = 0x7e;
memcpy(&c3.mac,&mac,6);
c3.devtype = 0x17;
memcpy(&c3.ipaddr,&ip,4);
memcpy(&c3.netmask,&netmask,4);
ptr_long = (u_long *)&c3;
for(n=0,check=0;n<96/4;n++)
check ^= *(ptr_long + n);
c3.check = check * 0x12C4B7E;
c3.unk2 = 0;
ptr = (u_char *)&c3.mac;
for(n=0;n<64;n++)
*(ptr + n) = (*(ptr + n) >> 8 - (n & 7)) + (*(ptr + n) << (n & 7));
sendlen = sendto(hsocket,&c3,96,MSG_NOSIGNAL,sa,sizeof(sin));
if(sendlen < 0 || errorcount >= 5)
{
printf("socket error! reinit...\n");
close(hsocket);
goto init;
}
if(waitdata(hsocket,1000*1000))
{
fromlen = sizeof(sin);
recvlen = recvfrom(hsocket,&c2,sizeof(c2),0,sa,&fromlen);
if(!workwell)
{
printf("Keeping connection active...\n");
workwell++;
}
}
else
{
printf("recv4 timed out\n");
sleep(1);
goto keepalive;
}
sleep(15);
goto keepalive;
return 0;
}
2.在终端里到drcom.c目录下,运行gcc drcom.c -o drcom.(如果没装gcc的话,先sudo apt-get install gcc)
3.运行drcom就好了。
要是嫌每次开机都要运行比较麻烦,可以添加到开机启动:
系统->首选项->启动应用程序->添加,然后把drcom加进去就OK了。
西邮的网通这样可以,其他地方的不一定。