]> git.proxmox.com Git - mirror_edk2.git/blob - AppPkg/Applications/Sockets/GetServByPort/GetServByPort.c
Add Socket Library applications.
[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, 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 <stdio.h>
18 #include <string.h>
19 #include <Uefi.h>
20 #include <unistd.h>
21
22 #include <Library/DebugLib.h>
23 #include <Library/UefiLib.h>
24
25 #include <sys/socket.h>
26
27 char mBuffer [65536];
28
29
30 /**
31 Translate the port number into a service name
32
33 @param [in] Argc The number of arguments
34 @param [in] Argv The argument value array
35
36 @retval 0 The application exited normally.
37 @retval Other An error occurred.
38 **/
39 int
40 main (
41 IN int Argc,
42 IN char **Argv
43 )
44 {
45 int AppStatus;
46 int PortNumber;
47 struct servent * pService;
48
49 //
50 // Determine if the service name is specified
51 //
52 AppStatus = 0;
53 if (( 2 != Argc )
54 || ( 1 != sscanf ( Argv[1], "%d", &PortNumber ))) {
55 Print ( L"%a <port number>\r\n", Argv[0]);
56 }
57 else {
58 //
59 // Translate the port number
60 //
61 pService = getservbyport ( htons ( PortNumber ), NULL );
62 if ( NULL == pService ) {
63 Print ( L"ERROR - service not found, errno: %d\r\n", errno );
64 }
65 else {
66 Print ( L"%a: %d, %a\r\n",
67 pService->s_name,
68 PortNumber,
69 pService->s_proto );
70 }
71 }
72
73 //
74 // All done
75 //
76 return errno;
77 }