EDK2 doxygen online documents - Firmware Encoding Index 1
EDK2 doxygen online documents - Firmware Encoding Index

AppPkg/Applications/Sockets/GetHostByName/GetHostByName.c

Go to the documentation of this file.
00001 
00015 #include <errno.h>
00016 #include <netdb.h>
00017 #include <string.h>
00018 #include <Uefi.h>
00019 #include <unistd.h>
00020 
00021 #include <Library/DebugLib.h>
00022 #include <Library/UefiLib.h>
00023 
00024 #include <sys/socket.h>
00025 
00026 char mBuffer[65536];
00027 
00028 
00038 int
00039 main (
00040   IN int Argc,
00041   IN char **Argv
00042   )
00043 {
00044   int AppStatus;
00045   UINTN Index;
00046   struct hostent * pHost;
00047   UINT8 * pIpAddress;
00048   char ** ppName;
00049 
00050   DEBUG (( DEBUG_INFO,
00051             "%a starting\r\n",
00052             Argv[0]));
00053 
00054   //
00055   //  Determine if the host name is specified
00056   //
00057   AppStatus = 0;
00058   if ( 1 == Argc ) {
00059     Print ( L"%a  <host name>\r\n", Argv[0]);
00060   }
00061   else {
00062     //
00063     //  Translate the host name
00064     //
00065     pHost = gethostbyname ( Argv[1]);
00066     if ( NULL == pHost ) {
00067       Print ( L"ERROR - host not found, h_errno: %d\r\n", h_errno );
00068     }
00069     else {
00070       pIpAddress = (UINT8 *)pHost->h_addr;
00071       Print ( L"%d.%d.%d.%d, Type %d, %a\r\n",
00072               pIpAddress[0],
00073               pIpAddress[1],
00074               pIpAddress[2],
00075               pIpAddress[3],
00076               pHost->h_addrtype,
00077               pHost->h_name );
00078 
00079       //
00080       //  Display the other addresses
00081       //
00082       for ( Index = 1; NULL != pHost->h_addr_list[Index]; Index++ ) {
00083         pIpAddress = (UINT8 *)pHost->h_addr_list[Index];
00084         Print ( L"%d.%d.%d.%d\r\n",
00085                 pIpAddress[0],
00086                 pIpAddress[1],
00087                 pIpAddress[2],
00088                 pIpAddress[3]);
00089       }
00090 
00091       //
00092       //  Display the list of aliases
00093       //
00094       ppName = pHost->h_aliases;
00095       if (( NULL == ppName ) || ( NULL == *ppName )) {
00096         Print ( L"No aliases\r\n" );
00097       }
00098       else {
00099         Print ( L"Aliases: " );
00100         while ( NULL != *ppName ) {
00101           //
00102           //  Display the alias
00103           //
00104           Print ( L"%a", *ppName );
00105 
00106           //
00107           //  Set the next alias
00108           //
00109           ppName += 1;
00110           if ( NULL != *ppName ) {
00111             Print ( L", " );
00112           }
00113         }
00114         Print ( L"\r\n" );
00115       }
00116     }
00117   }
00118 
00119   //
00120   //  All done
00121   //
00122   return errno;
00123 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Defines