4 #include <netinet/in.h>
11 int main(int argc, char **argv)
14 struct sockaddr_in psin;
18 fprintf(stderr, "Usage: %s <peer_ip> <peer_port> <file_name>\n", argv[0]);
22 printf("Opening AF_P2PKP socket\n");
24 sock = socket(AF_P2PKP, SOCK_DGRAM, 0);
25 printf("Socket returned: %d\n", sock);
28 printf("Cannot create AF_P2PKP socket: %s(%d)\n",
29 strerror(errno), errno);
32 printf("Successfully created AF_P2PKP socket: %d\n", sock);
36 host = gethostbyname(argv[0]);
37 psin.sin_family = AF_INET;
38 psin.sin_port = htons(atoi(argv[1]));
39 psin.sin_addr = *((struct in_addr *)host->h_addr);
41 if (bind(sock, (struct sockaddr *)&psin,
42 sizeof(struct sockaddr_in)) == -1) {
43 printf("Cannot bind to server: %s(%d)\n", strerror(errno), errno);
47 printf("Bound to: %s:%s\n", argv[0], argv[1]);
50 err = read(sock, argv[0], sizeof(argv[0]));
52 printf("Error while receiving file %s: %s(%d)\n", argv[0],
53 strerror(errno), errno);
57 printf("Successfully read file %s\n", argv[0]);