linux c - get server hostname?
like gethostname() ?
That's the name of the machine on which your app is running.
Or read from
/proc/sys/kernel/hostname
Update
Simple example
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(void) {
char hostname[1024];
gethostname(hostname, 1024);
puts(hostname);
return EXIT_SUCCESS;
}
Building on the answer from Alain Pannetier, you can spare a few bytes by using HOST_NAME_MAX:
#include <limits.h>
...
char hostname[HOST_NAME_MAX+1];
gethostname(hostname, HOST_NAME_MAX+1);
...