wireguard.lists.zx2c4.com archive mirror
 help / color / mirror / Atom feed
From: "Lukas Lüdke" <lukasluedke@web.de>
To: wireguard@lists.zx2c4.com
Subject: Problem using "WireGuardSetConfiguration" for Wireguard-NT with heap allocated configuration
Date: Sat, 14 Aug 2021 00:02:44 +0200	[thread overview]
Message-ID: <e3f36b3e-5337-0d04-6c8a-9ce1bb6c234e@web.de> (raw)


I am trying to implement a custom wireguard client using the provided
wireguard.dll/wireguard.h in c++.
I tried to modify the example from here:
It works, when I specify a struct with one interface
(WIREGUARD_INTERFACE) and one or more peers + allowed ips
"WireGuardSetConfiguration" to the the configuration on the adapter,
like it the example.
But when I try to use a buffer allocated on the heap, containing the
interface and the peers + allowed_ips, I always get error 0x57 from
It seems to work, when I only create the buffer and memcpy a
WIREGUARD_INTERFACE object into the buffer, but if I create a larger
buffer and also memcpy the WIREGUARD_PEER object into it, set the Flags
and set the PeersCount, I get the error.
like in the following example it does not work:

unsigned char* buffer = (unsigned char
*)malloc(sizeof(WIREGUARD_INTERFACE) + sizeof(WIREGUARD_PEER));
/*new_interface is the interface from the example.c file*/
new_interface.PeersCount = 1;
memcpy(buffer, &new_interface, sizeof(WIREGUARD_INTERFACE));
unsigned char* buffer2 = (buffer + sizeof(WIREGUARD_INTERFACE));
/*peer is a created peer, which does work, if I use it in a struct*/
memcpy(buffer2, &peer, sizeof(WIREGUARD_PEER));
if (!WireGuardSetConfiguration(Adapter, (WIREGUARD_INTERFACE
*)&(buffer), sizeof(struct t))) {
     LastError = LogError(L"Failed to set configuration", GetLastError());
     return cleanupAdapter(Adapter, WireGuard, LastError);

Does anyone has an idea, how I can implement this correctly, so that I
can dynamically add/remove the peers and I am not forced to create a
struct with fixed peer count?

Best Regards,

             reply	other threads:[~2021-08-13 22:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-13 22:02 Lukas Lüdke [this message]
2021-08-13 22:19 ` Problem using "WireGuardSetConfiguration" for Wireguard-NT with heap allocated configuration Jason A. Donenfeld

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e3f36b3e-5337-0d04-6c8a-9ce1bb6c234e@web.de \
    --to=lukasluedke@web.de \
    --cc=wireguard@lists.zx2c4.com \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).