#include	<stdio.h>
#include	"actived.h"
#include	"protocol.h"


int main(argc, argv)
int argc;
char *argv[];
{
	int s, i;
	int start = time(NULL) - 1;
	struct wireprotocol buffer;

	if ((s = create_udp_socket(0)) < 0) {
		fprintf(stderr, "couldnt create socket\n");
		exit(1);
	}
	if (connect_udp_socket(s, "localhost", 1119) < 0) {
		fprintf(stderr, "couldnt connect socket\n");
		exit(1);
	}
	i = 0;
	buffer.RequestType = REQ_FIND;
	buffer.RequestID = getpid();
	sprintf(buffer.Name, argv[1]);

	fprintf(stderr, "asking question: request-id %d, group \"%s\"\n\n", buffer.RequestID, buffer.Name);

	if (write_udp(s, (char *)&buffer, sizeof(buffer)) < 0) {
		fprintf(stderr, "couldnt write packet\n");
		exit(1);
	}
	if (read_udp(s, (char *)&buffer, sizeof(buffer)) != sizeof(buffer)) {
		fprintf(stderr, "couldnt read packet\n");
		exit(1);
	}
	fprintf(stderr, "request-id ok?         %s (%d)\n", buffer.RequestID == getpid() ? "yes" : "no", buffer.RequestID);
	fprintf(stderr, "response type correct? %s (%d)\n", buffer.RequestType == REQ_FINDRESP ? "yes" : "no", buffer.RequestType);
	fprintf(stderr, "success?               %s\n", buffer.Success ? "yes" : "no");
	fprintf(stderr, "name?                  %s\n", buffer.NameNull ? "<NULL>" : buffer.Name);
	fprintf(stderr, "alias?                 %s\n", buffer.AliasNull ? "<NULL>" : buffer.Alias);
	fprintf(stderr, "range?                 %d-%d\n", buffer.Low, buffer.High);
	fprintf(stderr, "flag?                  %c\n", buffer.Flag);
}




