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