]>
Commit | Line | Data |
---|---|---|
4684b66f | 1 | /** @file\r |
2 | Translate the service name into a port number\r | |
3 | \r | |
b81cc7d6 OM |
4 | Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>\r |
5 | This program and the accompanying materials are licensed and made available under\r | |
6 | the terms and conditions of the BSD License that accompanies this distribution.\r | |
7 | The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php.\r | |
4684b66f | 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 | |
4684b66f | 12 | **/\r |
4684b66f | 13 | #include <errno.h>\r |
14 | #include <netdb.h>\r | |
15 | #include <string.h>\r | |
16 | #include <Uefi.h>\r | |
17 | #include <unistd.h>\r | |
18 | \r | |
19 | #include <Library/DebugLib.h>\r | |
20 | #include <Library/UefiLib.h>\r | |
21 | \r | |
22 | #include <sys/socket.h>\r | |
23 | \r | |
59bc0593 | 24 | char mBuffer[65536];\r |
4684b66f | 25 | \r |
26 | \r | |
b81cc7d6 | 27 | /** Translate the service name into a port number\r |
4684b66f | 28 | \r |
b81cc7d6 OM |
29 | @param[in] Argc The number of arguments\r |
30 | @param[in] Argv The argument value array\r | |
4684b66f | 31 | \r |
32 | @retval 0 The application exited normally.\r | |
33 | @retval Other An error occurred.\r | |
34 | **/\r | |
35 | int\r | |
36 | main (\r | |
37 | IN int Argc,\r | |
38 | IN char **Argv\r | |
39 | )\r | |
40 | {\r | |
4684b66f | 41 | int PortNumber;\r |
42 | struct servent * pService;\r | |
43 | \r | |
4684b66f | 44 | // Determine if the service name is specified\r |
4684b66f | 45 | if ( 1 == Argc ) {\r |
46 | Print ( L"%a <service name>\r\n", Argv[0]);\r | |
47 | }\r | |
48 | else {\r | |
4684b66f | 49 | // Translate the service name\r |
4684b66f | 50 | pService = getservbyname ( Argv[1], NULL );\r |
51 | if ( NULL == pService ) {\r | |
52 | Print ( L"ERROR - service not found, errno: %d\r\n", errno );\r | |
53 | }\r | |
54 | else {\r | |
55 | PortNumber = htons ( pService->s_port );\r | |
56 | Print ( L"%a: %d, %a\r\n",\r | |
57 | pService->s_name,\r | |
58 | PortNumber,\r | |
59 | pService->s_proto );\r | |
60 | }\r | |
61 | }\r | |
4684b66f | 62 | // All done\r |
4684b66f | 63 | return errno;\r |
64 | }\r |