]> git.proxmox.com Git - mirror_edk2.git/blame - AppPkg/Applications/Sockets/GetServByPort/GetServByPort.c
EmbeddedPkg: Extend NvVarStoreFormattedLib LIBRARY_CLASS
[mirror_edk2.git] / AppPkg / Applications / Sockets / GetServByPort / GetServByPort.c
CommitLineData
4684b66f 1/** @file\r
2 Translate the port number into a service name\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 <stdio.h>\r
10#include <string.h>\r
11#include <Uefi.h>\r
12#include <unistd.h>\r
13\r
14#include <Library/DebugLib.h>\r
15#include <Library/UefiLib.h>\r
16\r
17#include <sys/socket.h>\r
18\r
59bc0593 19char mBuffer[65536];\r
4684b66f 20\r
21\r
b81cc7d6 22/** Translate the port number into a service name\r
4684b66f 23\r
b81cc7d6
OM
24 @param[in] Argc The number of arguments\r
25 @param[in] Argv The argument value array\r
4684b66f 26\r
27 @retval 0 The application exited normally.\r
28 @retval Other An error occurred.\r
29**/\r
30int\r
31main (\r
32 IN int Argc,\r
33 IN char **Argv\r
34 )\r
35{\r
4684b66f 36 int PortNumber;\r
37 struct servent * pService;\r
38\r
4684b66f 39 // Determine if the service name is specified\r
4684b66f 40 if (( 2 != Argc )\r
41 || ( 1 != sscanf ( Argv[1], "%d", &PortNumber ))) {\r
42 Print ( L"%a <port number>\r\n", Argv[0]);\r
43 }\r
44 else {\r
4684b66f 45 // Translate the port number\r
4684b66f 46 pService = getservbyport ( htons ( PortNumber ), NULL );\r
47 if ( NULL == pService ) {\r
48 Print ( L"ERROR - service not found, errno: %d\r\n", errno );\r
49 }\r
50 else {\r
51 Print ( L"%a: %d, %a\r\n",\r
52 pService->s_name,\r
53 PortNumber,\r
54 pService->s_proto );\r
55 }\r
56 }\r
4684b66f 57 // All done\r
4684b66f 58 return errno;\r
59}\r