summaryrefslogtreecommitdiff
path: root/ccan/net/_info
blob: cfa58f842830fd07ce4c89effa95e203e4248234 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "config.h"
#include <stdio.h>
#include <string.h>

/**
 * net - simple IPv4/IPv6 socket library
 *
 * This code makes it simple to support IPv4 and IPv6 without speed penalty
 * in clients by using non-blocking simultaneous connect, and using
 * a convenience function to create both IPv4 and IPv6 sockets for servers.
 *
 * License: MIT
 *
 * Author: Rusty Russell <rusty@rustcorp.com.au>
 *
 * Example:
 *	#include <ccan/net/net.h>
 *	#include <netinet/in.h>
 *	#include <stdio.h>
 *	#include <err.h>
 *
 *	int main(int argc, char *argv[])
 *	{
 *		struct addrinfo *addr;
 *		const char *dest, *port;
 *		int fd;
 *		union {
 *			struct sockaddr s;
 *			struct sockaddr_in v4;
 *			struct sockaddr_in6 v6;
 *		} u;
 *		socklen_t slen = sizeof(u);
 *	
 *		if (argc == 2) {
 *			dest = argv[1];
 *			port = "http";
 *		} else if (argc == 3) {
 *			dest = argv[1];
 *			port = argv[2];
 *		} else
 *			errx(1, "Usage: test-net <target> [<port>]");
 *	
 *		addr = net_client_lookup(dest, port, AF_UNSPEC, SOCK_STREAM);
 *		if (!addr)
 *			err(1, "Failed to look up %s", dest);
 *	
 *		fd = net_connect(addr);
 *		if (fd < 0)
 *			err(1, "Failed to connect to %s", dest);
 *		freeaddrinfo(addr);
 *	
 *		if (getsockname(fd, &u.s, &slen) == 0)
 *			printf("Connected via %s\n",
 *			       u.s.sa_family == AF_INET6 ? "IPv6"
 *			       : u.s.sa_family == AF_INET ? "IPv4"
 *			       : "UNKNOWN??");
 *		else
 *			err(1, "Failed to get socket type for connection");
 *		return 0;
 *	}
 */
int main(int argc, char *argv[])
{
	/* Expect exactly one argument */
	if (argc != 2)
		return 1;

	if (strcmp(argv[1], "depends") == 0) {
		printf("ccan/noerr\n");
		return 0;
	}

	return 1;
}