-
Notifications
You must be signed in to change notification settings - Fork 2
/
argfd.c.tmpl
81 lines (72 loc) · 2.31 KB
/
argfd.c.tmpl
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/event.h>
#include "drv.h"
#include "sysc.h"
int getStdFile(int typ)
{
int fd, pipes[2];
fd = -1;
switch(typ) {
#define F(n, fn, flg) case n: fd = open(fn, flg); break;
F($NUM, "/", O_RDONLY);
#define S(n, a,b,c) case n: fd = socket(a, b, c); break;
S($NUM, AF_INET, SOCK_STREAM, 0);
S($NUM, AF_INET, SOCK_DGRAM, 0);
S($NUM, AF_UNIX, SOCK_STREAM, 0);
S($NUM, AF_UNIX, SOCK_DGRAM, 0);
case $NUM:
if(pipe(pipes) == -1) return -1;
fd = pipes[0];
break;
case $NUM:
if(pipe(pipes) == -1) return -1;
fd = pipes[1];
break;
S($NUM, AF_UNIX, SOCK_STREAM, 0);
S($NUM, AF_UNIX, SOCK_DGRAM, 0);
S($NUM, AF_UNIX, SOCK_SEQPACKET, 0);
S($NUM, AF_UNIX, SOCK_RAW, 0);
S($NUM, AF_UNIX, SOCK_RDM, 0);
S($NUM, AF_INET, SOCK_STREAM, 0);
S($NUM, AF_INET, SOCK_DGRAM, 0);
S($NUM, AF_INET, SOCK_SEQPACKET, 0);
S($NUM, AF_INET, SOCK_RAW, 0);
S($NUM, AF_INET, SOCK_RDM, 0);
S($NUM, AF_INET6, SOCK_STREAM, 0);
S($NUM, AF_INET6, SOCK_DGRAM, 0);
S($NUM, AF_INET6, SOCK_SEQPACKET, 0);
S($NUM, AF_INET6, SOCK_RAW, 0);
S($NUM, AF_INET6, SOCK_RDM, 0);
S($NUM, AF_IPX, SOCK_STREAM, 0);
S($NUM, AF_IPX, SOCK_DGRAM, 0);
S($NUM, AF_IPX, SOCK_SEQPACKET, 0);
S($NUM, AF_IPX, SOCK_RAW, 0);
S($NUM, AF_IPX, SOCK_RDM, 0);
S($NUM, AF_APPLETALK, SOCK_STREAM, 0);
S($NUM, AF_APPLETALK, SOCK_DGRAM, 0);
S($NUM, AF_APPLETALK, SOCK_SEQPACKET, 0);
S($NUM, AF_APPLETALK, SOCK_RAW, 0);
S($NUM, AF_APPLETALK, SOCK_RDM, 0);
#define SP(n, f, ty, idx) case n: socketpair(f, ty, 0, pipes); fd = pipes[idx]; break
SP($NUM, AF_UNIX, SOCK_STREAM, 0);
SP($NUM, AF_UNIX, SOCK_STREAM, 1);
SP($NUM, AF_UNIX, SOCK_DGRAM, 0);
SP($NUM, AF_UNIX, SOCK_DGRAM, 1);
SP($NUM, AF_UNIX, SOCK_SEQPACKET, 0);
SP($NUM, AF_UNIX, SOCK_SEQPACKET, 1);
case $NUM:
fd = kqueue();
break;
default:
// XXX nonblocking sockets?
// XXX AF_NETLINK x (DGRAM,RAW) x protonr 0..22
// XXX (INET, INET6) x SOCK_RAW x protonr 0..256
// XXX PACKET X (DGRAM, RAW) x htons(rawtypes)
// XXX weird files from /dev, /proc, /sys, etc..
return -1;
}
return fd;
}