char *GetMyIPstr(int i,char *buf)
{
char name[128];struct hostent *phe;
*buf=0;
if(gethostname(name,sizeof(name))==0)
{
phe=gethostbyname(name);
if(phe!=NULL)
{
struct in_addr *pin;int j;
for(j=0;j<=i;j++)
{
pin=(struct in_addr *)phe->h_addr_list[j];
if(pin==0)break;
if(i==j)
{
strcpy(buf,inet_ntoa(*pin));
return buf;
}
}
}
}
else
{
int err=GetLastError();//10093 WSANOTINITIALISED
if(err==10093)
{
WSAStartup();
return GetMyIPstr(i,buf);
}
}
return 0;
}
wchar_t *GetMyIPstr(int i,wchar_t *buf)
{
char b[32];
GetMyIPstr(i,b);
strcpy(buf,b);
return buf;
}