a4c3cf55fc7e8622fa713a2d00694b47463ebdef
[reposerve] / client / src / main.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <errno.h>
5 #include <unistd.h>
6 #include <sys/socket.h>
7 #include <netinet/in.h>
8 #include <arpa/inet.h>
9 #include <netdb.h>
10
11 int main(int argc, char **argv)
12 {
13         int s;
14         struct sockaddr_in addr;
15         struct hostent *host;
16
17         if((s = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
18                 perror("failed to create socket");
19                 return 1;
20         }
21
22         if(!(host = gethostbyname(argv[1]))) {
23                 fprintf(stderr, "Can't find %s: %s\n", argv[1], hstrerror(h_errno));
24                 return 1;
25         }
26
27         memset(&addr, 0, sizeof addr);
28         addr.sin_family = AF_INET;
29         addr.sin_port = htons(64357);
30         addr.sin_addr.s_addr = inet_addr(host->h_addr);
31
32         if(connect(s, (struct sockaddr*)&addr, sizeof addr) == -1) {
33                 fprintf(stderr, "Failed to connect to %s: %s\n", argv[1], strerror(errno));
34                 return 1;
35         }
36
37         close(s);
38         return 0;
39 }