-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_reg_host.c
88 lines (80 loc) · 2.45 KB
/
get_reg_host.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/******************************************************************************/
/* */
/* $Header: server.c,v 1.23 93/03/30 16:19:12 tine Exp $ */
/* */
/******************************************************************************/
# include <stdio.h>
# include <stdlib.h> /* fuer 'malloc()', 'exit()' */
# include <string.h> /* fuer 'strlen()', 'memset()' */
# include <sys/socket.h>
# include <netinet/in.h>
#include <netdb.h>
# include <arpa/inet.h>
# include <unistd.h> /* fuer 'getpid()', 'fork()' */
# include <sys/msg.h> /* fuer 'msgrcv()', msgsnd()' */
# include <fcntl.h>
# include <sys/types.h>
# include <sys/stat.h>
//# include <sys/mknod.h>
# include <sys/ipc.h>
#include <sys/param.h>
#include <sys/types.h>
char gui_host_file[BUFSIZ];
FILE *gui_host;
char *default_conf_dir = "/usr/local/tcl/conf";
char *default_host_name = "hosts";
char *progname = "addr_serv";
char line[BUFSIZ];
char program_name[BUFSIZ];
main (argc, argv)
int argc;
char *argv[];
{
char *tmp;
char host_name[BUFSIZ];
char *host_node;
struct hostent *host_entry;
struct in_addr my_inet_addr;
int nitems;
char *lp;
if ( (tmp = getenv("TCL")) == (char*) 0)
{
sprintf (gui_host_file, "%s/hosts",default_conf_dir);
}
else
{
sprintf (gui_host_file, "%s/conf/hosts",tmp);
}
gui_host = fopen(gui_host_file, "r");
if (gui_host == 0)
{
fprintf(stderr, "Datei %s konnte nicht geoeffnet werden\n",
gui_host_file);
exit (1);
}
while ((lp = fgets(line, sizeof(line), gui_host)) != NULL)
{
if ( ( nitems = sscanf( line, "%s %s", program_name, host_name)) == 2 )
{
if (strcmp (program_name, progname) == 0)
break;
}
}
if (lp == NULL)
{
fprintf(stderr, "Kein Eintrag %s in der Konfigurationsdatei %s \n",
progname, gui_host_file);
exit (1);
}
host_entry = gethostbyname(host_name);
if ( host_entry == NULL ) {
fprintf(stderr, "Unbekannter Rechner %s in der Konfigurationsdatei %s \n",
host_name, gui_host_file);
exit (1);
} else {
my_inet_addr.s_addr = *(unsigned long*) (host_entry->h_addr);
host_node = inet_ntoa(my_inet_addr);
printf("%s\n", host_node);
exit(0);
}
}