Commit | Line | Data |
---|---|---|
e1b631e8 JSP |
1 | /* |
2 | * Copyright (c) 1992 The Regents of the University of California | |
3 | * Copyright (c) 1990, 1992 Jan-Simon Pendry | |
4 | * All rights reserved. | |
5 | * | |
6 | * This code is derived from software donated to Berkeley by | |
7 | * Jan-Simon Pendry. | |
8 | * | |
9 | * %sccs.include.redist.c% | |
10 | * | |
225429d9 | 11 | * @(#)pt_tcp.c 1.2 (Berkeley) %G% |
e1b631e8 JSP |
12 | * |
13 | * $Id: pt_tcp.c,v 1.1 1992/05/25 21:43:09 jsp Exp jsp $ | |
14 | */ | |
15 | ||
16 | #include <stdio.h> | |
17 | #include <unistd.h> | |
18 | #include <stdlib.h> | |
19 | #include <errno.h> | |
225429d9 | 20 | #include <strings.h> |
e1b631e8 | 21 | #include <sys/types.h> |
225429d9 | 22 | #include <sys/param.h> |
e1b631e8 JSP |
23 | #include <sys/syslog.h> |
24 | ||
25 | #include "portald.h" | |
26 | ||
225429d9 JSP |
27 | /* |
28 | * Key will be tcp/host/port[/"priv"] | |
29 | * Create a TCP socket connected to the | |
30 | * requested host and port. | |
31 | * Some trailing suffix values have special meanings. | |
32 | * An unrecognised suffix is an error. | |
33 | */ | |
e1b631e8 JSP |
34 | int portal_tcp(pcr, key, v, so, fdp) |
35 | struct portal_cred *pcr; | |
36 | char *key; | |
37 | char **v; | |
38 | int so; | |
39 | int *fdp; | |
40 | { | |
225429d9 JSP |
41 | char host[MAXHOSTNAMELEN]; |
42 | char port[MAXHOSTNAMELEN]; | |
43 | char *p = key + (v[1] ? strlen(v[1]) : 0); | |
44 | char *q; | |
45 | ||
46 | q = strchr(p, '/'); | |
47 | if (q == 0 || q - p >= sizeof(host)) | |
48 | return (EINVAL); | |
49 | *q = '\0'; | |
50 | strcpy(host, p); | |
51 | p = q++; | |
52 | ||
53 | q = strchr(p, '/'); | |
54 | if (q == 0 || q - p >= sizeof(port)) | |
55 | return (EINVAL); | |
56 | *q = '\0'; | |
57 | strcpy(port, p); | |
58 | p = q++; | |
59 | ||
e1b631e8 JSP |
60 | return (EHOSTUNREACH); |
61 | } |