]> Cypherpunks.ru repositories - ucspi.git/blob - cmd/proxy/main.go
Unify copyright comment format
[ucspi.git] / cmd / proxy / main.go
1 // ucspi/cmd/proxy -- UCSPI TCP proxy
2 // Copyright (C) 2021-2024 Sergey Matveev <stargrave@stargrave.org>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, version 3 of the License.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16 package main
17
18 import (
19         "flag"
20         "fmt"
21         "io"
22         "log"
23         "os"
24 )
25
26 func main() {
27         flag.Usage = func() {
28                 fmt.Fprintln(os.Stderr, "Usage: UCSPIserver [address] UCSPIclient [address] ucspi-proxy")
29         }
30         flag.Parse()
31         log.SetFlags(log.Lshortfile)
32
33         r := os.NewFile(6, "R")
34         if r == nil {
35                 log.Fatalln("no 6 file descriptor")
36         }
37         w := os.NewFile(7, "W")
38         if w == nil {
39                 log.Fatalln("no 7 file descriptor")
40         }
41         worker := make(chan struct{})
42         var err error
43         go func() {
44                 _, err = io.Copy(w, os.Stdin)
45                 w.Close()
46                 close(worker)
47         }()
48         go func() {
49                 io.Copy(os.Stdout, r)
50         }()
51         <-worker
52         if err != nil {
53                 log.Fatalln(err)
54         }
55 }