00001
00002 #include "gateway_rpc.h"
00003 #include "gateway_prot.h"
00004 #include <netdb.h>
00005 #include <string.h>
00006 #include <stdio.h>
00007
00008 static const int DHT_PORT = 5852;
00009
00011
00012
00013
00014 int
00015 lookup_host(const char* host, int port, struct sockaddr_in* addr)
00016 {
00017 struct hostent* h = gethostbyname (host);
00018 if (h == NULL) return 0;
00019
00020 bzero (addr, sizeof(struct sockaddr_in));
00021 addr->sin_family = AF_INET;
00022 addr->sin_port = htons(port);
00023
00024
00025
00026 memcpy(&addr->sin_addr, h->h_addr, sizeof(struct in_addr));
00027 return 1;
00028 }
00029
00030
00031
00032 CLIENT*
00033 get_connection(struct sockaddr_in* addr)
00034 {
00035 int sockp = RPC_ANYSOCK;
00036 CLIENT * c = clnttcp_create(addr, BAMBOO_DHT_GATEWAY_PROGRAM,
00037 BAMBOO_DHT_GATEWAY_VERSION, &sockp, 0, 0);
00038 return c;
00039 }
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 int
00056 do_null_op(CLIENT* c)
00057 {
00058 void* null_args = NULL;
00059 void* res = bamboo_dht_proc_null_2(&null_args, c);
00060 return (res != NULL);
00061 }
00062
00063
00064
00065
00066 int
00067 test_node(const char* hostname, struct sockaddr_in* addr)
00068 {
00069 printf(" testing dht node %s... ", hostname);
00070
00071
00072 if (!lookup_host(hostname, DHT_PORT, addr))
00073 {
00074 printf("lookup_host failed\n");
00075 return 0;
00076 }
00077
00078
00079
00080
00081 CLIENT* p_client = get_connection(addr);
00082 if (p_client == NULL)
00083 {
00084 printf("get_connection failed\n");
00085 return 0;
00086 }
00087
00088
00089 if (!do_null_op(p_client))
00090 {
00091 printf("null_op failed\n");
00092 clnt_destroy(p_client);
00093 return 0;
00094 }
00095
00096 printf("succeeded.\n");
00097 clnt_destroy(p_client);
00098 return 1;
00099 }