flag.PrintDefaults()
}
-type InetdConn struct {
+type UCSPIConn struct {
r *os.File
w *os.File
}
-func (c InetdConn) Read(p []byte) (n int, err error) {
+func (c UCSPIConn) Read(p []byte) (n int, err error) {
return c.r.Read(p)
}
-func (c InetdConn) Write(p []byte) (n int, err error) {
+func (c UCSPIConn) Write(p []byte) (n int, err error) {
return c.w.Write(p)
}
-func (c InetdConn) SetReadDeadline(t time.Time) error {
+func (c UCSPIConn) SetReadDeadline(t time.Time) error {
return c.r.SetReadDeadline(t)
}
-func (c InetdConn) SetWriteDeadline(t time.Time) error {
+func (c UCSPIConn) SetWriteDeadline(t time.Time) error {
return c.w.SetWriteDeadline(t)
}
-func (c InetdConn) Close() error {
+func (c UCSPIConn) Close() error {
if err := c.r.Close(); err != nil {
c.w.Close() // #nosec G104
return err
cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
niceRaw = flag.String("nice", nncp.NicenessFmt(255), "Minimal required niceness")
bind = flag.String("bind", "[::]:5400", "Address to bind to")
- inetd = flag.Bool("inetd", false, "Is it started as inetd service")
+ ucspi = flag.Bool("ucspi", false, "Is it started as UCSPI-TCP server")
+ inetd = flag.Bool("inetd", false, "Obsolete, use -ucspi")
maxConn = flag.Int("maxconn", 128, "Maximal number of simultaneous connections")
noCK = flag.Bool("nock", false, "Do no checksum checking")
mcdOnce = flag.Bool("mcd-once", false, "Send MCDs once and quit")
if err != nil {
log.Fatalln(err)
}
+ if *inetd {
+ *ucspi = true
+ }
ctx, err := nncp.CtxFromCmdline(
*cfgPath,
}
ctx.Umask()
- if *inetd {
+ if *ucspi {
os.Stderr.Close() // #nosec G104
- conn := &InetdConn{os.Stdin, os.Stdout}
+ conn := &UCSPIConn{os.Stdin, os.Stdout}
nodeIdC := make(chan *nncp.NodeId)
- go performSP(ctx, conn, "PIPE", nice, *noCK, nodeIdC)
+ addr := "PIPE"
+ if proto := os.Getenv("PROTO"); proto == "TCP" {
+ port := os.Getenv("TCPREMOTEPORT")
+ if host := os.Getenv("TCPREMOTEHOST"); host == "" {
+ addr = fmt.Sprintf("[%s]:%s", os.Getenv("TCPREMOTEIP"), port)
+ } else {
+ addr = fmt.Sprintf("%s:%s", host, port)
+ }
+ }
+ go performSP(ctx, conn, addr, nice, *noCK, nodeIdC)
nodeId := <-nodeIdC
var autoTossFinish chan struct{}
var autoTossBadCode chan bool