]> git.proxmox.com Git - mirror_edk2.git/blob - AppPkg/Applications/Sockets/GetHostByDns/GetHostByDns.c
c5c78ac2b3813974b0e57d066fd72121a7bae881
[mirror_edk2.git] / AppPkg / Applications / Sockets / GetHostByDns / GetHostByDns.c
1 /** @file
2 Translate the host name into an IP address
3
4 Copyright (c) 2011, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. 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 **/
14
15 #include <errno.h>
16 #include <netdb.h>
17 #include <string.h>
18 #include <Uefi.h>
19 #include <unistd.h>
20
21 #include <Library/DebugLib.h>
22 #include <Library/UefiLib.h>
23
24 #include <sys/socket.h>
25
26 struct hostent * _gethostbydnsname (const char *, int);
27
28 char mBuffer[65536];
29
30
31 /**
32 Translate the host name into an IP address
33
34 @param [in] Argc The number of arguments
35 @param [in] Argv The argument value array
36
37 @retval 0 The application exited normally.
38 @retval Other An error occurred.
39 **/
40 int
41 main (
42 IN int Argc,
43 IN char **Argv
44 )
45 {
46 int AppStatus;
47 UINT8 * pIpAddress;
48 struct hostent * pHost;
49
50 DEBUG (( DEBUG_INFO,
51 "%a starting\r\n",
52 Argv[0]));
53
54 //
55 // Determine if the host name is specified
56 //
57 AppStatus = 0;
58 if ( 1 == Argc ) {
59 Print ( L"%a <host name>\r\n", Argv[0]);
60 }
61 else {
62 //
63 // Translate the host name
64 //
65 pHost = _gethostbydnsname ( Argv[1], AF_INET );
66 if ( NULL == pHost ) {
67 Print ( L"ERROR - host not found, errno: %d\r\n", errno );
68 }
69 else {
70 pIpAddress = (UINT8 *)pHost->h_addr;
71 Print ( L"%a: Type %d, %d.%d.%d.%d\r\n",
72 pHost->h_name,
73 pHost->h_addrtype,
74 pIpAddress[0],
75 pIpAddress[1],
76 pIpAddress[2],
77 pIpAddress[3]);
78 }
79 }
80
81 //
82 // All done
83 //
84 return errno;
85 }