]>
Commit | Line | Data |
---|---|---|
4684b66f | 1 | /** @file\r |
2 | Translate the port number into a service name\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 <stdio.h>\r | |
18 | #include <string.h>\r | |
19 | #include <Uefi.h>\r | |
20 | #include <unistd.h>\r | |
21 | \r | |
22 | #include <Library/DebugLib.h>\r | |
23 | #include <Library/UefiLib.h>\r | |
24 | \r | |
25 | #include <sys/socket.h>\r | |
26 | \r | |
59bc0593 | 27 | char mBuffer[65536];\r |
4684b66f | 28 | \r |
29 | \r | |
30 | /**\r | |
31 | Translate the port number into a service name\r | |
32 | \r | |
33 | @param [in] Argc The number of arguments\r | |
34 | @param [in] Argv The argument value array\r | |
35 | \r | |
36 | @retval 0 The application exited normally.\r | |
37 | @retval Other An error occurred.\r | |
38 | **/\r | |
39 | int\r | |
40 | main (\r | |
41 | IN int Argc,\r | |
42 | IN char **Argv\r | |
43 | )\r | |
44 | {\r | |
45 | int AppStatus;\r | |
46 | int PortNumber;\r | |
47 | struct servent * pService;\r | |
48 | \r | |
49 | //\r | |
50 | // Determine if the service name is specified\r | |
51 | //\r | |
52 | AppStatus = 0;\r | |
53 | if (( 2 != Argc )\r | |
54 | || ( 1 != sscanf ( Argv[1], "%d", &PortNumber ))) {\r | |
55 | Print ( L"%a <port number>\r\n", Argv[0]);\r | |
56 | }\r | |
57 | else {\r | |
58 | //\r | |
59 | // Translate the port number\r | |
60 | //\r | |
61 | pService = getservbyport ( htons ( PortNumber ), NULL );\r | |
62 | if ( NULL == pService ) {\r | |
63 | Print ( L"ERROR - service not found, errno: %d\r\n", errno );\r | |
64 | }\r | |
65 | else {\r | |
66 | Print ( L"%a: %d, %a\r\n",\r | |
67 | pService->s_name,\r | |
68 | PortNumber,\r | |
69 | pService->s_proto );\r | |
70 | }\r | |
71 | }\r | |
72 | \r | |
73 | //\r | |
74 | // All done\r | |
75 | //\r | |
76 | return errno;\r | |
77 | }\r |