/**********************************************************************
 
	Copyright (C) 2003 Hirohisa MORI <joshua@nichibun.ac.jp>
 
	This program is free software; you can redistribute it 
	and/or modify it under the terms of the GLOBALBASE 
	Library General Public License (G-LGPL) as published by 

	http://www.globalbase.org/
 
	This program is distributed in the hope that it will be 
	useful, but WITHOUT ANY WARRANTY; without even the 
	implied warranty of MERCHANTABILITY or FITNESS FOR A 
	PARTICULAR PURPOSE.

**********************************************************************/


#include	<stdio.h>
#include	"netutils.h"
#include	"memory_debug.h"
#include <winsock2.h>

static char * dm;
char *
get_localdomainname()
{
	char *p;
	char *ret;
	static char *local_domain_name = 0;
	char host_name[256];
	struct hostent *he;

	if(local_domain_name)
		return local_domain_name;
	
	get_localhostname(host_name);
	he = gethostbyname(host_name);
	if(he){
		strcpy(host_name, he->h_name);
	}
	
	p = strchr(host_name, '.');
	if(p){
		++p;
		ret = d_alloc(strlen(p)+1);
		strcpy(ret, p);
	}
	else{
		ret = 0;
	}
	local_domain_name = ret;
	printf("local domain name = %s\n", local_domain_name);
	return ret;

}
