Description

gethostname not accurate in kubernetes

Troubleshooting

Reproduction

on a recent test with kamailio in kubernetes, found that gethostname can return only the hostname and not the fqdn. this depends on the kind of object is used (deployment/statefulset)

Possible Solutions

the below patch fixed the issues i was having

diff --git a/src/modules/ipops/ipops_pv.c b/src/modules/ipops/ipops_pv.c
index 5f77aa9..f65b4dd 100644
--- a/src/modules/ipops/ipops_pv.c
+++ b/src/modules/ipops/ipops_pv.c
@@ -455,6 +455,11 @@
 	if (gethostname(hbuf, 512)<0) {
 		LM_WARN("gethostname failed - host pvs will be null\n");
 		return -1;
+	} else {
+		struct hostent* h;
+		if((h = gethostbyname(hbuf)) != NULL) {
+			memcpy(hbuf, h->h_name, 512);
+		}
 	}
 
 	hlen = strlen(hbuf);

Additional Information

latest master
buster & centos7


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.