text: #include <stdio.h>
  #include <stdlib.h>
  #include <unistd.h>
  #include <netdb.h>
  #include <sys/socket.h>
  #include <arpa/inet.h>
  #include <sys/types.h>
  #include <ifaddrs.h>
  
  
  
  void check_host_name(int hostname) { //This function returns host name for local computer
     if (hostname == -1) {
        perror("gethostname");
        exit(1);
     }
  }
  void check_host_entry(struct hostent * hostentry) { //find host info from host name
     if (hostentry == NULL){
        perror("gethostbyname");
        exit(1);
     }
  }
  void IP_formatter(char *IPbuffer) { //convert IP string to dotted decimal format
     if (NULL == IPbuffer) {
        perror("inet_ntoa");
        exit(1);
     }
  }
  
  void ifs();
  
  int main(int ac, char *av[]) 
  {
     char host[256];
     char *IP;
     struct hostent *host_entry;
     int hostname;
     hostname = gethostname(host, sizeof(host)); //find the host name
     check_host_name(hostname);
     host_entry = gethostbyname(host); //find host information
     check_host_entry(host_entry);
     IP = inet_ntoa(*((struct in_addr*) host_entry->h_addr_list[0])); //Convert into IP string
  
     printf("Current Host Name: %s\n", host);
     printf("Host IP: %s\n", IP);
  
     ifs();
  }
  
  void ifs() 
  {
      struct ifaddrs *ifap, *ifa;
      struct sockaddr_in *sa;
      char *addr;
  
      getifaddrs (&ifap);
      for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
          if (ifa->ifa_addr->sa_family==AF_INET) {
              sa = (struct sockaddr_in *) ifa->ifa_netmask;
              addr = inet_ntoa(sa->sin_addr);
              printf("Interface: %s\tAddress: %s\n", ifa->ifa_name, addr);
          }
      }
  
      freeifaddrs(ifap);
  }
  