|
|
1.1 root 1: #include "defs.h"
2: #include <ctype.h>
3:
4: /*
5: * convert a port number into a file system name
6: */
7: char *
8: tcptofs(port)
9: int port;
10: {
11: static char name[PATHLEN];
12:
13: sprintf(name, "/cs/tcp.%d", port);
14: return name;
15: }
16:
17: /*
18: * convert an internal name into a port number
19: */
20: fstotcp(name)
21: char *name;
22: {
23: int port;
24:
25: if (strncmp(name, CSROOT, sizeof(CSROOT)-1)==0)
26: name += sizeof(CSROOT)-1;
27: if (strncmp(name, "tcp.", sizeof("tcp.")-1)==0)
28: name += sizeof("tcp.")-1;
29: for (port=0; *name; name++) {
30: if (!isdigit(*name))
31: return -1;
32: port = port*10 + (*name - '0');
33: }
34: return port;
35: }
36:
37: /*
38: * ipccreate a tcp usable port. a bit of a crock.
39: */
40: tcpcreat(name, param)
41: char *name;
42: char *param;
43: {
44: int p;
45: int offset;
46: int fd= -1;
47:
48: if (getuid()==0)
49: offset = 512;
50: else
51: offset = 1024;
52: for (p=0; p<511 && fd<0; p++) {
53: strcpy(name, tcptofs(p+offset));
54: fd = ipccreat(name, param);
55: if (fd<0)
56: continue;
57: }
58: return fd;
59: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.