Add new example for IPv6 with UDP

This commit is contained in:
seajee
2025-08-24 23:45:30 +02:00
parent 46d7ed775d
commit ad986c777a
2 changed files with 63 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
#include <stdio.h>
#include <errno.h>
#define SOCK_IMPLEMENTATION
#include "sock.h"
int main(void)
{
bool err = false;
Sock *s = sock_create(SOCK_IPV6, SOCK_UDP);
if (s == NULL) { err = "create"; goto defer; }
SockAddr addr = sock_addr("::1", 6969);
const char *msg = "Hello from client!";
char buf[128];
memset(buf, 0, sizeof(buf));
sock_sendto(s, msg, strlen(msg), addr);
sock_recvfrom(s, buf, sizeof(buf), NULL);
printf("%s:%d: %.*s\n", addr.str, addr.port,
(int)sizeof(buf), buf);
defer:
if (err) sock_log_error(s);
sock_close(s);
return 0;
}