1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| #ifdef WIN32
# ifdef _MSC_VER
# pragma comment(lib,"Ws2_32.lib")
# endif /* _MSC_VER */
# ifdef UNICODE
# undef UNICODE
# endif /* UNICODE */
# ifdef _UNICODE
# undef _UNICODE
# endif /* _UNICODE */
# include <winsock2.h>
#else
# define <unistd.h>
#endif /* WIN32 */
#ifndef HOST_NAME_MAX
# define HOST_NAME_MAX 256
#endif /* HOST_NAME_MAX */
#include <stdio.h>
int main (void)
{
char hostname[HOST_NAME_MAX] = { 0 };
#ifdef WIN32
WSADATA wsa = { 0 };
WSAStartup (MAKEWORD (2, 2), &wsa);
#endif /* WIN32 */
gethostname (hostname, sizeof hostname);
puts (hostname);
#ifdef WIN32
WSACleanup ();
#endif /* WIN32 */
return 0;
} |
Partager