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