GetServByPort.c revision 4fd606d1f5abe38e1f42c38de1d2e895166bd0f4
1N/A/** @file
1N/A Translate the port number into a service name
1N/A
1N/A Copyright (c) 2011, Intel Corporation
1N/A All rights reserved. This program and the accompanying materials
1N/A are licensed and made available under the terms and conditions of the BSD License
1N/A which accompanies this distribution. The full text of the license may be found at
1N/A http://opensource.org/licenses/bsd-license.php
1N/A
1N/A THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
1N/A WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
1N/A
1N/A**/
1N/A
1N/A#include <errno.h>
1N/A#include <netdb.h>
1N/A#include <stdio.h>
1N/A#include <string.h>
1N/A#include <Uefi.h>
1N/A#include <unistd.h>
1N/A
1N/A#include <Library/DebugLib.h>
1N/A#include <Library/UefiLib.h>
1N/A
1N/A#include <sys/socket.h>
1N/A
1N/Achar mBuffer[65536];
1N/A
1N/A
1N/A/**
1N/A Translate the port number into a service name
1N/A
1N/A @param [in] Argc The number of arguments
1N/A @param [in] Argv The argument value array
1N/A
1N/A @retval 0 The application exited normally.
1N/A @retval Other An error occurred.
1N/A**/
1N/Aint
1N/Amain (
1N/A IN int Argc,
1N/A IN char **Argv
1N/A )
1N/A{
1N/A int AppStatus;
1N/A int PortNumber;
1N/A struct servent * pService;
1N/A
1N/A //
1N/A // Determine if the service name is specified
1N/A //
1N/A AppStatus = 0;
1N/A if (( 2 != Argc )
1N/A || ( 1 != sscanf ( Argv[1], "%d", &PortNumber ))) {
1N/A Print ( L"%a <port number>\r\n", Argv[0]);
1N/A }
1N/A else {
1N/A //
1N/A // Translate the port number
1N/A //
1N/A pService = getservbyport ( htons ( PortNumber ), NULL );
1N/A if ( NULL == pService ) {
Print ( L"ERROR - service not found, errno: %d\r\n", errno );
}
else {
Print ( L"%a: %d, %a\r\n",
pService->s_name,
PortNumber,
pService->s_proto );
}
}
//
// All done
//
return errno;
}