File: sender.c

package info (click to toggle)
librecast 0.11.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,760 kB
  • sloc: ansic: 31,144; asm: 28,570; sh: 3,164; makefile: 713; python: 70
file content (46 lines) | stat: -rw-r--r-- 1,420 bytes parent folder | download
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
/* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only */
/* Copyright (c) 2025 Brett Sheffield <bacs@librecast.net> */

/* Librecast sender example */

#include <librecast.h>

int main(void)
{
	char data[] = "I have a dream";
	ssize_t bytes;
	int rc = EXIT_FAILURE;	/* pessimistic, aren't we? */

	/* we start with a Librecast Context (lc_ctx_t) */
	lc_ctx_t *lctx = lc_ctx_new();
	if (!lctx) return rc;
	/* create a Librecast Socket (IPv6) */
	lc_socket_t *sock = lc_socket_new(lctx);
	if (!sock) goto free_ctx;
	/* create a Librecast Channel */
	lc_channel_t *chan = lc_channel_new(lctx, "my very first Librecast channel");
	/* bind the Channel to the Socket */
	lc_channel_bind(sock, chan);
	/* enable loopback, so we receive our own packets on the same host */
	lc_socket_loop(sock, 1);
#if 0
	/* enable RaptorQ encoding (RFC6330) */
	lc_channel_coding_set(chan, LC_CODE_FEC_RQ | LC_CODE_FEC_OTI);
	lc_channel_rq_overhead(chan, RQ_OVERHEAD + 5);
#endif
	/* rate-limit sending */
	lc_channel_ratelimit(chan, 104857600 /* 100Mbps */ , 0);
	/* send some multicast data */
	bytes = lc_channel_send(chan, data, sizeof data, 0);
	if (bytes == -1) {
		perror("lc_channel_send");
		goto free_ctx;
	}
	printf("sent: '%s' (%zi bytes)\n", data, bytes);
	rc = EXIT_SUCCESS;
	/* free the Context. This also frees all Sockets, Channels, Routers etc.
	 * created with that Context */
free_ctx:
	lc_ctx_free(lctx);
	return rc;
}