]>
git.proxmox.com Git - mirror_edk2.git/blob - AppPkg/Applications/Sockets/GetNetByAddr/GetNetByAddr.c
2 Translate the IPv4 address into a network name
4 Copyright (c) 2011-2012, Intel Corporation. All rights reserved.
5 SPDX-License-Identifier: BSD-2-Clause-Patent
16 #include <Library/DebugLib.h>
17 #include <Library/UefiLib.h>
19 #include <sys/socket.h>
22 Translate the IPv4 address into a network name
24 @param [in] Argc The number of arguments
25 @param [in] Argv The argument value array
27 @retval 0 The application exited normally.
28 @retval Other An error occurred.
36 UINT32 RemoteAddress
[4];
38 struct netent
* pNetwork
;
41 // Determine if the IPv4 address is specified
44 || ( 4 != sscanf ( Argv
[1],
50 || ( 255 < RemoteAddress
[0])
51 || ( 255 < RemoteAddress
[1])
52 || ( 255 < RemoteAddress
[2])
53 || ( 255 < RemoteAddress
[3])) {
54 Print ( L
"%a <IPv4 Address>\r\n", Argv
[0]);
58 // Translate the address into a network name
60 IpAddress
[0] = (UINT8
)RemoteAddress
[0];
61 IpAddress
[1] = (UINT8
)RemoteAddress
[1];
62 IpAddress
[2] = (UINT8
)RemoteAddress
[2];
63 IpAddress
[3] = (UINT8
)RemoteAddress
[3];
64 pNetwork
= getnetbyaddr ( *(uint32_t *)&IpAddress
[0], AF_INET
);
65 if ( NULL
== pNetwork
) {
66 Print ( L
"ERROR - network not found, errno: %d\r\n", errno
);
69 Print ( L
"%a: %d.%d.%d.%d, 0x%08x\r\n",