]> git.proxmox.com Git - mirror_edk2.git/blame - AppPkg/Applications/Sockets/GetServByName/GetServByName.c
AppPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / AppPkg / Applications / Sockets / GetServByName / GetServByName.c
CommitLineData
4684b66f 1/** @file\r
2 Translate the service name into a port number\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 <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
59bc0593 18char mBuffer[65536];\r
4684b66f 19\r
20\r
b81cc7d6 21/** Translate the service name into a port number\r
4684b66f 22\r
b81cc7d6
OM
23 @param[in] Argc The number of arguments\r
24 @param[in] Argv The argument value array\r
4684b66f 25\r
26 @retval 0 The application exited normally.\r
27 @retval Other An error occurred.\r
28**/\r
29int\r
30main (\r
31 IN int Argc,\r
32 IN char **Argv\r
33 )\r
34{\r
4684b66f 35 int PortNumber;\r
36 struct servent * pService;\r
37\r
4684b66f 38 // Determine if the service name is specified\r
4684b66f 39 if ( 1 == Argc ) {\r
40 Print ( L"%a <service name>\r\n", Argv[0]);\r
41 }\r
42 else {\r
4684b66f 43 // Translate the service name\r
4684b66f 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
4684b66f 56 // All done\r
4684b66f 57 return errno;\r
58}\r