FROM_PORT and TO_PORT support
This commit is contained in:
@ -21,6 +21,9 @@ type Client struct {
|
||||
sigType string
|
||||
destination string
|
||||
|
||||
fromport string
|
||||
toport string
|
||||
|
||||
inLength uint
|
||||
inVariance int
|
||||
inQuantity uint
|
||||
@ -97,6 +100,8 @@ func NewClientFromOptions(opts ...func(*Client) error) (*Client, error) {
|
||||
c.id = 0
|
||||
c.lastaddr = "invalid"
|
||||
c.destination = ""
|
||||
c.fromport = "0"
|
||||
c.toport = "0"
|
||||
for _, o := range opts {
|
||||
if err := o(&c); err != nil {
|
||||
return nil, err
|
||||
|
64
options.go
64
options.go
@ -111,6 +111,59 @@ func SetPortInt(i int) func(*Client) error {
|
||||
}
|
||||
}
|
||||
|
||||
//SetFromPort sets the port of the client's SAM bridge using a string
|
||||
func SetFromPort(s string) func(*Client) error {
|
||||
return func(c *Client) error {
|
||||
port, err := strconv.Atoi(s)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Invalid port; non-number")
|
||||
}
|
||||
if port < 65536 && port > -1 {
|
||||
c.fromport = s
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid port")
|
||||
}
|
||||
}
|
||||
|
||||
//SetFromPortInt sets the port of the client's SAM bridge using a string
|
||||
func SetFromPortInt(i int) func(*Client) error {
|
||||
return func(c *Client) error {
|
||||
if i < 65536 && i > -1 {
|
||||
c.fromport = strconv.Itoa(i)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid port")
|
||||
}
|
||||
}
|
||||
|
||||
//SetToPort sets the port of the client's SAM bridge using a string
|
||||
func SetToPort(s string) func(*Client) error {
|
||||
return func(c *Client) error {
|
||||
port, err := strconv.Atoi(s)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Invalid port; non-number")
|
||||
}
|
||||
if port < 65536 && port > -1 {
|
||||
c.toport = s
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid port")
|
||||
}
|
||||
}
|
||||
|
||||
//SetToPortInt sets the port of the client's SAM bridge using a string
|
||||
func SetToPortInt(i int) func(*Client) error {
|
||||
return func(c *Client) error {
|
||||
if i < 65536 && i > -1 {
|
||||
c.fromport = strconv.Itoa(i)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid port")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//SetDebug enables debugging messages
|
||||
func SetDebug(b bool) func(*Client) error {
|
||||
return func(c *Client) error {
|
||||
@ -306,6 +359,17 @@ func SetSignatureType(s string) func(*Client) error {
|
||||
}
|
||||
}
|
||||
|
||||
//return the from port as a string.
|
||||
func (c *Client) from() string {
|
||||
return fmt.Sprintf(" FROM_PORT=%v ", c.fromport)
|
||||
}
|
||||
|
||||
|
||||
//return the to port as a string.
|
||||
func (c *Client) to() string {
|
||||
return fmt.Sprintf(" TO_PORT=%v ", c.toport)
|
||||
}
|
||||
|
||||
//return the signature type as a string.
|
||||
func (c *Client) sigtype() string {
|
||||
return fmt.Sprintf(" %s ", c.sigType)
|
||||
|
@ -19,8 +19,10 @@ func (c *Client) CreateStreamSession(id int32, dest string) (string, error) {
|
||||
}
|
||||
c.id = id
|
||||
r, err := c.sendCmd(
|
||||
"SESSION CREATE STYLE=STREAM ID=%d DESTINATION=%s %s %s\n",
|
||||
"SESSION CREATE STYLE=STREAM ID=%d %s %s DESTINATION=%s %s %s\n",
|
||||
c.id,
|
||||
c.from(),
|
||||
c.to(),
|
||||
dest,
|
||||
c.sigtype(),
|
||||
c.allOptions(),
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
|
||||
// StreamConnect asks SAM for a TCP-Like connection to dest, has to be called on a new Client
|
||||
func (c *Client) StreamConnect(id int32, dest string) error {
|
||||
r, err := c.sendCmd("STREAM CONNECT ID=%d DESTINATION=%s\n", id, dest)
|
||||
r, err := c.sendCmd("STREAM CONNECT ID=%d %s %s DESTINATION=%s\n", id, c.from(), c.to(), dest)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Reference in New Issue
Block a user