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 "basis_types.h"
42
#include "msg_utilbin.h"
43
#include "sge_string.h"
45
#include "sge_hostname.h"
46
#include "cl_commlib.h"
51
fprintf(stderr, "Version: %s\n", GDI_VERSION);
52
fprintf(stderr, "%s\n gethostname [-help|-name|-aname|-all]\n\n%s\n", MSG_UTILBIN_USAGE, MSG_COMMAND_USAGE_GETHOSTNAME );
57
int main(int argc,char *argv[]) {
58
struct hostent *he = NULL;
59
char* resolved_name = NULL;
60
int retval = CL_RETVAL_OK;
71
if (!strcmp(argv[1], "-help")) {
74
if (!strcmp(argv[1], "-name")) {
80
if (!strcmp(argv[1], "-aname")) {
87
if (!strcmp(argv[1], "-all")) {
97
if (name_only == 0 && argc != 1 && all_option == 0) {
101
retval = cl_com_setup_commlib(CL_NO_THREAD ,CL_LOG_OFF, NULL);
102
if (retval != CL_RETVAL_OK) {
103
fprintf(stderr,"%s\n",cl_get_error_text(retval));
108
const char *alias_path = sge_get_alias_path();
109
cl_com_set_alias_file(alias_path);
113
retval = cl_com_gethostname(&resolved_name, NULL, &he, &system_error);
114
if (retval != CL_RETVAL_OK) {
115
char* err_text = cl_com_get_h_error_string(system_error);
116
if (err_text == NULL) {
117
err_text = strdup(strerror(system_error));
118
if (err_text == NULL) {
119
err_text = strdup("unexpected error");
122
fprintf(stderr,"error resolving local host: %s (%s)\n",cl_get_error_text(retval), err_text);
125
cl_com_cleanup_commlib();
132
if (resolved_name != NULL) {
133
printf("%s\n",resolved_name);
135
printf("%s\n","unexpected error");
139
printf("%s\n",he->h_name);
141
printf("%s\n","could not get hostent struct");
146
printf(MSG_SYSTEM_HOSTNAMEIS_S , he->h_name);
149
if (resolved_name != NULL && all_option) {
150
printf("SGE name: %s\n",resolved_name);
153
printf(MSG_SYSTEM_ALIASES );
155
for (tp = he->h_aliases; *tp; tp++)
159
printf(MSG_SYSTEM_ADDRESSES );
160
for (tp2 = he->h_addr_list; *tp2; tp2++)
161
printf("%s ", inet_ntoa(* (struct in_addr *) *tp2)); /* inet_ntoa() is not MT save */
164
fprintf(stderr,"%s\n","could not get hostent struct");
168
sge_free_hostent(&he);
170
retval = cl_com_cleanup_commlib();
171
if (retval != CL_RETVAL_OK) {
172
fprintf(stderr,"%s\n",cl_get_error_text(retval));