2
1
Fork
You've already forked liblnpp
0
LNPP protocol library for implementing clients & servers.
  • C 98.2%
  • Meson 1.8%
2025年12月13日 14:31:23 +03:00
LICENSE.txt Added license 2025年12月12日 02:02:49 +03:00
lnpp.c Lowered lnpp.h standard to C11 2025年12月13日 14:31:23 +03:00
lnpp.h Lowered lnpp.h standard to C11 2025年12月13日 14:31:23 +03:00
meson.build Added pkg-config to the build system 2025年12月13日 13:32:54 +03:00
README.md Lowered lnpp.h standard to C11 2025年12月13日 14:31:23 +03:00
test_lnpp.c enum lnpp_result -> enum lnpp_decode_status 2025年12月13日 13:04:55 +03:00

Overview

liblnpp — a reference implementation of the LNPP protocol. Has an interface suited for implementing both clients and servers. Implemented with 100% compliance to the LNPP specification.

Features

  • Implemented in C using C23 standard.
  • Very minimalistic (<700 LOC).
  • No dependencies except libc.
  • Header file doesn't depend on libc.
  • Header file is compatible with C11 standard.
  • Doesn't do any system calls. Therefore, doesn't do networking nor memory allocations, allowing to use library with any IO and memory model.
  • Only implements message parsing/rendering part, keeping things simple.

Building

This project consists of the following files:

  • "lnpp.h" — header file for library users;
  • "lnpp.c" — implementation of "lnpp.h";
  • "test_lnpp.c" — unit tests for "lnpp.h" utilizing CUnit.

This project uses Meson build system.

Although even if you don't have/don't want to use Meson, building liblnpp without that is extremely simple. Simply compile "lnpp.c" to get a usable .o file for your project, or a shared library:

cc lnpp.c -std=c23 -D_DEFAULT_SOURCE -c -o lnpp.o
cc lnpp.c -std=c23 -D_DEFAULT_SOURCE -shared -o liblnpp.so

Usage

Just include the header file:

#include "lnpp.h"

And link the library:

cc main.c -c -o main.o # Let main.c be your program
cc main.o lnpp.o -o main # If compiled as an object
cc main.o -o main -llnpp # If installed as a shared library
cc main.o -o main `pkg-config --libs --cflags lnpp` # Let pkgconf determine required flags

Documentation

About the most important definitions in "lnpp.h":

struct lnpp_request, struct lnpp_response
Data structures representing LNPP messages in memory.
lnpp_request_packetlen, lnpp_response_packetlen
Calculate how many bytes required to encode a UDP packet for a message.
lnpp_request_validate, lnpp_response_validate
Check if numeric values in a message are valid according to LNPP specification.
lnpp_request_encode, lnpp_response_encode
Render message in a UDP packet. Write bytes in a user provided pointer, assuming that it points to a required amount of memory allocated. Return amount of bytes written.
lnpp_request_decode, lnpp_response_decode
Parse message out of UDP packet. Return code signifies either success or one of the errors.
LNPP_REQUEST_MAX_PACKETLEN, LNPP_RESPONSE_MAX_PACKETLEN
Max possible length of a UDP packet for any message.

Authors

Feel free to message me if you have any questions.