started test client
[reposerve] / client / src / main.c
diff --git a/client/src/main.c b/client/src/main.c
new file mode 100644 (file)
index 0000000..a4c3cf5
--- /dev/null
@@ -0,0 +1,39 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+
+int main(int argc, char **argv)
+{
+       int s;
+       struct sockaddr_in addr;
+       struct hostent *host;
+
+       if((s = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
+               perror("failed to create socket");
+               return 1;
+       }
+
+       if(!(host = gethostbyname(argv[1]))) {
+               fprintf(stderr, "Can't find %s: %s\n", argv[1], hstrerror(h_errno));
+               return 1;
+       }
+
+       memset(&addr, 0, sizeof addr);
+       addr.sin_family = AF_INET;
+       addr.sin_port = htons(64357);
+       addr.sin_addr.s_addr = inet_addr(host->h_addr);
+
+       if(connect(s, (struct sockaddr*)&addr, sizeof addr) == -1) {
+               fprintf(stderr, "Failed to connect to %s: %s\n", argv[1], strerror(errno));
+               return 1;
+       }
+
+       close(s);
+       return 0;
+}