Before we move ahead I would like to explain first why we need domain name. Please go through the below link to understand in more.
Now you have idea of what is domain names, along with the domain name we also need some information of our local system where we are running our application. This we can get with the function uname. Go through the below link and see how it works and help us
After that here are the api's that are used to tell the hostname and the domin name.
Obtaining Hostnames and Domain Names