]> git.proxmox.com Git - mirror_edk2.git/blame - AppPkg/Applications/Sockets/GetNetByName/GetNetByName.c
AppPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / AppPkg / Applications / Sockets / GetNetByName / GetNetByName.c
CommitLineData
4684b66f 1/** @file\r
2 Translate the network name into an IP address\r
3\r
b81cc7d6 4 Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>\r
bcb96695 5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
4684b66f 6**/\r
4684b66f 7#include <errno.h>\r
8#include <netdb.h>\r
9#include <string.h>\r
10#include <Uefi.h>\r
11#include <unistd.h>\r
12\r
13#include <Library/DebugLib.h>\r
14#include <Library/UefiLib.h>\r
15\r
16#include <sys/socket.h>\r
17\r
59bc0593 18char mBuffer[65536];\r
4684b66f 19\r
20\r
b81cc7d6 21/** Translate the network name into an IP address\r
4684b66f 22\r
b81cc7d6
OM
23 @param[in] Argc The number of arguments\r
24 @param[in] Argv The argument value array\r
4684b66f 25\r
26 @retval 0 The application exited normally.\r
27 @retval Other An error occurred.\r
28**/\r
29int\r
30main (\r
31 IN int Argc,\r
32 IN char **Argv\r
33 )\r
34{\r
4684b66f 35 UINT8 * pIpAddress;\r
36 struct netent * pNetwork;\r
37\r
38 DEBUG (( DEBUG_INFO,\r
39 "%a starting\r\n",\r
40 Argv[0]));\r
41\r
4684b66f 42 // Determine if the network name is specified\r
4684b66f 43 if ( 1 == Argc ) {\r
44 Print ( L"%a <network name>\r\n", Argv[0]);\r
45 }\r
46 else {\r
4684b66f 47 // Translate the net name\r
4684b66f 48 pNetwork = getnetbyname ( Argv[1]);\r
49 if ( NULL == pNetwork ) {\r
50 Print ( L"ERROR - network not found, errno: %d\r\n", errno );\r
51 }\r
52 else {\r
53c31c51 53 pIpAddress = (UINT8 *)(UINTN)&pNetwork->n_net;\r
4684b66f 54 Print ( L"%a: Type %d, %d.%d.%d.%d\r\n",\r
55 pNetwork->n_name,\r
56 pNetwork->n_addrtype,\r
57 pIpAddress[0],\r
58 pIpAddress[1],\r
59 pIpAddress[2],\r
60 pIpAddress[3]);\r
61 }\r
62 }\r
4684b66f 63 // All done\r
4684b66f 64 return errno;\r
65}\r