コード例 #1
0
ファイル: test_main.c プロジェクト: deval-maker/rtems-libbsd
static void *
foobar_thread(void *arg)
{
	static const char foobar[] = "FooBar!";

	mDNSu16 port = FOOBAR_PORT_BEGIN;

	while (1) {
		ServiceRecordSet *srs;
		struct sockaddr_in addr;
		struct sockaddr_in addr2;
		socklen_t addr2_len;
		int sd;
		int sd2;
		int rv;
		ssize_t n;

		sd = socket(PF_INET, SOCK_STREAM, 0);
		assert(sd >= 0);

		memset(&addr, 0, sizeof(addr));
		addr.sin_family = AF_INET;
		addr.sin_port = htons(port);
		addr.sin_addr.s_addr = htonl(INADDR_ANY);

		rv = bind(sd, (const struct sockaddr *) &addr, sizeof(addr));
		assert(rv == 0);

		rv = listen(sd, 0);
		assert(rv == 0);

		srs = foobar_register(port);

		addr2_len = sizeof(addr2);
		sd2 = accept(sd, (struct sockaddr *) &addr2, &addr2_len);
		assert(sd2 >= 0);

		n = write(sd2, &foobar[0], sizeof(foobar));
		assert(n == (ssize_t) sizeof(foobar));

		foobar_deregister(srs);

		rv = close(sd2);
		assert(rv == 0);

		rv = close(sd);
		assert(rv == 0);

		if (port < FOOBAR_PORT_END) {
			++port;
		} else {
			port = FOOBAR_PORT_BEGIN;
		}
	}

	return NULL;
}
コード例 #2
0
ファイル: test_main.c プロジェクト: deval-maker/rtems-libbsd
static void
test_main(void)
{
	const char name[] = "foobarclient";
	int rv;
	DNSQuestion question;
	rtems_status_code sc;

	rv = sethostname(&name[0], sizeof(name) - 1);
	assert(rv == 0);

	sc = rtems_mdns_initialize(254, &rr_cache[0], RTEMS_ARRAY_SIZE(rr_cache));
	assert(sc == RTEMS_SUCCESSFUL);

	foobar_register(&question);

	rtems_task_delete(RTEMS_SELF);
	assert(0);
}
コード例 #3
0
ファイル: test_main.c プロジェクト: scclancy/rtems-libbsd
static void
test_main(void)
{
	mStatus status;
	DNSQuestion question;

	status = mDNS_Init(&mDNSStorage, &PlatformStorage, &rr_cache[0],
	    sizeof(rr_cache) / sizeof(rr_cache[0]),
	    mDNS_Init_DontAdvertiseLocalAddresses, mDNS_Init_NoInitCallback,
	    mDNS_Init_NoInitCallbackContext);
	assert(status == mStatus_NoError);

	foobar_register(&question);

	while (1) {
		struct timeval timeout = { .tv_sec = 0x3fffffff, .tv_usec = 0 };
		sigset_t signals;
		mDNSBool got_something;

		mDNSPosixRunEventLoopOnce(&mDNSStorage, &timeout, &signals, &got_something);
	}
}