Red de conocimiento informático - Material del sitio web - Cómo ver el nombre del host local usando programación en lenguaje C

Cómo ver el nombre del host local usando programación en lenguaje C

Sistema WINDOWS:

//------------------------------------- - ------------------------------------

#include lt;windows hgt. ;<

#include lt;stdio.hgt;

#define INFO_BUFFER_SIZE 32767

void main()

{

TCHAR infoBuf[INFO_BUFFER_SIZE];

DWORD bufCharCount = INFO_BUFFER_SIZE;

if( GetComputerName( infoBuf, amp; bufCharCount ) )

printf( " \nNombre del equipo: s", infoBuf );

}

//---------------------- - -------------------------------------------------- --

Sistema LINUX:

//----- ----------------------- - ----------------------------------------------

#include lt;stdio.hgt;

int main(void)

{

char str[256];

ARCHIVO *fp=fopen("/etc/hostname", "r");

fgets(str, 256, fp);

puts(str); p>

devuelve 0;

}

//---------------------- ---- ---------------------------------------------- ----