-
Notifications
You must be signed in to change notification settings - Fork 396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmds/core/netcat: add support for udp #2737
Conversation
Signed-off-by: Siarhiej Siemianczuk <pdp.eleven11@gmail.com>
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #2737 +/- ##
==========================================
- Coverage 75.54% 75.40% -0.15%
==========================================
Files 416 416
Lines 42373 42401 +28
==========================================
- Hits 32012 31972 -40
- Misses 10361 10429 +68
☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to leave the comment about 1500 if you don't see a need for it.
one bigger question: the golang net package tried to follow the plan 9 convention that code could set up a socket and just use Read()/Write() once it was set up, no metter the type. IOW you did not need a WriteToUDP, for example, because, once the socket is set up, you should be able to use Read and Write. Are you pretty certain you need to break out UDP functions by name, once you have the socket? I do not know but it's a shame if we need to add so much code for every different transport.
Thanks.
Hi, can you look at https://github.com/rminnich/u-root/pull/new/netcat-udp It does the same thing, but only needs the run() function |
Signed-off-by: Siarhiej Siemianczuk <pdp.eleven11@gmail.com>
I updated udp listen test with server -> client message and net.Conn approach should not work now. |
I am convinced we should be able to make this work without runDatagram() but perhaps you can show my why I am wrong() but, bear in mind, all these functions UDPConn even says so: so this really ought to be usable without adding another function. |
We somehow need to obtain remote address, so UDPConn implements Conn, but it working only one way (client -> server, client knows server address). In this simple program I got package main
import (
"fmt"
"log"
"net"
)
func main() {
var conn net.Conn
conn, err := net.ListenUDP("udp", &net.UDPAddr{Port: 1234})
if err != nil {
panic(err)
}
b := make([]byte, 1024)
for {
fmt.Println()
n, err := conn.Read(b)
if err != nil {
log.Println(err)
}
fmt.Printf("Received: %s\n", b[:n])
n, err = conn.Write([]byte("Hello from server"))
if err != nil {
log.Println(n, err)
}
}
} But in net.Conn interface we can get remote address, but we can't specify it in conn.Write and upd message will not reach client. A bit more about error: EDESTADDRREQ |
you can set a remote address on a UDP connection. It then becomes a "connected" socket. See this writeup so I think that's what we need here, and why you are getting this error |
Yeah, this is interesting "Established-over-unconnected technique", but a bit hacky and probably will require build constraints, at least author claims it works on Linux. But I'm not sure if it will simplify things, will require syscall package. |
it's worked on just about everything for many decades. I learned about it long after it was a standard. It surprised me too. "connected UDP socket? What?" but it's real. |
courtesy chatgpt, no idea if it is right
|
func DialUDP(network string, laddr, raddr *UDPAddr) (*UDPConn, error)
I suspect this will try a connect. I only got so far following the code down the rabbit hole however. |
Maybe own type with some embeddings is a good idea to do it in one function. I will try it on weekend. |
ok but before you do the own type, I recommend you try DialUDP, b/c I think that's what we want |
But DialUDP where? I already using it in runDatagram function? |
Signed-off-by: Siarhiej Siemianczuk <pdp.eleven11@gmail.com>
No description provided.