blob: 439f3e2b5de2748a5f5118a5cedf959de94aaa5f (
plain)
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
|
int
do_sopt(optype, stab, arglast)
int optype;
STAB *stab;
int *arglast;
{
register STR **st = stack->ary_array;
register int sp = arglast[1];
register STIO *stio;
int fd;
unsigned int lvl;
unsigned int optname;
if (!stab)
goto nuts;
stio = stab_io(stab);
if (!stio || !stio->ifp)
goto nuts;
fd = fileno(stio->ifp);
lvl = (unsigned int)str_gnum(st[sp+1]);
optname = (unsigned int)str_gnum(st[sp+2]);
switch (optype) {
case O_GSOCKOPT:
st[sp] = str_2mortal(Str_new(22,257));
st[sp]->str_cur = 256;
st[sp]->str_pok = 1;
if (getsockopt(fd, lvl, optname, st[sp]->str_ptr,
(int*)&st[sp]->str_cur) < 0)
goto nuts;
break;
case O_SSOCKOPT:
st[sp] = st[sp+3];
if (setsockopt(fd, lvl, optname, st[sp]->str_ptr, st[sp]->str_cur) < 0)
goto nuts;
st[sp] = &str_yes;
break;
}
return sp;
nuts:
if (dowarn)
warn("[gs]etsockopt() on closed fd");
st[sp] = &str_undef;
errno = EBADF;
return sp;
}
|