]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | Translate the service name into a port number\r | |
3 | \r | |
4 | Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>\r | |
5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
6 | **/\r | |
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 | |
18 | char mBuffer[65536];\r | |
19 | \r | |
20 | \r | |
21 | /** Translate the service name into a port number\r | |
22 | \r | |
23 | @param[in] Argc The number of arguments\r | |
24 | @param[in] Argv The argument value array\r | |
25 | \r | |
26 | @retval 0 The application exited normally.\r | |
27 | @retval Other An error occurred.\r | |
28 | **/\r | |
29 | int\r | |
30 | main (\r | |
31 | IN int Argc,\r | |
32 | IN char **Argv\r | |
33 | )\r | |
34 | {\r | |
35 | int PortNumber;\r | |
36 | struct servent * pService;\r | |
37 | \r | |
38 | // Determine if the service name is specified\r | |
39 | if ( 1 == Argc ) {\r | |
40 | Print ( L"%a <service name>\r\n", Argv[0]);\r | |
41 | }\r | |
42 | else {\r | |
43 | // Translate the service name\r | |
44 | pService = getservbyname ( Argv[1], NULL );\r | |
45 | if ( NULL == pService ) {\r | |
46 | Print ( L"ERROR - service not found, errno: %d\r\n", errno );\r | |
47 | }\r | |
48 | else {\r | |
49 | PortNumber = htons ( pService->s_port );\r | |
50 | Print ( L"%a: %d, %a\r\n",\r | |
51 | pService->s_name,\r | |
52 | PortNumber,\r | |
53 | pService->s_proto );\r | |
54 | }\r | |
55 | }\r | |
56 | // All done\r | |
57 | return errno;\r | |
58 | }\r |