]>
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, 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
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.
22 #include <Library/DebugLib.h>
23 #include <Library/UefiLib.h>
25 #include <sys/socket.h>
28 Translate the IPv4 address into a network name
30 @param [in] Argc The number of arguments
31 @param [in] Argv The argument value array
33 @retval 0 The application exited normally.
34 @retval Other An error occurred.
42 UINT32 RemoteAddress
[4];
44 struct netent
* pNetwork
;
47 // Determine if the IPv4 address is specified
50 || ( 4 != sscanf ( Argv
[1],
56 || ( 255 < RemoteAddress
[0])
57 || ( 255 < RemoteAddress
[1])
58 || ( 255 < RemoteAddress
[2])
59 || ( 255 < RemoteAddress
[3])) {
60 Print ( L
"%a <IPv4 Address>\r\n", Argv
[0]);
64 // Translate the address into a network name
66 IpAddress
[0] = (UINT8
)RemoteAddress
[0];
67 IpAddress
[1] = (UINT8
)RemoteAddress
[1];
68 IpAddress
[2] = (UINT8
)RemoteAddress
[2];
69 IpAddress
[3] = (UINT8
)RemoteAddress
[3];
70 pNetwork
= getnetbyaddr ( *(uint32_t *)&IpAddress
[0], AF_INET
);
71 if ( NULL
== pNetwork
) {
72 Print ( L
"ERROR - network not found, errno: %d\r\n", errno
);
75 Print ( L
"%a: %d.%d.%d.%d, 0x%08x\r\n",