---
name: "lc_sync"
section: "3"
platform: "linux"
package: "liblibrecast-dev"
version: "0.9.1-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/lc_sync"
---

# lc\_sync(3)

synchronize memory or files over multicast

## NAME

lc\_sync, lc\_syncfile - synchronize memory or files over multicast

## LIBRARY

Librecast library (*liblibrecast*, *-llibrecast*)

## SYNOPSIS

```
#include <librecast/sync.h>
```

**ssize\_t lc\_sync(lc\_ctx\_t** *\*lctx***, unsigned char** *\*hash***, void** *\*data***, const size\_t** *len***,**                 **q\_t** *\*q***, lc\_stat\_t** *\*stats***, lc\_sync\_options\_t** *\*opt***, int** *flags***);** **ssize\_t lc\_syncfile(lc\_ctx\_t** *\*lctx***, unsigned char** *\*hash***, const char** *\*pathname***,**                 **q\_t** *\*q***, lc\_stat\_t** *\*stats***, lc\_sync\_options\_t** *\*opt***, int** *flags***);**

Compile and link with *-llibrecast*.

## DESCRIPTION

The **lc\_sync**() function synchronizes the memory area pointed to by *data* of length *len* with data fetched from the network.

The **lc\_syncfile**() synchronizes the file at *pathname* with with data fetched from the network. The file will be created if it does not exist.

*hash* is used to create the multicast address from which to fetch the merkle tree of the source data.  This tree is compared to the merkle tree of the memory at *data* to find which chunks differ, and these chunks are fetched from the network using their hashes to create the multicast source addresses.

*lctx* is a Librecast context, created with [**lc\_ctx\_new**(3)](/lc_ctx_new/3.md).

If *q* is not NULL, it must point to a queue *q\_t* structure previously initialized with [**q\_init**(3)](/q_init/3.md). This queue will have jobs enqueued to build the tree. This is normally used in conjunction with a threadpool created with [**q\_pool\_create**(3)](/q_pool_create/3.md) with threads all calling [**q\_job\_seek**(3)](/q_job_seek/3.md).

If *q* is NULL, the creation and destruction of a queue and threadpool will be handled automatically.

If *stats* is not NULL, transfer statistics will be returned in this structure.

*opt* is not used, at present, and must be NULL for compatibility with future versions.

*flags* is not used, at present, and must be zero for compatibility with future versions.

## RETURN VALUE

These calls return the number of bytes received, or -1 if an error occurred. On error, NULL is returned, and *errno* is set to indicate the error.

## ERRORS

- **EINVAL**

  Invalid argument.

**ENOMEM** Not enough space/cannot allocate memory (POSIX.1-2001).

**EACCES** Permission to create a socket of the specified type and/or protocol is denied.

**lc\_syncfile**() can also fail with any of the errors for [**lc\_mmapfile**(3)](/lc_mmapfile/3.md).

## NOTES

To restrict syncing to a particular network interface, call [**lc\_ctx\_ifx**(3)](/lc_ctx_ifx/3.md) to set the default interface for the Librecast context before calling the appropriate sync function.

## SEE ALSO

[**lc\_ctx\_new**(3)](/lc_ctx_new/3.md), [**lc\_ctx\_ifx**(3)](/lc_ctx_ifx/3.md), [**lc\_mmapfile**(3)](/lc_mmapfile/3.md), [**lc\_share**(3)](/lc_share/3.md), [**mdex\_init**(3)](/mdex_init/3.md), [**mdex\_free**(3)](/mdex_free/3.md), [**mdex\_add**(3)](/mdex_add/3.md), [**mdex\_addfile**(3)](/mdex_addfile/3.md), [**mdex\_alias**(3)](/mdex_alias/3.md), [**mdex\_get**(3)](/mdex_get/3.md), [**mdex\_put**(3)](/mdex_put/3.md), [**mdex\_del**(3)](/mdex_del/3.md), [**lcrq**(7)](/lcrq/7.md)
