I'm new to usocket and would like to bind a socket to a specific address. (bind as in http://www.istild.com/man-pages/man2/bind.2.html)
Is there an api for that?
Cheers, Chris Dean
Hi, Chris Dean
You mean: when you connect to a remote address/port, you also want to bind to specified local-address/port?
If so, I'm afraid that no such support in usocket yet. The USOCKET:SOCKET-CONNECT should have additional two keyword parameters for this feature:
SOCKET-CONNECT (host port &key element-type timeout local-address local-port)
For LispWorks, following patch can give you what you want (If I guess right above):
Index: lispworks.lisp =================================================================== --- lispworks.lisp (revision 362) +++ lispworks.lisp (working copy) @@ -73,7 +73,8 @@ (declare (ignore host port err-msg)) (raise-usock-err errno socket condition)))))
-(defun socket-connect (host port &key (element-type 'base-char) timeout) +(defun socket-connect (host port &key (element-type 'base-char) timeout + local-address local-port) (when timeout (warn "SOCKET-CONNECT timeout not supported in Lispworks")) (let ((hostname (host-to-hostname host)) @@ -81,7 +82,9 @@ (setf stream (with-mapped-conditions () (comm:open-tcp-stream hostname port - :element-type element-type))) + :element-type element-type + :local-address local-address + :local-port local-port))) (if stream (make-stream-socket :socket (comm:socket-stream-socket stream) :stream stream)
For other platforms I think there're also quite trivial patches. Maybe Erik should add this support in usocket 0.4.x.
Regards,
Chun Tian (binghe)
I'm new to usocket and would like to bind a socket to a specific address. (bind as in http://www.istild.com/man-pages/man2/bind. 2.html)
Is there an api for that?
Cheers, Chris Dean _______________________________________________ usocket-devel mailing list usocket-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/usocket-devel
"Chun Tian (binghe)" binghe.lisp@gmail.com writes:
You mean: when you connect to a remote address/port, you also want to bind to specified local-address/port?
If so, I'm afraid that no such support in usocket yet.
Yes, that is what I mean Thanks.
Cheers, Chris Dean
Hi, Chris & Erik
I researched networking API of CMUCL, SBCL, Clozure CL, LispWorks, Allegro CL (I have only these 5 CLs installed), to bind local address/ port:
* CMUCL, no such support (yet) but I can learn cmucl source code and make it worked. * SBCL, supported. * Allegro CL, supported. * LispWorks, supported. * Clozure CL, supported.
Above five CLs, I have working patches for "bind-local" support, as in attach.
For other CL platforms, I'll try to install them first. But since I never used them, maybe I cannot do any help...
Regards,
Chun Tian (binghe)
在 2008-7-16,下午5:45, Chris Dean 写道:
"Chun Tian (binghe)" binghe.lisp@gmail.com writes:
You mean: when you connect to a remote address/port, you also want to bind to specified local-address/port?
If so, I'm afraid that no such support in usocket yet.
Yes, that is what I mean Thanks.
Cheers, Chris Dean
2008/7/21 Chun Tian (binghe) binghe.lisp@gmail.com:
Hi, Chris & Erik
I researched networking API of CMUCL, SBCL, Clozure CL, LispWorks, Allegro
CL (I have only these 5 CLs installed), to bind local address/port:
- CMUCL, no such support (yet) but I can learn cmucl source code and make
it worked.
- SBCL, supported.
- Allegro CL, supported.
- LispWorks, supported.
- Clozure CL, supported.
Well, if you use the standard (public) functions in the sb-bsd-sockets package, your solution should work portably from SBCL on ECL, because that uses the same API. The ABCL solution I can do myself as I have it installed (and researched it a bit last weekend): the conclusion is that - at least - it's possible.
CLISP - from the review of the documentation - will not support this feature.
Which leaves LispWorks and Scieneer. Scieneer is very much like CMUCL, so if the latter needs adapting, so does the former (most likely). LispWorks supports :local-address and :local-port keys - at least as of 5.0 which I have installed here.
This means that we can have this feature everywhere but on CLISP... Which sounds enough to implement it [and contact the CLISP authors to implement it on CLISP too].
Above five CLs, I have working patches for "bind-local" support, as in attach.
For other CL platforms, I'll try to install them first. But since I never used them, maybe I cannot do any help...
That's fine. You already saved me many hours of research, meaning we now can make sure it gets in.
Thanks a lot for your efforts!
(By the way, I hope you don't mind if I take your patch as a guideline, not as the final one - especially the SBCL backend is changed more than I'd like: it could be a 4 line change.)
Once more: thanks a lot!
Bye,
Erik.
Mostly implemented now and on the 0.4.x branch.
Bye,
Erik.
2008/7/21 Chun Tian (binghe) binghe.lisp@gmail.com:
Hi, Chris & Erik
I researched networking API of CMUCL, SBCL, Clozure CL, LispWorks, Allegro CL (I have only these 5 CLs installed), to bind local address/port:
- CMUCL, no such support (yet) but I can learn cmucl source code and make
it worked.
- SBCL, supported.
- Allegro CL, supported.
- LispWorks, supported.
- Clozure CL, supported.
Above five CLs, I have working patches for "bind-local" support, as in attach.
For other CL platforms, I'll try to install them first. But since I never used them, maybe I cannot do any help...
Regards,
Chun Tian (binghe)
在 2008-7-16,下午5:45, Chris Dean 写道:
"Chun Tian (binghe)" binghe.lisp@gmail.com writes:
You mean: when you connect to a remote address/port, you also want to bind to specified local-address/port?
If so, I'm afraid that no such support in usocket yet.
Yes, that is what I mean Thanks.
Cheers, Chris Dean
usocket-devel mailing list usocket-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/usocket-devel
"Erik Huelsmann" ehuels@gmail.com writes:
Mostly implemented now and on the 0.4.x branch.
Great work, thanks.
Cheers, Chris Dean
Hi Chris,
"Chun Tian (binghe)" binghe.lisp@gmail.com writes:
You mean: when you connect to a remote address/port, you also want to bind to specified local-address/port?
If so, I'm afraid that no such support in usocket yet.
Yes, that is what I mean Thanks.
On the CMUCL development list, Chun Tian is lobbying for implementing this feature in it, so usocket can use it. However, he's meeting some resistance, because people can't envision the use-case - and as a matter of fact, so have I. Could you describe yours to us, so we understand what it is that you're trying to do?
Thanks in advance!
Bye,
Erik.
"Erik Huelsmann" ehuels@gmail.com writes:
On the CMUCL development list, Chun Tian is lobbying for implementing this feature in it, so usocket can use it. However, he's meeting some resistance, because people can't envision the use-case - and as a matter of fact, so have I. Could you describe yours to us, so we understand what it is that you're trying to do?
Sure thing. Before I do, I will mention that this is a commonly available in many tools, ssh -b is one example.
The situation I currently have is a machine with two different ethernet ports and two different IP addresses. Each of these IP addresses routes to the Internet through different gateways. I also have two services (call them A and B) on the Internet that I access from this machine.
Due to factors beyond my control, service A is only authorized from IP address #1 and service B is only authorized from IP address #2.
Binding to different local addresses lets me access both services from the same application. This is what I am doing now with the LispWorks api.
Cheers, Chris Dean
"Erik Huelsmann" ehuels@gmail.com writes:
On the CMUCL development list, Chun Tian is lobbying for implementing this feature in it, so usocket can use it. However, he's meeting some resistance, because people can't envision the use-case - and as a matter of fact, so have I. Could you describe yours to us, so we understand what it is that you're trying to do?
Sure thing. Before I do, I will mention that this is a commonly available in many tools, ssh -b is one example.
The situation I currently have is a machine with two different ethernet ports and two different IP addresses. Each of these IP addresses routes to the Internet through different gateways. I also have two services (call them A and B) on the Internet that I access from this machine.
Nice. And I said this twice on cmucl-imp...
Due to factors beyond my control, service A is only authorized from IP address #1 and service B is only authorized from IP address #2.
Binding to different local addresses lets me access both services from the same application. This is what I am doing now with the LispWorks api.
Cheers, Chris Dean
"Chun Tian (binghe)" binghe.lisp@gmail.com writes:
Nice. And I said this twice on cmucl-imp...
Thanks for the perseverance. It is a funny sort of discussion since bind(2) is part of the the standard TCP/IP api. I am having trouble thinking of a system that doesn't support bind! Perl, Python, Ruby, Squeak, PLT Scheme, SBCL, etc all have bind.
Cheers, Chris Dean
Oh no, this discuss let me start to think another usocket API extension:
How can you get your OS's interface addresses through a programming method? If there's more than one of them?
For example, on Linux, if you have lo, eth0 and eth1, i.e. two link plus the loopback, how can you get the three addresses (one of them is 127.0.0.1)? Again, no portable method, no such support in usocket. Actually, almost no CL's networking API support this. But, in most C- based networking programming, It's the most fundamental step in server side programming.
But, I think, to support this (most of time, unuse) feature, it's also quite trivial: direct use each CL's existing networking code plus FFI, 10~20 lines of code per implementation should work.
Oh, seems I'm going too far... Just forget this brain storm if no one need it:) In the future, if some guys start to write servers (smtp, pop3, or other httpd) in CL, this feature (auto choose interfaces to listen) may be needed.
Regards,
Chun Tian (binghe)
在 2008-7-26,上午9:36, Chris Dean 写道:
"Chun Tian (binghe)" binghe.lisp@gmail.com writes:
Nice. And I said this twice on cmucl-imp...
Thanks for the perseverance. It is a funny sort of discussion since bind(2) is part of the the standard TCP/IP api. I am having trouble thinking of a system that doesn't support bind! Perl, Python, Ruby, Squeak, PLT Scheme, SBCL, etc all have bind.
Cheers, Chris Dean