From 876132d8af81566d21ad035d440e6842b321abfa Mon Sep 17 00:00:00 2001 From: tejaskumark Date: Fri, 3 Oct 2025 21:16:26 +0530 Subject: [PATCH 1/8] changing client behaviour --- client.go | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/client.go b/client.go index 8802a0b..048341d 100644 --- a/client.go +++ b/client.go @@ -10,6 +10,23 @@ import ( // NewClient creates TFTP client for server on address provided. func NewClient(addr string) (*Client, error) { + a, err := net.ResolveUDPAddr("udp", addr) + if err != nil { + return nil, fmt.Errorf("resolving address %s: %v", addr, err) + } + return &Client{ + addr: a, + timeout: defaultTimeout, + retries: defaultRetries, + localAddr: &net.UDPAddr{}, + }, nil +} + +// NewClient creates TFTP client for server on address provided. +func NewClientWithLocalAddr(addr string, laddr string) (*Client, error) { + if laddr == "" { + return nil, fmt.Errorf("local addr is empty") + } a, err := net.ResolveUDPAddr("udp", addr) if err != nil { return nil, fmt.Errorf("resolving address %s: %v", addr, err) @@ -18,6 +35,10 @@ func NewClient(addr string) (*Client, error) { addr: a, timeout: defaultTimeout, retries: defaultRetries, + localAddr: &net.UDPAddr{ + IP: net.ParseIP(laddr), + Port: 0, + }, }, nil } @@ -57,17 +78,18 @@ func (c *Client) RequestTSize(s bool) { // Client stores data about a single TFTP client type Client struct { - addr *net.UDPAddr - timeout time.Duration - retries int - backoff backoffFunc - blksize int - tsize bool + addr *net.UDPAddr + timeout time.Duration + retries int + backoff backoffFunc + blksize int + tsize bool + localAddr *net.UDPAddr } // Send starts outgoing file transmission. It returns io.ReaderFrom or error. func (c Client) Send(filename string, mode string) (io.ReaderFrom, error) { - conn, err := net.ListenUDP("udp", &net.UDPAddr{}) + conn, err := net.ListenUDP("udp", c.localAddr) if err != nil { return nil, err } @@ -97,7 +119,7 @@ func (c Client) Send(filename string, mode string) (io.ReaderFrom, error) { // Receive starts incoming file transmission. It returns io.WriterTo or error. func (c Client) Receive(filename string, mode string) (io.WriterTo, error) { - conn, err := net.ListenUDP("udp", &net.UDPAddr{}) + conn, err := net.ListenUDP("udp", c.localAddr) if err != nil { return nil, err } From e946abbc7dd4635a9aa29f2f461a0436c6316af3 Mon Sep 17 00:00:00 2001 From: tejaskumark Date: Fri, 3 Oct 2025 22:04:05 +0530 Subject: [PATCH 2/8] adding support to choose local ip addr to pass the traffic --- client.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/client.go b/client.go index 048341d..548c549 100644 --- a/client.go +++ b/client.go @@ -22,10 +22,13 @@ func NewClient(addr string) (*Client, error) { }, nil } -// NewClient creates TFTP client for server on address provided. -func NewClientWithLocalAddr(addr string, laddr string) (*Client, error) { - if laddr == "" { - return nil, fmt.Errorf("local addr is empty") +// NewClientWithLocalAddr creates TFTP client for server on local ip address laddr provided. +func NewClientWithLocalAddr(addr string, localaddr string) (*Client, error) { + if localaddr == "" { + return nil, fmt.Errorf("localaddr is empty") + } + if net.ParseIP(localaddr) == nil { + return nil, fmt.Errorf("provided localaddr: %s is not valid ip addr", localaddr) } a, err := net.ResolveUDPAddr("udp", addr) if err != nil { @@ -36,7 +39,7 @@ func NewClientWithLocalAddr(addr string, laddr string) (*Client, error) { timeout: defaultTimeout, retries: defaultRetries, localAddr: &net.UDPAddr{ - IP: net.ParseIP(laddr), + IP: net.ParseIP(localaddr), Port: 0, }, }, nil From 7cc213b0993c46cabd2c043fb7706e7179416ab8 Mon Sep 17 00:00:00 2001 From: tejaskumark Date: Sat, 4 Oct 2025 17:46:26 +0530 Subject: [PATCH 3/8] changing to local path to import properly in my repo --- go.mod | 2 +- receiver.go | 2 +- sender.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 1ce9954..7d5f4fa 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/pin/tftp/v3 +module github.com/tejaskumar/tftp go 1.23.0 diff --git a/receiver.go b/receiver.go index 7244567..da3b63a 100644 --- a/receiver.go +++ b/receiver.go @@ -8,7 +8,7 @@ import ( "strconv" "time" - "github.com/pin/tftp/v3/netascii" + "github.com/tejaskumar/tftp/netascii" ) // IncomingTransfer provides methods that expose information associated with diff --git a/sender.go b/sender.go index 1fd50db..9fe6095 100644 --- a/sender.go +++ b/sender.go @@ -8,7 +8,7 @@ import ( "strconv" "time" - "github.com/pin/tftp/v3/netascii" + "github.com/tejaskumar/tftp/netascii" ) // OutgoingTransfer provides methods to set the outgoing transfer size and From efc6e11f91d1655c482eeda5b9821d9145e55e75 Mon Sep 17 00:00:00 2001 From: tejaskumark Date: Sat, 4 Oct 2025 17:50:13 +0530 Subject: [PATCH 4/8] modifying to correct path --- go.mod | 2 +- receiver.go | 2 +- sender.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 7d5f4fa..3da31a0 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/tejaskumar/tftp +module github.com/tejaskumark/tftp go 1.23.0 diff --git a/receiver.go b/receiver.go index da3b63a..2034cf2 100644 --- a/receiver.go +++ b/receiver.go @@ -8,7 +8,7 @@ import ( "strconv" "time" - "github.com/tejaskumar/tftp/netascii" + "github.com/tejaskumark/tftp/netascii" ) // IncomingTransfer provides methods that expose information associated with diff --git a/sender.go b/sender.go index 9fe6095..9ba9f0a 100644 --- a/sender.go +++ b/sender.go @@ -8,7 +8,7 @@ import ( "strconv" "time" - "github.com/tejaskumar/tftp/netascii" + "github.com/tejaskumark/tftp/netascii" ) // OutgoingTransfer provides methods to set the outgoing transfer size and From ac696339e1f1329076ee7ed690f779b2dcc4f055 Mon Sep 17 00:00:00 2001 From: tejaskumark Date: Sat, 4 Oct 2025 18:03:28 +0530 Subject: [PATCH 5/8] version update --- go.mod | 2 +- receiver.go | 2 +- sender.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 3da31a0..7a96f70 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/tejaskumark/tftp +module github.com/tejaskumark/tftp/v1 go 1.23.0 diff --git a/receiver.go b/receiver.go index 2034cf2..0b0d9e9 100644 --- a/receiver.go +++ b/receiver.go @@ -8,7 +8,7 @@ import ( "strconv" "time" - "github.com/tejaskumark/tftp/netascii" + "github.com/tejaskumark/tftp/v1/netascii" ) // IncomingTransfer provides methods that expose information associated with diff --git a/sender.go b/sender.go index 9ba9f0a..a3a6497 100644 --- a/sender.go +++ b/sender.go @@ -8,7 +8,7 @@ import ( "strconv" "time" - "github.com/tejaskumark/tftp/netascii" + "github.com/tejaskumark/tftp/v1/netascii" ) // OutgoingTransfer provides methods to set the outgoing transfer size and From 5d03844342afaa279358543f10f22e8b62aeeb9c Mon Sep 17 00:00:00 2001 From: tejaskumark Date: Sat, 4 Oct 2025 18:36:57 +0530 Subject: [PATCH 6/8] moving to latest again --- go.mod | 2 +- receiver.go | 2 +- sender.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 7a96f70..3da31a0 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/tejaskumark/tftp/v1 +module github.com/tejaskumark/tftp go 1.23.0 diff --git a/receiver.go b/receiver.go index 0b0d9e9..2034cf2 100644 --- a/receiver.go +++ b/receiver.go @@ -8,7 +8,7 @@ import ( "strconv" "time" - "github.com/tejaskumark/tftp/v1/netascii" + "github.com/tejaskumark/tftp/netascii" ) // IncomingTransfer provides methods that expose information associated with diff --git a/sender.go b/sender.go index a3a6497..9ba9f0a 100644 --- a/sender.go +++ b/sender.go @@ -8,7 +8,7 @@ import ( "strconv" "time" - "github.com/tejaskumark/tftp/v1/netascii" + "github.com/tejaskumark/tftp/netascii" ) // OutgoingTransfer provides methods to set the outgoing transfer size and From da4bd691410b55b1af08421c0ae2141d246f46b5 Mon Sep 17 00:00:00 2001 From: tejaskumark Date: Sat, 4 Oct 2025 19:07:25 +0530 Subject: [PATCH 7/8] adding retraction --- go.mod | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/go.mod b/go.mod index 3da31a0..f0a7206 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,11 @@ module github.com/tejaskumark/tftp go 1.23.0 +retract ( + v1.0.0 // Published accidentally. + v1.0.1 // Contains retractions only. +) + require golang.org/x/net v0.43.0 require golang.org/x/sys v0.35.0 // indirect From f25a4a2ef3c0be27a33e476615c2f276c02f5a95 Mon Sep 17 00:00:00 2001 From: tejaskumark Date: Sat, 4 Oct 2025 19:20:42 +0530 Subject: [PATCH 8/8] adding v2 --- go.mod | 6 +++--- receiver.go | 2 +- sender.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index f0a7206..fb8e513 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,10 @@ -module github.com/tejaskumark/tftp +module github.com/tejaskumark/tftp/v2 go 1.23.0 retract ( - v1.0.0 // Published accidentally. - v1.0.1 // Contains retractions only. + v1.0.1 // Contains retractions only. + v1.0.0 // Published accidentally. ) require golang.org/x/net v0.43.0 diff --git a/receiver.go b/receiver.go index 2034cf2..8a94e30 100644 --- a/receiver.go +++ b/receiver.go @@ -8,7 +8,7 @@ import ( "strconv" "time" - "github.com/tejaskumark/tftp/netascii" + "github.com/tejaskumark/tftp/v2/netascii" ) // IncomingTransfer provides methods that expose information associated with diff --git a/sender.go b/sender.go index 9ba9f0a..0208974 100644 --- a/sender.go +++ b/sender.go @@ -8,7 +8,7 @@ import ( "strconv" "time" - "github.com/tejaskumark/tftp/netascii" + "github.com/tejaskumark/tftp/v2/netascii" ) // OutgoingTransfer provides methods to set the outgoing transfer size and