Nmap Development mailing list archives
Re: Nsock unconnected sockets
From: David Fifield <david () bamsoftware com>
Date: Sat, 9 Oct 2010 16:25:06 -0700
On Tue, Oct 05, 2010 at 04:37:54PM -0700, David Fifield wrote:
On Mon, Oct 04, 2010 at 11:01:50PM -0500, Kris Katterjohn wrote:On 10/04/2010 10:18 PM, David Fifield wrote:On Mon, Oct 04, 2010 at 09:17:07PM -0500, Kris Katterjohn wrote:Well, given that scripts shouldn't be connecting multiple times (which leads me to believe there should be one connect() for each new_socket()), then a possibility is this: s = nmap.new_socket(<protocol>, <optional family>) s:connect(host, port) -- remove/deprecate protocol argThis has a little bit of a problem, though, which is the address family. Currently you can do s = nmap.new_socket() s:connect("::1", 80) and it will work fine. If OS socket creation always happens when new_socket is called, then it becomes necessary to declare the address family in advance (even if implicit). Consider that someone may give an address in a script argument--then it becomes necessary to analyze its address family before calling new_socket.Ah, good point! But isn't this also a problem with setup/sendto if you send to a user-given address?Yes, you're right.Another thing to consider is that at least one function, bind, needs to be called before the socket is connected.Sorry, but I'm not sure how this would be an issue. new_socket("tcp") bind("192.168.10.69", 31337) connect("192.168.10.1", 80) and new_socket("udp") bind("192.168.10.69", 31337) sendto("192.168.10.1", 53, "stuff") How would these not work? I suspect something may have to be moved around, but are these really not possible?You're right, this is a better interface. I'll see what's needed to make it work.
This is what I've implemented now. new_socket works the way it always
has, except that you can optionally declare a protocol and address
family.
s = nmap.new_socket("udp")
The iod isn't created at this point. The address family and protocol are
just cached for later. You can connect it as before. If you try to do an
operation such as a send or receive without first connecting, an iod is
created on demand using the information you provided to new_socket.
s:bind(nil, 888)
s:receive()
s:sendto("1.2.3.4", 888, data)
If you connect with a different protocol, it overrides whatever you set
earlier. The third argument to connect is optional if it's what you
already set in new_socket.
David Fifield
_______________________________________________
Sent through the nmap-dev mailing list
http://cgi.insecure.org/mailman/listinfo/nmap-dev
Archived at http://seclists.org/nmap-dev/
Current thread:
- Nsock unconnected sockets David Fifield (Oct 03)
- Re: Nsock unconnected sockets Kris Katterjohn (Oct 03)
- Re: Nsock unconnected sockets David Fifield (Oct 04)
- Re: Nsock unconnected sockets Kris Katterjohn (Oct 04)
- Re: Nsock unconnected sockets David Fifield (Oct 04)
- Re: Nsock unconnected sockets Kris Katterjohn (Oct 04)
- Re: Nsock unconnected sockets David Fifield (Oct 05)
- Re: Nsock unconnected sockets David Fifield (Oct 09)
- Re: Nsock unconnected sockets Kris Katterjohn (Oct 10)
- Re: Nsock unconnected sockets Ron (Oct 14)
- Re: Nsock unconnected sockets David Fifield (Oct 15)
- Re: Nsock unconnected sockets Patrik Karlsson (Oct 15)
- Re: Nsock unconnected sockets David Fifield (Oct 04)
- Re: Nsock unconnected sockets Kris Katterjohn (Oct 03)
