-
Notifications
You must be signed in to change notification settings - Fork 9
/
sys_socket.sh
61 lines (48 loc) · 1.19 KB
/
sys_socket.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
declare -ri AF_INET=2
declare -ri AF_UNSPEC=0
declare -ri SOCK_STREAM=1
declare -ri SHUT_RD=0
declare -ri SHUT_WR=1
declare -ri SHUT_RDWR=2
if [ "$PLATFORM" = FreeBSD ]; then
declare -ri SOL_SOCKET=0xffff
declare -ri SO_REUSEADDR=4
declare -ri SOCK_NONBLOCK=0x20000000
elif [ "$PLATFORM" = Linux ]; then
declare -ri SOL_SOCKET=1
declare -ri SO_REUSEADDR=2
declare -ri SOCK_NONBLOCK=0x800
fi
function accept() {
dlcall -r int accept int:$2 $3 $4
eval $1=\$DLRETVAL
}
function listen() {
dlcall -r int listen int:$2 int:$3
eval $1=\$DLRETVAL
}
function recv() {
dlcall -r $ssize_t recv int:$2 $3 $size_t:$4 int:$5
eval $1=\$DLRETVAL
}
function send() {
dlcall -r $ssize_t send int:$2 "$3" $size_t:$4 int:$5
eval $1=\$DLRETVAL
}
function setsockopt() {
dlcall -r int setsockopt int:$2 int:$3 int:$4 $5 $6
eval $1=\$DLRETVAL
}
function shutdown() {
dlcall -r int shutdown int:$2 int:$3
eval $1=\$DLRETVAL
}
function socket() {
dlcall -r int socket int:$2 int:$3 int:$4
eval $1=\$DLRETVAL
}
# Alternative name to work around built-in 'bind'
function so_bind() {
dlcall -r int bind int:$2 $3 $socklen_t:$4
eval $1=\$DLRETVAL
}