Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F6381992
client.c
tig_freebsdfoundation.org (Tiger Gao)
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
tig_freebsdfoundation.org
Apr 16 2020, 3:22 PM
2020-04-16 15:22:32 (UTC+0)
Size
898 B
Referenced Files
None
Subscribers
None
client.c
View Options
#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
Details
Attached
Mime Type
text/x-c
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2559416
Default Alt Text
client.c (898 B)
Attached To
Mode
D24442: Add new casper socket service
Attached
Detach File
Event Timeline
Log In to Comment