Page MenuHomeFreeBSD
Authored By
tig_freebsdfoundation.org
Apr 16 2020, 3:22 PM
Size
898 B
Referenced Files
None
Subscribers
None

client.c

#include <libcasper.h>
#include <err.h>
#include <capsicum_helpers.h>
#include <cap_socket.h>
#include <sys/socket.h>
#include <string.h>
int main() {
cap_channel_t *capcas, *capsock;
int sock;
const char *paths[2] = {"any:127.0.0.1:-1", "tcp:www.google.com:80"};
char *hello = "Hello from client hehe";
char buffer[1024] = {0};
capcas = cap_init();
if (capcas == NULL)
err(1, "Unable to contact Casper");
if (cap_enter() < 0 && errno != ENOSYS)
err(1, "Unable to enter capability mode");
capsock = cap_service_open(capcas, "system.socket");
if (capsock == NULL)
err(1, "Unable to open system.socket service");
cap_close(capcas);
cap_socket_init(capsock, 2, paths);
sock = cap_socket_connect(capsock, "tcp:127.0.0.1:8080");
if (sock == -1)
err(1, "Not allowed.");
send(sock, hello, strlen(hello), 0);
read(sock, buffer, 1024);
printf("%s\n",buffer);
return (0);
}

File Metadata

Mime Type
text/x-c
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2559416
Default Alt Text
client.c (898 B)

Event Timeline