F
FangQ
Unregistered / Unconfirmed
GUEST, unregistred user!
在CB里我用下面的函数(从原来大家的讨论中改编的)来得到自己
的IP地址然后,但有位南京的同志用我的程序传过来的IP地址竟
然是它机子的子网掩码,请问到底是那句错了?
BTW:他们是几台机子用一个IP,然后用不同的子网掩码来同时上网的
//----------------------------------
AnsiString LocalIP()
{
u_long result;
int bufsize=255;
char *buf;
AnsiString IP="";
struct hostent FAR * RemoteHost;
buf=NULL;
try
{
buf=new char[bufsize];
gethostname(buf,bufsize);
RemoteHost=gethostbyname(buf);
if (RemoteHost!=NULL)
{
int Sec=(int)(RemoteHost->h_addr_list)[0][0];
IP+= AnsiString(Sec>=0? Sec: 256+Sec)+".";
Sec=(int)(RemoteHost->h_addr_list)[0][1];
IP+= AnsiString(Sec>=0? Sec: 256+Sec)+".";
Sec=(int)(RemoteHost->h_addr_list)[0][2];
IP+= AnsiString(Sec>=0? Sec: 256+Sec)+".";
Sec=(int)(RemoteHost->h_addr_list)[0][3];
IP+= AnsiString(Sec>=0? Sec: 256+Sec);
}
else
result=(long int)(RemoteHost->h_addr_list);
}
catch(...)
{
if (buf!=NULL)
delete buf;
}
return IP;
}
的IP地址然后,但有位南京的同志用我的程序传过来的IP地址竟
然是它机子的子网掩码,请问到底是那句错了?
BTW:他们是几台机子用一个IP,然后用不同的子网掩码来同时上网的
//----------------------------------
AnsiString LocalIP()
{
u_long result;
int bufsize=255;
char *buf;
AnsiString IP="";
struct hostent FAR * RemoteHost;
buf=NULL;
try
{
buf=new char[bufsize];
gethostname(buf,bufsize);
RemoteHost=gethostbyname(buf);
if (RemoteHost!=NULL)
{
int Sec=(int)(RemoteHost->h_addr_list)[0][0];
IP+= AnsiString(Sec>=0? Sec: 256+Sec)+".";
Sec=(int)(RemoteHost->h_addr_list)[0][1];
IP+= AnsiString(Sec>=0? Sec: 256+Sec)+".";
Sec=(int)(RemoteHost->h_addr_list)[0][2];
IP+= AnsiString(Sec>=0? Sec: 256+Sec)+".";
Sec=(int)(RemoteHost->h_addr_list)[0][3];
IP+= AnsiString(Sec>=0? Sec: 256+Sec);
}
else
result=(long int)(RemoteHost->h_addr_list);
}
catch(...)
{
if (buf!=NULL)
delete buf;
}
return IP;
}