home *** CD-ROM | disk | FTP | other *** search
- #ifndef lint
- static char *RCSid = "$Header: driver.c,v 1.5 87/06/24 15:02:38 mike Rel $";
- #endif
-
- /* driver --
- drive the IEN 116 nameserver.
-
- Written by Michael I. Bushnell.
- Copyright (c) 1987 Michael I. Bushnell
- You are hereby granted permission to use this program however you wish,
- including copying and distribution. However, you are obligated not to sell
- it or any part of it. Anyone who obtains this program receives the right
- to do the same. This statement may not be removed from this program.
- */
-
- /*
- * $Source: /u1/staff/mike/src/nameserver/RCS/driver.c,v $
- * $Revision: 1.5 $
- * $Date: 87/06/24 15:02:38 $
- * $State: Rel $
- * $Author: mike $
- * $Locker: $
- * $Log: driver.c,v $
- * Revision 1.5 87/06/24 15:02:38 mike
- * Prepared for final release. Added Copyright.
- *
- * Revision 1.4 87/06/19 17:00:05 mike
- * More toying around.
- *
- * Revision 1.3 87/06/19 14:44:13 mike
- * Toyed around.
- *
- * Revision 1.2 87/06/15 13:50:51 mike
- * Changed the host it asks for
- *
- * Revision 1.1 87/06/12 13:42:29 mike
- * Initial revision
- *
- */
-
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <stdio.h>
- #include <netdb.h>
-
- #define PORT 5001
- #define BUFLEN 256
- char buf[BUFLEN];
-
- /* Driver for the IEN 116 nameserver */
-
- main()
- {
- int sock; /* Datagram socket */
- struct sockaddr_in from; /* Where we got the reply from */
- struct sockaddr_in server; /* Server's address */
- struct sockaddr_in ourname; /* Our address */
- int addrlen; /* Address length */
- int c,i; /* Generic counters */
-
-
- sock = socket(AF_INET, SOCK_DGRAM, 0);
- if (sock < 0)
- {
- perror("driver: opening socket");
- exit (1);
- }
- ourname.sin_family = AF_INET;
- ourname.sin_port = 0;
- ourname.sin_addr.s_addr = INADDR_ANY;
- if (bind(sock, (struct sockaddr *)&ourname, sizeof(ourname)))
- {
- perror("driver: binding socket");
- exit(1);
- }
-
- server.sin_family = AF_INET;
- server.sin_port = PORT;
- server.sin_addr.s_addr = INADDR_ANY;
-
- /* stick in whatever machine you want here */
- buf[0] = 1; /* Code for request */
- buf[1] = 8; /* Length of message */
- buf[2] = 'c';
- buf[3] = 'h';
- buf[4] = 'a';
- buf[5] = 'r';
- buf[6] = 'o';
- buf[7] = 'n';
-
- if (sendto(sock, buf, 8, 0, (struct sockaddr *)&server, sizeof(server))==-1)
- {
- perror("driver: sending message");
- exit(1);
- }
-
- if ((c=recvfrom(sock, buf, BUFLEN, 0, (struct sockaddr *)&from, sizeof(from)))==-1)
- {
- perror("driver: getting message");
- exit(1);
- }
-
- for(i=0;i<c; ++i)
- putchar(buf[i]);
- }
-