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