Q> Как узнать ip адрес(а) машины (в текстовом виде)?
A> Кусок исходника от плугина к BackOrifice:

//---------------------------------------------------
void MachineIP(char *result)
{
WSADATA WSAData;

WSAStartup(MAKEWORD(1,1), &WSAData);

char dot[6];
int iResult;
int i = 0;
u_long *ppIpNO;
u_long *pIpNO;
HOSTENT FAR *lphostent;
u_long ipHO;
unsigned char binIp[4];
int iterations = 0;

//Get local host name and crudely validate
char szHostName[100];
*result = 0;

iResult = gethostname(szHostName, sizeof(szHostName));
// printf("%d %s",iResult,szHostName);
if ((iResult != 0) || (lstrcmp(szHostName, "")==0))
return;

//Lok up this host info via supplied name
lphostent = gethostbyname(szHostName);
if (lphostent == NULL)
return;
//Retreive first entry (might have multiple connects)
do
{
iterations++;
ppIpNO = (u_long *)lphostent->h_addr_list;
if (ppIpNO+i == NULL)
return;
pIpNO = ((u_long *)*(ppIpNO+i));
if (pIpNO == NULL)
return;

//convert back to host order, since SOCKADDR_IN expects that
//MessageBox(NULL,"z","x",MB_OK);
ipHO = ntohl(*pIpNO);

binIp[0] = (BYTE)((ipHO & 0xff000000) >> 24);
itoa(binIp[0], dot, 10);
strcat(result,dot);
binIp[1] = (BYTE)((ipHO & 0x00ff0000) >> 16);
itoa(binIp[1], dot, 10);
strcat(result, "."); strcat(result, dot);
binIp[2] = (BYTE)((ipHO & 0x0000ff00) >> 8);
itoa(binIp[2], dot, 10);
strcat(result, "."); strcat(result, dot);
binIp[3] = (BYTE)(ipHO & 0x000000ff);
itoa(binIp[3], dot, 10);
strcat(result,"."); strcat(result, dot);
strcat(result,"\r\n");
i++;
} while ((pIpNO != NULL) && (iterations < 6));
WSACleanup();
PostQuitMessage(0);
return;
}


Рейтинг@Mail.ru be number one Submitter.ru - Promoting!
Хостинг от uCoz