Commit | Line | Data |
79072805 |
1 | #ifdef HAS_SOCKET |
2 | int |
3 | do_socket(stab, arglast) |
4 | STAB *stab; |
5 | int *arglast; |
6 | { |
7 | register STR **st = stack->ary_array; |
8 | register int sp = arglast[1]; |
9 | register STIO *stio; |
10 | int domain, type, protocol, fd; |
11 | |
12 | if (!stab) { |
13 | errno = EBADF; |
14 | return FALSE; |
15 | } |
16 | |
17 | stio = stab_io(stab); |
18 | if (!stio) |
19 | stio = stab_io(stab) = stio_new(); |
20 | else if (stio->ifp) |
21 | do_close(stab,FALSE); |
22 | |
23 | domain = (int)str_gnum(st[++sp]); |
24 | type = (int)str_gnum(st[++sp]); |
25 | protocol = (int)str_gnum(st[++sp]); |
26 | TAINT_PROPER("socket"); |
27 | fd = socket(domain,type,protocol); |
28 | if (fd < 0) |
29 | return FALSE; |
30 | stio->ifp = fdopen(fd, "r"); /* stdio gets confused about sockets */ |
31 | stio->ofp = fdopen(fd, "w"); |
32 | stio->type = 's'; |
33 | if (!stio->ifp || !stio->ofp) { |
34 | if (stio->ifp) fclose(stio->ifp); |
35 | if (stio->ofp) fclose(stio->ofp); |
36 | if (!stio->ifp && !stio->ofp) close(fd); |
37 | return FALSE; |
38 | } |
39 | |
40 | return TRUE; |
41 | } |
42 | |