1570af302Sopenharmony_ci#ifdef __LITEOS_A__
2570af302Sopenharmony_ci#define _GNU_SOURCE
3570af302Sopenharmony_ci
4570af302Sopenharmony_ci#include <netdb.h>
5570af302Sopenharmony_ci#include <string.h>
6570af302Sopenharmony_ci#include <unistd.h>
7570af302Sopenharmony_ci
8570af302Sopenharmony_ci#define HOSTID_NUM   16
9570af302Sopenharmony_ci#else
10570af302Sopenharmony_ci#include <unistd.h>
11570af302Sopenharmony_ci#endif
12570af302Sopenharmony_ci
13570af302Sopenharmony_cilong gethostid()
14570af302Sopenharmony_ci{
15570af302Sopenharmony_ci#ifdef __LITEOS_A__
16570af302Sopenharmony_ci	int ret;
17570af302Sopenharmony_ci	struct in_addr in;
18570af302Sopenharmony_ci	struct hostent *hst = NULL;
19570af302Sopenharmony_ci	char **p = NULL;
20570af302Sopenharmony_ci	char host[128] = {0};
21570af302Sopenharmony_ci
22570af302Sopenharmony_ci	ret = gethostname(host, sizeof(host));
23570af302Sopenharmony_ci	if (ret || host[0] == '\0') {
24570af302Sopenharmony_ci		return -1;
25570af302Sopenharmony_ci	}
26570af302Sopenharmony_ci
27570af302Sopenharmony_ci	hst = gethostbyname(host);
28570af302Sopenharmony_ci	if (hst == NULL) {
29570af302Sopenharmony_ci		return -1;
30570af302Sopenharmony_ci	}
31570af302Sopenharmony_ci
32570af302Sopenharmony_ci	p = hst->h_addr_list;
33570af302Sopenharmony_ci	memcpy(&in.s_addr, *p, sizeof(in.s_addr));
34570af302Sopenharmony_ci
35570af302Sopenharmony_ci	return (long)((in.s_addr << HOSTID_NUM) | (in.s_addr >> HOSTID_NUM));
36570af302Sopenharmony_ci#else
37570af302Sopenharmony_ci	return 0;
38570af302Sopenharmony_ci#endif
39570af302Sopenharmony_ci}
40