From 0543936bef46ef47a12601373a1cf16f0301d808 Mon Sep 17 00:00:00 2001 From: "David C. Jedlinsky" Date: Tue, 16 Jun 1987 20:36:31 +0000 Subject: Works on the client side. Uses internet port for both client and server. See rev. 1.1 to use unix domain sockets. --- zhm/zhm.c | 160 +++++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 97 insertions(+), 63 deletions(-) (limited to 'zhm/zhm.c') diff --git a/zhm/zhm.c b/zhm/zhm.c index d1c2848..7286f1a 100644 --- a/zhm/zhm.c +++ b/zhm/zhm.c @@ -1,4 +1,3 @@ - /* This file is part of the Project Athena Zephyr Notification System. * It contains the hostmanager client program. * @@ -23,9 +22,7 @@ static char rcsid_hm_c[] = "$Header$"; #include #include #include -#include - -#define CLIENT_SOCK "/tmp/*Z|&" /* :-) */ +#include #ifdef DEBUG #define DPR(a) fprintf(stderr, a) @@ -35,48 +32,47 @@ static char rcsid_hm_c[] = "$Header$"; #define DPR2(a,b) #endif -int serv_sock, recv_sock, cli_sock; +#define ever (;;) +#define Zperr(e) fprintf(stderr, "Error = %d\n", e) + +int serv_sock; +struct sockaddr_in cli_sin, serv_sin, from; extern int errno; main(argc, argv) char *argv[]; { - char buf[BUFSIZ]; struct hostent *hp; struct servent *sp; - struct sockaddr_in serv_sin; - struct sockaddr_in recv_sin; - struct sockaddr_un cli_sun; - - fd_set readable, copy; - int funix, cc, repl, nfound; - + int cli_port; + ZPacket_t packet; + ZNotice_t notice; + int auth, len; + Code_t repl; + char hostname[MAXHOSTNAMELEN]; if (argc < 2) { printf("Usage: %s server_machine\n", argv[0]); exit(-1); } + ZInitialize(); + gethostname(hostname, MAXHOSTNAMELEN); -/* Open a random socket here, using recv_sock, to talk to server */ - - - - if ((cli_sock = socket(PF_UNIX, SOCK_DGRAM, 0)) < 0) { - printf("client socket failed\n"); - exit(1); - } + /* Open client socket, for receiving client and server notices */ - /* bind the socket to Unix domain port on the local host */ - cli_sun.sun_family = AF_UNIX; - strcpy (cli_sun.sun_path, CLIENT_SOCK); + sp = getservbyname("zephyr-hm", "udp"); + cli_port = ntohs(sp->s_port); - if (bind(cli_sock, &cli_sun, strlen (cli_sun.sun_path) + 2) < 0) { - perror("bind"); - exit(1); + if ((repl = ZOpenPort(&cli_port)) != ZERR_NONE) { + Zperr(repl); + com_err("hm", repl, "opening port"); } + cli_sin = ZGetDestAddr(); + cli_sin.sin_port = sp->s_port; + /* Open the server socket */ sp = getservbyname("zephyr-clt", "udp"); serv_sin.sin_port = sp->s_port; @@ -87,7 +83,7 @@ char *argv[]; } DPR2 ("zephyr server port: %u\n", ntohs(serv_sin.sin_port)); - DPR2 ("zephyr client port: %s\n", cli_sun.sun_path); + DPR2 ("zephyr client port: %u\n", cli_port); /* This is here until hesiod or something that can find NS is put in */ @@ -103,34 +99,43 @@ char *argv[]; serv_sin.sin_family = AF_INET; bcopy(hp->h_addr, &serv_sin.sin_addr, hp->h_length); - sprintf(buf, "This message will be an ident. notice later.\n"); - - /* send it off */ - if ((cc = sendto(serv_sock, buf, strlen(buf) + 1, - 0, &recv_sin, sizeof(recv_sin))) < 0) - perror("sendto"); - else - printf("%d bytes sent\n",cc); - - FD_ZERO(&readable); - FD_SET(serv_sock, &readable); - FD_SET(cli_sock, &readable); - - do { - bcopy(&readable, ©, sizeof(fd_set)); - - /* Select on this port until response received */ - if ((repl = recvfrom(serv_sock, buf, sizeof(buf), - 0, &recv_sin, sizeof(recv_sin))) < 0) { - perror("recvfrom"); - find_next_server(&hp); + /* Set up server notice */ + notice.z_kind = ACK; + notice.z_checksum[0] = 0x100; + notice.z_checksum[1] = 0x200; + notice.z_port = (short) cli_port; + notice.z_class = "HMBOOT"; + notice.z_class_inst = hostname; + notice.z_opcode = "opcode"; + notice.z_sender = "sender"; + notice.z_recipient = "recip"; + notice.z_message_len = 0; + + /* send it off, using ZSendNotice */ + + + /* Sleep with wakeup call set */ + for ever { + DPR ("Waiting for a packet..."); + if ((repl = ZReceivePacket(packet, sizeof packet, + &len, &from)) != ZERR_NONE) { + Zperr(repl); + com_err("hm", repl, "receiving packet"); + } else { + if ((repl = ZParseNotice(packet, len, + ¬ice, &auth)) != ZERR_NONE) { + Zperr(repl); + com_err("hm", repl, "parsing notice"); + } + /* Where did it come from? */ + DPR ("Got a packet.\n"); + + /* Client program... */ + transmission_tower(¬ice); } - else - printf("reply: %s\n",buf); - } while (repl < 0); + + } - /* Right at end... */ - unlink(CLIENT_SOCK); } /* This will eventually use Hesiod */ @@ -150,16 +155,44 @@ ZNotice_t notice; printf("A notice came in from the server.\n"); } -client_manager(notice) -ZNotice_t notice; -{ - printf("A notice came in from a client.\n"); -} - -server_timeout() +transmission_tower(notice) +ZNotice_t *notice; { - perror ("server timed out.\n"); - exit(1); + ZNotice_t gack; + Code_t repl; + struct sockaddr_in gsin; + + gack = *notice; + DPR2 ("Message = %s\n", gack.z_message); + gack.z_kind = HMACK; + gack.z_message_len = 0; + /* Make library think the client is the HM */ + gsin = cli_sin; + gsin.sin_port = htons(gack.z_port); + if (gack.z_port == 0) { + gack.z_port = ntohs(from.sin_port); + gsin.sin_port = from.sin_port; + } + DPR2 ("Client Port = %u\n", gack.z_port); + if ((repl = ZSetDestAddr(&gsin)) != ZERR_NONE) { + Zperr(repl); + com_err("hm", repl, "setting destination"); + } + if ((repl = ZSendRawNotice(&gack)) != ZERR_NONE) { + Zperr(repl); + com_err("hm", repl, "sending raw notice"); + } + gsin = serv_sin; + DPR2 ("Server Port = %u\n", ntohs(gsin.sin_port)); + if ((repl = ZSetDestAddr(&gsin)) != ZERR_NONE) { + printf("Error = %d\n", repl); + com_err("hm", repl, "setting destination"); + } + if ((repl = ZSendRawNotice(notice)) != ZERR_NONE) { + printf("Error = %d\n", repl); + com_err("hm", repl, "while sending raw notice"); + } + add_notice_to_queue(notice); } new_server() @@ -167,3 +200,4 @@ new_server() perror("server going down.\n"); exit(1); } + -- cgit v1.2.3