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