be81b3483d26612fdfb3f6ca34689fd21712f77d
[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, 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 network name into an IP address
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 UINT8 * pIpAddress;
46 struct netent * pNetwork;
47
48 DEBUG (( DEBUG_INFO,
49 "%a starting\r\n",
50 Argv[0]));
51
52 //
53 // Determine if the network name is specified
54 //
55 AppStatus = 0;
56 if ( 1 == Argc ) {
57 Print ( L"%a <network name>\r\n", Argv[0]);
58 }
59 else {
60 //
61 // Translate the net name
62 //
63 pNetwork = getnetbyname ( Argv[1]);
64 if ( NULL == pNetwork ) {
65 Print ( L"ERROR - network not found, errno: %d\r\n", errno );
66 }
67 else {
68 pIpAddress = (UINT8 *)pNetwork->n_net;
69 Print ( L"%a: Type %d, %d.%d.%d.%d\r\n",
70 pNetwork->n_name,
71 pNetwork->n_addrtype,
72 pIpAddress[0],
73 pIpAddress[1],
74 pIpAddress[2],
75 pIpAddress[3]);
76 }
77 }
78
79 //
80 // All done
81 //
82 return errno;
83 }