| 1 |
/* |
| 2 |
* Copyright (c) 2002-2005, Network Appliance, Inc. All rights reserved. |
| 3 |
* |
| 4 |
* This Software is licensed under one of the following licenses: |
| 5 |
* |
| 6 |
* 1) under the terms of the "Common Public License 1.0" a copy of which is |
| 7 |
* in the file LICENSE.txt in the root directory. The license is also |
| 8 |
* available from the Open Source Initiative, see |
| 9 |
* http://www.opensource.org/licenses/cpl.php. |
| 10 |
* |
| 11 |
* 2) under the terms of the "The BSD License" a copy of which is in the file |
| 12 |
* LICENSE2.txt in the root directory. The license is also available from |
| 13 |
* the Open Source Initiative, see |
| 14 |
* http://www.opensource.org/licenses/bsd-license.php. |
| 15 |
* |
| 16 |
* 3) under the terms of the "GNU General Public License (GPL) Version 2" a |
| 17 |
* copy of which is in the file LICENSE3.txt in the root directory. The |
| 18 |
* license is also available from the Open Source Initiative, see |
| 19 |
* http://www.opensource.org/licenses/gpl-license.php. |
| 20 |
* |
| 21 |
* Licensee has the right to choose one of the above licenses. |
| 22 |
* |
| 23 |
* Redistributions of source code must retain the above copyright |
| 24 |
* notice and one of the license notices. |
| 25 |
* |
| 26 |
* Redistributions in binary form must reproduce both the above copyright |
| 27 |
* notice, one of the license notices in the documentation |
| 28 |
* and/or other materials provided with the distribution. |
| 29 |
*/ |
| 30 |
|
| 31 |
#include "dapl_proto.h" |
| 32 |
|
| 33 |
DAT_IA_ADDRESS_PTR DT_NetAddrAlloc(Per_Test_Data_t * pt_ptr) |
| 34 |
{ |
| 35 |
DAT_IA_ADDRESS_PTR netaddr; |
| 36 |
|
| 37 |
netaddr = (DAT_IA_ADDRESS_PTR) DT_Mdep_Malloc(sizeof(DAT_SOCK_ADDR)); |
| 38 |
if (!netaddr) { |
| 39 |
DT_Mdep_printf("dapltest: No Memory to create netaddr!\n"); |
| 40 |
} |
| 41 |
return netaddr; |
| 42 |
} |
| 43 |
|
| 44 |
void DT_NetAddrFree(Per_Test_Data_t * pt_ptr, DAT_IA_ADDRESS_PTR netaddr) |
| 45 |
{ |
| 46 |
DT_Mdep_Free(netaddr); |
| 47 |
} |
| 48 |
|
| 49 |
bool |
| 50 |
DT_NetAddrLookupHostAddress(DAT_IA_ADDRESS_PTR to_netaddr, |
| 51 |
DAT_NAME_PTR hostname) |
| 52 |
{ |
| 53 |
struct addrinfo *target; |
| 54 |
int rval; |
| 55 |
|
| 56 |
rval = getaddrinfo(hostname, NULL, NULL, &target); |
| 57 |
if (rval != 0) { |
| 58 |
char *whatzit = "unknown error return"; |
| 59 |
|
| 60 |
switch (rval) { |
| 61 |
case EAI_FAMILY: |
| 62 |
{ |
| 63 |
whatzit = "unsupported address family"; |
| 64 |
break; |
| 65 |
} |
| 66 |
case EAI_SOCKTYPE: |
| 67 |
{ |
| 68 |
whatzit = "unsupported socket type"; |
| 69 |
break; |
| 70 |
} |
| 71 |
case EAI_BADFLAGS: |
| 72 |
{ |
| 73 |
whatzit = "invalid flags"; |
| 74 |
break; |
| 75 |
} |
| 76 |
case EAI_NONAME: |
| 77 |
{ |
| 78 |
whatzit = "unknown node name"; |
| 79 |
break; |
| 80 |
} |
| 81 |
case EAI_SERVICE: |
| 82 |
{ |
| 83 |
whatzit = "service unavailable"; |
| 84 |
break; |
| 85 |
} |
| 86 |
#if !defined(WIN32) && defined(__USE_GNU) |
| 87 |
case EAI_ADDRFAMILY: |
| 88 |
{ |
| 89 |
whatzit = "node has no address in this family"; |
| 90 |
break; |
| 91 |
} |
| 92 |
case EAI_NODATA: |
| 93 |
{ |
| 94 |
whatzit = "node has no addresses defined"; |
| 95 |
break; |
| 96 |
} |
| 97 |
#endif |
| 98 |
case EAI_MEMORY: |
| 99 |
{ |
| 100 |
whatzit = "out of memory"; |
| 101 |
break; |
| 102 |
} |
| 103 |
case EAI_FAIL: |
| 104 |
{ |
| 105 |
whatzit = "permanent name server failure"; |
| 106 |
break; |
| 107 |
} |
| 108 |
case EAI_AGAIN: |
| 109 |
{ |
| 110 |
whatzit = "temporary name server failure"; |
| 111 |
break; |
| 112 |
} |
| 113 |
#if !defined(WIN32) |
| 114 |
case EAI_SYSTEM: |
| 115 |
{ |
| 116 |
whatzit = "system error"; |
| 117 |
break; |
| 118 |
} |
| 119 |
#endif |
| 120 |
} |
| 121 |
|
| 122 |
DT_Mdep_printf("getaddrinfo (%s) failed (%s)\n", |
| 123 |
hostname, whatzit); |
| 124 |
return DAT_FALSE; |
| 125 |
} |
| 126 |
|
| 127 |
/* Pull out IP address and print it as a sanity check */ |
| 128 |
DT_Mdep_printf("Server Name: %s \n", hostname); |
| 129 |
DT_Mdep_printf("Server Net Address: %s\n", |
| 130 |
inet_ntoa(((struct sockaddr_in *)target->ai_addr)-> |
| 131 |
sin_addr)); |
| 132 |
|
| 133 |
*to_netaddr = *((DAT_IA_ADDRESS_PTR) target->ai_addr); |
| 134 |
freeaddrinfo(target); |
| 135 |
|
| 136 |
return (DAT_TRUE); |
| 137 |
} |