Add Socket Library applications.
[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, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. 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 **/
14
15 #include <errno.h>
16 #include <netdb.h>
17 #include <string.h>
18 #include <Uefi.h>
19 #include <unistd.h>
20
21 #include <Library/DebugLib.h>
22 #include <Library/UefiLib.h>
23
24 #include <sys/socket.h>
25
26 char mBuffer [65536];
27
28
29 /**
30 Translate the service name into a port number
31
32 @param [in] Argc The number of arguments
33 @param [in] Argv The argument value array
34
35 @retval 0 The application exited normally.
36 @retval Other An error occurred.
37 **/
38 int
39 main (
40 IN int Argc,
41 IN char **Argv
42 )
43 {
44 int AppStatus;
45 int PortNumber;
46 struct servent * pService;
47
48 //
49 // Determine if the service name is specified
50 //
51 AppStatus = 0;
52 if ( 1 == Argc ) {
53 Print ( L"%a <service name>\r\n", Argv[0]);
54 }
55 else {
56 //
57 // Translate the service name
58 //
59 pService = getservbyname ( Argv[1], NULL );
60 if ( NULL == pService ) {
61 Print ( L"ERROR - service not found, errno: %d\r\n", errno );
62 }
63 else {
64 PortNumber = htons ( pService->s_port );
65 Print ( L"%a: %d, %a\r\n",
66 pService->s_name,
67 PortNumber,
68 pService->s_proto );
69 }
70 }
71
72 //
73 // All done
74 //
75 return errno;
76 }