1
/*___INFO__MARK_BEGIN__*/
2
/*************************************************************************
4
* The Contents of this file are made available subject to the terms of
5
* the Sun Industry Standards Source License Version 1.2
7
* Sun Microsystems Inc., March, 2001
10
* Sun Industry Standards Source License Version 1.2
11
* =================================================
12
* The contents of this file are subject to the Sun Industry Standards
13
* Source License Version 1.2 (the "License"); You may not use this file
14
* except in compliance with the License. You may obtain a copy of the
15
* License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
17
* Software provided under this License is provided on an "AS IS" basis,
18
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
19
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
20
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
21
* See the License for the specific provisions governing your rights and
22
* obligations concerning the Software.
24
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
26
* Copyright: 2001 by Sun Microsystems, Inc.
28
* All Rights Reserved.
30
************************************************************************/
31
/*___INFO__MARK_END__*/
32
#include <sys/types.h>
33
#include <sys/socket.h>
34
#include <netinet/in.h>
35
#include <arpa/inet.h>
41
#include "comm/lists/cl_util.h"
42
#include "comm/cl_commlib.h"
44
#include "uti/sge_string.h"
45
#include "uti/sge_hostname.h"
46
#include "uti/sge_language.h"
50
#include "basis_types.h"
52
#include "msg_utilbin.h"
56
fprintf(stderr, "Version: %s\n", GDI_VERSION);
57
fprintf(stderr, "%s gethostbyname [-help|-name|-aname|-all] <name>\n",MSG_UTILBIN_USAGE);
61
int main(int argc, char *argv[]) {
62
struct hostent *he = NULL;
63
char* resolved_name = NULL;
64
int retval = CL_RETVAL_OK;
69
char* unresolved_name = NULL;
76
unresolved_name = argv[1];
78
if (!strcmp(argv[1], "-help")) {
81
if (!strcmp(argv[1], "-name")) {
86
unresolved_name = argv[2];
88
if (!strcmp(argv[1], "-aname")) {
94
unresolved_name = argv[2];
96
if (!strcmp(argv[1], "-all")) {
103
unresolved_name = argv[2];
106
retval = cl_com_setup_commlib(CL_NO_THREAD ,CL_LOG_OFF, NULL);
107
if (retval != CL_RETVAL_OK) {
108
fprintf(stderr,"%s\n", cl_get_error_text(retval));
113
const char *alias_path = sge_get_alias_path();
114
cl_com_set_alias_file(alias_path);
118
retval = cl_com_cached_gethostbyname(unresolved_name, &resolved_name, NULL, &he, &system_error);
120
if (retval != CL_RETVAL_OK) {
121
char* err_text = cl_com_get_h_error_string(system_error);
122
if (err_text == NULL) {
123
err_text = strdup(strerror(system_error));
124
if (err_text == NULL) {
125
err_text = strdup("unexpected error");
128
if (unresolved_name == NULL) {
129
unresolved_name = "NULL";
131
fprintf(stderr,"error resolving host "SFQ": %s (%s)\n",unresolved_name,cl_get_error_text(retval),err_text );
134
cl_com_cleanup_commlib();
140
if (resolved_name != NULL) {
141
printf("%s\n",resolved_name);
143
printf("%s\n","unexpected error");
147
printf("%s\n",he->h_name);
149
printf("%s\n","could not get hostent struct");
154
printf(MSG_SYSTEM_HOSTNAMEIS_S , he->h_name);
157
if (resolved_name != NULL && all_option) {
158
printf("SGE name: %s\n",resolved_name);
161
printf(MSG_SYSTEM_ALIASES );
163
for (tp = he->h_aliases; *tp; tp++)
167
printf(MSG_SYSTEM_ADDRESSES );
168
for (tp2 = he->h_addr_list; *tp2; tp2++)
169
printf("%s ", inet_ntoa(* (struct in_addr *) *tp2)); /* inet_ntoa() is not MT save */
172
fprintf(stderr,"%s\n","could not get hostent struct");
176
sge_free_hostent(&he);
178
retval = cl_com_cleanup_commlib();
179
if (retval != CL_RETVAL_OK) {
180
fprintf(stderr,"%s\n",cl_get_error_text(retval));