Home | History | Annotate | Download | only in GetHostByDns
      1 /** @file
      2   Translate the host name into an IP address
      3 
      4   Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
      5   This program and the accompanying materials are licensed and made available under
      6   the terms and conditions of the BSD License that accompanies this distribution.
      7   The full text of the license may be found at
      8   http://opensource.org/licenses/bsd-license.php.
      9 
     10   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     11   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     12 **/
     13 #include <errno.h>
     14 #include <netdb.h>
     15 #include <string.h>
     16 #include <Uefi.h>
     17 #include <unistd.h>
     18 
     19 #include <Library/DebugLib.h>
     20 #include <Library/UefiLib.h>
     21 
     22 #include <sys/socket.h>
     23 
     24 struct hostent * _gethostbydnsname (const char *, int);
     25 
     26 char mBuffer[65536];
     27 
     28 
     29 /** Translate the host name into an IP address
     30 
     31   @param [in] Argc  The number of arguments
     32   @param [in] Argv  The argument value array
     33 
     34   @retval  0        The application exited normally.
     35   @retval  Other    An error occurred.
     36 **/
     37 int
     38 main (
     39   IN int Argc,
     40   IN char **Argv
     41   )
     42 {
     43   UINT8 * pIpAddress;
     44   struct hostent * pHost;
     45 
     46   DEBUG (( DEBUG_INFO,
     47             "%a starting\r\n",
     48             Argv[0]));
     49 
     50   //  Determine if the host name is specified
     51   if ( 1 == Argc ) {
     52     Print ( L"%a  <host name>\r\n", Argv[0]);
     53   }
     54   else {
     55     //  Translate the host name
     56     pHost = _gethostbydnsname ( Argv[1], AF_INET );
     57     if ( NULL == pHost ) {
     58       Print ( L"ERROR - host not found, h_errno: %d\r\n", h_errno );
     59     }
     60     else {
     61       pIpAddress = (UINT8 *)pHost->h_addr;
     62       Print ( L"%a: Type %d, %d.%d.%d.%d\r\n",
     63               pHost->h_name,
     64               pHost->h_addrtype,
     65               pIpAddress[0],
     66               pIpAddress[1],
     67               pIpAddress[2],
     68               pIpAddress[3]);
     69     }
     70   }
     71   //  All done
     72   return errno;
     73 }
     74