hostname client, ip client

This commit is contained in:
2026-02-09 08:30:34 +01:00
commit a7ff320857
13 changed files with 282 additions and 0 deletions

29
client2/src/main.c Normal file
View File

@@ -0,0 +1,29 @@
#include <arpa/inet.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
int main() {
char *hostname = "www.motionweb.hu";
char ip[100];
struct hostent *he;
struct in_addr **addr_list;
int i;
if ((he = gethostbyname(hostname)) == NULL) {
puts("gethostbyname error\n");
return 1;
}
// Cast the h_addr_list to in_addr , since h_addr_list also has the ip address in long format only
addr_list = (struct in_addr **)he->h_addr_list;
for (i = 0; addr_list[i] != NULL; i++) {
// return the first one
strcpy(ip, inet_ntoa(*addr_list[i]));
}
printf("%s resolved to : %s", hostname, ip);
return 0;
}