]> git.proxmox.com Git - mirror_edk2.git/blob - AppPkg/Applications/Sockets/GetNetByName/GetNetByName.c
AppPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / AppPkg / Applications / Sockets / GetNetByName / GetNetByName.c
1 /** @file
2 Translate the network name into an IP address
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 network name into an IP address
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 UINT8 * pIpAddress;
36 struct netent * pNetwork;
37
38 DEBUG (( DEBUG_INFO,
39 "%a starting\r\n",
40 Argv[0]));
41
42 // Determine if the network name is specified
43 if ( 1 == Argc ) {
44 Print ( L"%a <network name>\r\n", Argv[0]);
45 }
46 else {
47 // Translate the net name
48 pNetwork = getnetbyname ( Argv[1]);
49 if ( NULL == pNetwork ) {
50 Print ( L"ERROR - network not found, errno: %d\r\n", errno );
51 }
52 else {
53 pIpAddress = (UINT8 *)(UINTN)&pNetwork->n_net;
54 Print ( L"%a: Type %d, %d.%d.%d.%d\r\n",
55 pNetwork->n_name,
56 pNetwork->n_addrtype,
57 pIpAddress[0],
58 pIpAddress[1],
59 pIpAddress[2],
60 pIpAddress[3]);
61 }
62 }
63 // All done
64 return errno;
65 }