unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Local interface used for outbound network connections
@ 2003-01-07 22:43 Mario Lang
  2003-01-08 11:50 ` Kim F. Storm
  2003-01-09  7:28 ` Richard Stallman
  0 siblings, 2 replies; 7+ messages in thread
From: Mario Lang @ 2003-01-07 22:43 UTC (permalink / raw)


Hello.

We're now working on DCC server support for erc, which involes using
make-network-prcess :server t.  First of all, thanks to all people involved
with that functionality for their work!  It seem possible, we're only missing
one vital bit of information:

For IRC DCC connection, we need a reliable way to optain the IP
address we're reachable via.  Normally, IRC clients do this by calling
getsockname on the connection they have to the IRC server.  This
returns the interface used + port number.

Emacs does (as far as I could see) currently not support this in any way.
We'd need to do ugly hacks with ifconfig or whatever, to optain the
currently used IP, and this is not really portable.

But with a very small addition to make-network-process, we can record
the local address used for outbound tcp connections.

I've attached the patch.  As usual, I'm not good at C, and I'm sure
something is wrong, but it works.  I originally wanted to use
:local, but it appears that indicates server processes, and did not
work.  So I creates a new keyword symbol, :iface.  I know the name is bad,
any suggestions for a better name would be nice.

Here is what process-contact reports for my currently active irc connection:
(process-contact erc-process t)
=> (:name "erc-irc.eu.freenode.net-6667"
    :buffer #<buffer irc.eu.freenode.net:6667>
    :host "irc.eu.freenode.net"
    :service 6667
    :remote [195 139 52 134 6667]
    :iface [80 109 223 66 33231]
    :filter erc-process-filter)

Can someone comment on this.  Could we please install that in some form?

Thank you

*** process.c.~1.388.~	Mon Nov 18 16:40:06 2002
--- process.c	Tue Jan  7 23:26:29 2003
***************
*** 130,136 ****
  Lisp_Object Qopen, Qclosed, Qconnect, Qfailed, Qlisten;
  Lisp_Object Qlocal, Qdatagram;
  Lisp_Object QCname, QCbuffer, QChost, QCservice, QCtype;
! Lisp_Object QClocal, QCremote, QCcoding;
  Lisp_Object QCserver, QCnowait, QCnoquery, QCstop;
  Lisp_Object QCsentinel, QClog, QCoptions;
  Lisp_Object Qlast_nonmenu_event;
--- 130,136 ----
  Lisp_Object Qopen, Qclosed, Qconnect, Qfailed, Qlisten;
  Lisp_Object Qlocal, Qdatagram;
  Lisp_Object QCname, QCbuffer, QChost, QCservice, QCtype;
! Lisp_Object QCiface, QClocal, QCremote, QCcoding;
  Lisp_Object QCserver, QCnowait, QCnoquery, QCstop;
  Lisp_Object QCsentinel, QClog, QCoptions;
  Lisp_Object Qlast_nonmenu_event;
***************
*** 3066,3071 ****
--- 3066,3085 ----
  #endif
        contact = Fplist_put (contact, QCaddress, 
  			    conv_sockaddr_to_lisp (lres->ai_addr, lres->ai_addrlen));
+ #ifdef HAVE_GETSOCKNAME
+       /* Record the address info returned by getsockname
+       if (socktype == SOCK_STREAM && !is_server)
+ 	{
+ 	  struct sockaddr_in sa1;
+ 	  int len1 = sizeof (sa1);
+ 	  if (getsockname (s, (struct sockaddr *)&sa1, &len1) == 0)
+ 	    {
+ 	      contact =
+ 		Fplist_put (contact, QCiface,
+ 			    conv_sockaddr_to_lisp (&sa1, len1));
+ 	    }
+ 	}
+ #endif
      }
  
  #ifdef HAVE_GETADDRINFO
***************
*** 6261,6266 ****
--- 6275,6282 ----
    staticpro (&QCtype);
    QClocal = intern (":local");
    staticpro (&QClocal);
+   QCiface = intern (":iface");
+   staticpro (&QCiface);
    QCremote = intern (":remote");
    staticpro (&QCremote);
    QCcoding = intern (":coding");

-- 
CYa,
  Mario | Debian Developer <URL:http://debian.org/>
        | Get my public key via finger mlang@db.debian.org
        | 1024D/7FC1A0854909BCCDBE6C102DDFFC022A6B113E44

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Local interface used for outbound network connections
  2003-01-07 22:43 Local interface used for outbound network connections Mario Lang
@ 2003-01-08 11:50 ` Kim F. Storm
  2003-01-08 14:49   ` Mario Lang
  2003-01-09  7:28 ` Richard Stallman
  1 sibling, 1 reply; 7+ messages in thread
From: Kim F. Storm @ 2003-01-08 11:50 UTC (permalink / raw)
  Cc: emacs-devel

Mario Lang <mlang@delysid.org> writes:

> For IRC DCC connection, we need a reliable way to optain the IP
> address we're reachable via.  Normally, IRC clients do this by calling
> getsockname on the connection they have to the IRC server.  This
> returns the interface used + port number.

I definitely intended make-network-process to make this info
available, but I forgot to implement it.  Thanks for reminding me :-)

I have just committed the following changes to CVS:

make-network-process now stores the local network address in the
:local property for client processes (i.e. outbound connections).
It does so for all types of connections.

The :local property is the proper place for this, and I don't see why
it wouldn't work (although you said it doesn't).  If you need to
differentiate between client and server processes, look at the
process-status.

I also fixed a bug which meant that the :local property was not setup
correctly for new "slave" processes created when a server process
accepted a new connection.

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Local interface used for outbound network connections
  2003-01-08 11:50 ` Kim F. Storm
@ 2003-01-08 14:49   ` Mario Lang
  2003-01-08 16:39     ` Kim F. Storm
  0 siblings, 1 reply; 7+ messages in thread
From: Mario Lang @ 2003-01-08 14:49 UTC (permalink / raw)
  Cc: emacs-devel

storm@cua.dk (Kim F. Storm) writes:

> Mario Lang <mlang@delysid.org> writes:
>
>> For IRC DCC connection, we need a reliable way to optain the IP
>> address we're reachable via.  Normally, IRC clients do this by calling
>> getsockname on the connection they have to the IRC server.  This
>> returns the interface used + port number.
>
> I definitely intended make-network-process to make this info
> available, but I forgot to implement it.  Thanks for reminding me :-)
>
> I have just committed the following changes to CVS:

Thanks a lot!  Tested, and works here.

(defun erc-dcc-get-host (proc)
  (let ((sockaddr (plist-get (process-contact erc-process t) :local)))
    (when sockaddr
        (mapconcat #'number-to-string (subseq sockaddr 0 4) "."))))

-- 
CYa,
  Mario | Debian Developer <URL:http://debian.org/>
        | Get my public key via finger mlang@db.debian.org
        | 1024D/7FC1A0854909BCCDBE6C102DDFFC022A6B113E44

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Local interface used for outbound network connections
  2003-01-08 14:49   ` Mario Lang
@ 2003-01-08 16:39     ` Kim F. Storm
  2003-01-08 16:54       ` Kim F. Storm
  0 siblings, 1 reply; 7+ messages in thread
From: Kim F. Storm @ 2003-01-08 16:39 UTC (permalink / raw)
  Cc: emacs-devel

Mario Lang <mlang@delysid.org> writes:

> > I definitely intended make-network-process to make this info
> > available, but I forgot to implement it.  Thanks for reminding me :-)
> >
> Thanks a lot!  Tested, and works here.

Good.

> 
> (defun erc-dcc-get-host (proc)
>   (let ((sockaddr (plist-get (process-contact erc-process t) :local)))
>     (when sockaddr
>         (mapconcat #'number-to-string (subseq sockaddr 0 4) "."))))

I just installed a change to format-network-address, so you can now 
omit the port number from the result string.  

You may thus simplify your code like this (format-network-address
returns nil if the address is nil):

(defun erc-dcc-get-host (proc)
  (let ((sockaddr (plist-get (process-contact erc-process t) :local)))
     (format-network-address sockaddr t)))


-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Local interface used for outbound network connections
  2003-01-08 16:39     ` Kim F. Storm
@ 2003-01-08 16:54       ` Kim F. Storm
  0 siblings, 0 replies; 7+ messages in thread
From: Kim F. Storm @ 2003-01-08 16:54 UTC (permalink / raw)
  Cc: emacs-devel

I wrote:

> You may thus simplify your code like this (format-network-address
> returns nil if the address is nil):
> 
> (defun erc-dcc-get-host (proc)
>   (let ((sockaddr (plist-get (process-contact erc-process t) :local)))
>      (format-network-address sockaddr t)))

Actually, you can make this even simpler:

(defun erc-dcc-get-host (proc)
   (format-network-address (process-contact proc :local) t))

I assume that you intended to use the PROC arg rather than erc-process?

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Local interface used for outbound network connections
  2003-01-07 22:43 Local interface used for outbound network connections Mario Lang
  2003-01-08 11:50 ` Kim F. Storm
@ 2003-01-09  7:28 ` Richard Stallman
  2003-01-09 15:27   ` Mario Lang
  1 sibling, 1 reply; 7+ messages in thread
From: Richard Stallman @ 2003-01-09  7:28 UTC (permalink / raw)
  Cc: emacs-devel

The change looks clean to me.  Would someone please install it?

*** process.c.~1.388.~	Mon Nov 18 16:40:06 2002
--- process.c	Tue Jan  7 23:26:29 2003
***************
*** 130,136 ****
  Lisp_Object Qopen, Qclosed, Qconnect, Qfailed, Qlisten;
  Lisp_Object Qlocal, Qdatagram;
  Lisp_Object QCname, QCbuffer, QChost, QCservice, QCtype;
! Lisp_Object QClocal, QCremote, QCcoding;
  Lisp_Object QCserver, QCnowait, QCnoquery, QCstop;
  Lisp_Object QCsentinel, QClog, QCoptions;
  Lisp_Object Qlast_nonmenu_event;
--- 130,136 ----
  Lisp_Object Qopen, Qclosed, Qconnect, Qfailed, Qlisten;
  Lisp_Object Qlocal, Qdatagram;
  Lisp_Object QCname, QCbuffer, QChost, QCservice, QCtype;
! Lisp_Object QCiface, QClocal, QCremote, QCcoding;
  Lisp_Object QCserver, QCnowait, QCnoquery, QCstop;
  Lisp_Object QCsentinel, QClog, QCoptions;
  Lisp_Object Qlast_nonmenu_event;
***************
*** 3066,3071 ****
--- 3066,3085 ----
  #endif
        contact = Fplist_put (contact, QCaddress, 
  			    conv_sockaddr_to_lisp (lres->ai_addr, lres->ai_addrlen));
+ #ifdef HAVE_GETSOCKNAME
+       /* Record the address info returned by getsockname
+       if (socktype == SOCK_STREAM && !is_server)
+ 	{
+ 	  struct sockaddr_in sa1;
+ 	  int len1 = sizeof (sa1);
+ 	  if (getsockname (s, (struct sockaddr *)&sa1, &len1) == 0)
+ 	    {
+ 	      contact =
+ 		Fplist_put (contact, QCiface,
+ 			    conv_sockaddr_to_lisp (&sa1, len1));
+ 	    }
+ 	}
+ #endif
      }
  
  #ifdef HAVE_GETADDRINFO
***************
*** 6261,6266 ****
--- 6275,6282 ----
    staticpro (&QCtype);
    QClocal = intern (":local");
    staticpro (&QClocal);
+   QCiface = intern (":iface");
+   staticpro (&QCiface);
    QCremote = intern (":remote");
    staticpro (&QCremote);
    QCcoding = intern (":coding");

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Local interface used for outbound network connections
  2003-01-09  7:28 ` Richard Stallman
@ 2003-01-09 15:27   ` Mario Lang
  0 siblings, 0 replies; 7+ messages in thread
From: Mario Lang @ 2003-01-09 15:27 UTC (permalink / raw)
  Cc: emacs-devel

Richard Stallman <rms@gnu.org> writes:

> The change looks clean to me.  Would someone please install it?

Kim has already installed the proper fix, plus another
important fix to process.c.  We're now already writing Lisp-level code,
and no futher functionality bugs occured till now.  It seems
the server-process functionality is working as documented now.

-- 
Thanks to everyone involed, this is really a kickass feature!
  Mariok

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2003-01-09 15:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-07 22:43 Local interface used for outbound network connections Mario Lang
2003-01-08 11:50 ` Kim F. Storm
2003-01-08 14:49   ` Mario Lang
2003-01-08 16:39     ` Kim F. Storm
2003-01-08 16:54       ` Kim F. Storm
2003-01-09  7:28 ` Richard Stallman
2003-01-09 15:27   ` Mario Lang

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).