1 /** @file
2   Translate the port number into a service name
3 
4   Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
5   This program and the accompanying materials are licensed and made available under
6   the terms and conditions of the BSD License that accompanies this distribution.
7   The full text of the license may be found at
8   http://opensource.org/licenses/bsd-license.php.
9 
10   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 **/
13 #include <errno.h>
14 #include <netdb.h>
15 #include <stdio.h>
16 #include <string.h>
17 #include <Uefi.h>
18 #include <unistd.h>
19 
20 #include <Library/DebugLib.h>
21 #include <Library/UefiLib.h>
22 
23 #include <sys/socket.h>
24 
25 char mBuffer[65536];
26 
27 
28 /** Translate the port number into a service name
29 
30   @param[in]  Argc  The number of arguments
31   @param[in]  Argv  The argument value array
32 
33   @retval  0        The application exited normally.
34   @retval  Other    An error occurred.
35 **/
36 int
main(IN int Argc,IN char ** Argv)37 main (
38   IN int Argc,
39   IN char **Argv
40   )
41 {
42   int PortNumber;
43   struct servent * pService;
44 
45   //  Determine if the service name is specified
46   if (( 2 != Argc )
47     || ( 1 != sscanf ( Argv[1], "%d", &PortNumber ))) {
48     Print ( L"%a  <port number>\r\n", Argv[0]);
49   }
50   else {
51     //  Translate the port number
52     pService = getservbyport ( htons ( PortNumber ), NULL );
53     if ( NULL == pService ) {
54       Print ( L"ERROR - service not found, errno: %d\r\n", errno );
55     }
56     else {
57       Print ( L"%a: %d, %a\r\n",
58               pService->s_name,
59               PortNumber,
60               pService->s_proto );
61     }
62   }
63   //  All done
64   return errno;
65 }
66