From a.hofmann at fhbb.ch Mon Jan 5 15:04:12 2004 From: a.hofmann at fhbb.ch (Andreas Hofmann) Date: Mon Jan 5 15:08:05 2004 Subject: [ds6-devel] problem connecting to ipv6 sockets Message-ID: <200401051504.12638.a.hofmann@fhbb.ch> hi all, i try to port some applications to ipv4/v6 and i try to do this as af-independent as possible. but i ran into problems by connecting to a ipv4/6 daemon by connecting to it via a real ipv6 address. because i don't have a nameserver do do name-address lookups i used the local /etc/hosts file as follows: ---------------------- 127.0.0.1 localhost.fhbb.ch localhost fe80::20b:cdff:fef8:1c32 local6.fhbb.ch local6 ---------------------- i wrote two simple test applications to get on a clue for my problem. the one is a simple server that listens on port 20100 for ipv4 and ipv6 connections. the other is a simple clients which tries to establish a connection to that server and then receives a simple string from that server. for testing i start the server on the same machine as the client. the eth0 config of this machine is: eth0 Protokoll:Ethernet Hardware Adresse 00:0B:CD:F8:1C:32 inet Adresse:10.1.93.108 Bcast:10.1.93.255 Maske:255.255.255.0 inet6 Adresse: fe80::20b:cdff:fef8:1c32/64 G?ltigkeitsbereich:Verbindung UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:63004 errors:2786 dropped:0 overruns:0 frame:2 TX packets:52194 errors:0 dropped:0 overruns:0 carrier:0 Kollisionen:3073 Sendewarteschlangenl?nge:100 RX bytes:22941133 (21.8 Mb) TX bytes:46248518 (44.1 Mb) Interrupt:20 Speicher:fc500000-fc510000 the client is started as follows: ip6client what i can not understand now is, that i can connect to the server by ipv4 address 10.1.93.108. i can see then, that the server produces an ipv4 mapped ipv6 address (::ffff:10.1.93.108) and answers properly to the ipv4 client. i also can connect to the server by the ipv6 loopback address ::1 . but i can not connect neither by using the whole ipv6 address nor by the local6 entry in /etc/hosts. summary: ip6client localhost ---> works ip6client 10.1.93.108 ---> works ip6client ::1 ---> works ! ip6client local6 ---> does not work ip6client fe80::20b:cdff:fef8:1c32 ---> does not work the ipv6 config of my machines should work, because i can ping6 them from everywhere. the sources of these two small apps are below. where is the mistake i made? any ideas? thanks in advance andy. p.s. : Linux version 2.4.21 / gcc version 3.2.2 / Mandrake Linux 9.1 3.2.2 ------------------------IP6SERVER--------------------- #include #include #include #include #include #include #include /* getrusage() */ #include #include /* malloc(3) */ #include #include #include #include int main(int argc, char **argv){ int sockfd, connfd, error; socklen_t addrlen; struct sockaddr_storage clientaddr; char clienthost[100], clientservice[6]; struct addrinfo hints, *res, *ressave; memset(&hints, 0, sizeof(hints)); hints.ai_flags = AI_PASSIVE; hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; sockfd = -1; error = getaddrinfo(NULL, "20100", &hints, &res); if(error){ perror(gai_strerror(error)); exit(-4); } else{ ressave = res; while(res){ sockfd=socket(res->ai_family, res->ai_socktype, res->ai_protocol); if(!(sockfd < 0)){ if(bind(sockfd, res->ai_addr, res->ai_addrlen) == 0){ break; }; close(sockfd); sockfd = -1; } res = res->ai_next; }; if(sockfd < 0){ freeaddrinfo(ressave); fprintf(stderr, "socket error:: could not open socket\n"); return -1; }; listen(sockfd, 20); freeaddrinfo(ressave); for( ; ; ){ addrlen = sizeof(clientaddr); connfd = accept(sockfd, (struct sockaddr *) &clientaddr, &addrlen); if(connfd < 0){ continue; }; getnameinfo((struct sockaddr *) &clientaddr, addrlen, clienthost, sizeof(clienthost), clientservice, sizeof(clientservice), NI_NUMERICHOST); if(!(connfd < 0)){ printf("Anfrage erhalten: Host=[%s] remote Port=[%s]\n",clienthost, clientservice); char msg[200]; sprintf(msg, "Hallo [%s], habe die Anfrage von deinem Port [%s] erhalten\n", clienthost, clientservice); error = send(connfd, &msg, sizeof(msg), 0); }; }; }; return 1; }; ------------------------------------------------------------ ------------------------IP6CLIENT----------------------- #include #include #include #include #include #include #include #include /* malloc(3) */ #include #include #include #include int main(int argc, char **argv){ int sockfd, connfd, error; int addrlen; char serverhost[1000], hostname[100]; struct addrinfo hints, *res, *ressave; strcpy(hostname, argv[1]); memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; error = getaddrinfo(hostname, "20100", &hints, &res); if(error < 0){ fprintf(stderr, "getaddrinfo error:: [%s]\n", gai_strerror(error)); exit(-4); } ressave = res; sockfd = -1; while(res){ sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); if(!(sockfd < 0)) { if(connect(sockfd, res->ai_addr, res->ai_addrlen)==0){ printf("successfully connected::\n"); break; }; fprintf(stderr, "connect error:: [%s]\n", gai_strerror(errno)); close(sockfd); sockfd = -1; }; res = res->ai_next; }; freeaddrinfo(ressave); if(sockfd < 0){ fprintf(stderr, "socket error:: could not open socket\n"); return -1; }; char buf[200]; error = recv(sockfd, &buf, sizeof(buf), 0); if(error == -1){ perror(gai_strerror(errno)); exit(-4); } printf("Meldung erhalten: %s\n", buf); return 1; }; ------------------------------------------------------------ From parijat at i2r.a-star.edu.sg Tue Jan 6 14:33:00 2004 From: parijat at i2r.a-star.edu.sg (Parijat) Date: Tue Jan 6 07:33:14 2004 Subject: [ds6-devel] problem connecting to ipv6 sockets In-Reply-To: <200401051504.12638.a.hofmann@fhbb.ch> References: <200401051504.12638.a.hofmann@fhbb.ch> Message-ID: <20040106063300.GA13683@i2r.a-star.edu.sg> Hello, comments below: On Mon, Jan 05, 2004 at 03:04:12PM +0100, Andreas Hofmann wrote: > ip6client local6 ---> does not work > ip6client fe80::20b:cdff:fef8:1c32 ---> does not work The problem with the above two is that the clien is trying to make a connection to a "link-local" address. One requirement of sockets using or connecting to link-local addresses is that the interface on which the connection should be made must also be specified. I think this is the 'sin6_scopeid' field in struct sockaddr_in6. On Linux this should be the interface index. If you really want to find the interface index programmatically, look at netdeivce(7) (on Debian at least), for the documentation to appropriate ioctls(). If you are just trying to test, then set the scopeid to 0 or 1 (...) and by any luck things should just work. > the ipv6 config of my machines should work, because i can ping6 them from > everywhere. I would be surprised if you were able to ping the link-local address from another machine without telling ping6 which interface to ping from (i.e., something like 'ping6 -i eth0
'. > > the sources of these two small apps are below. where is the mistake i made? > any ideas? > if(connect(sockfd, res->ai_addr, res->ai_addrlen)==0){ Here, connect expects that res->ai_addr.sin6_scopeif would contain a valid interface id, and IMO getaddrinfo() does not set this. -- Sincerely, Parijat Mishra parijat@i2r.a-star.edu.sg Tel: +65 6874 6243 From lionel at mamane.lu Tue Jan 6 08:14:23 2004 From: lionel at mamane.lu (Lionel Elie Mamane) Date: Tue Jan 6 08:20:52 2004 Subject: [ds6-devel] problem connecting to ipv6 sockets In-Reply-To: <20040106063300.GA13683@i2r.a-star.edu.sg> References: <200401051504.12638.a.hofmann@fhbb.ch> <20040106063300.GA13683@i2r.a-star.edu.sg> Message-ID: <20040106071423.GA4279@tofu.mamane.lu> On Tue, Jan 06, 2004 at 02:33:00PM +0800, Parijat wrote: > On Mon, Jan 05, 2004 at 03:04:12PM +0100, Andreas Hofmann wrote: >> ip6client local6 ---> does not work >> ip6client fe80::20b:cdff:fef8:1c32 ---> does not work > The problem with the above two is that the clien is trying to make a > connection to a "link-local" address. One requirement of sockets > using or connecting to link-local addresses is that the interface on > which the connection should be made must also be specified. Indeed. Try this: ip6client fe80::20b:cdff:fef8:1c32%eth0 >> the sources of these two small apps are below. where is the mistake i made? >> any ideas? >> if(connect(sockfd, res->ai_addr, res->ai_addrlen)==0){ > Here, connect expects that res->ai_addr.sin6_scopeif would contain a > valid interface id, and IMO getaddrinfo() does not set this. It does, if the address contains the %eth0 part. -- Lionel -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Digital signature Url : http://lists.deepspace6.net/archive/ds6-devel/attachments/20040106/84ba1f3f/attachment.bin From a.hofmann at fhbb.ch Tue Jan 6 09:20:50 2004 From: a.hofmann at fhbb.ch (Andreas Hofmann) Date: Tue Jan 6 09:24:46 2004 Subject: [ds6-devel] problem connecting to ipv6 sockets In-Reply-To: <20040106071423.GA4279@tofu.mamane.lu> References: <200401051504.12638.a.hofmann@fhbb.ch> <20040106063300.GA13683@i2r.a-star.edu.sg> <20040106071423.GA4279@tofu.mamane.lu> Message-ID: <200401060919.35477.a.hofmann@fhbb.ch> thanks a lot, it is exactly what is wrong! and by coincidence, after days of work with this problem, i wondered yesterday why i have to allways use the -I eth0 parameter with ping6. a look at getaddrinfo man page (Extension for scoped IPv6 address) gave me a hint. the %eth0 at the end of the address solves the problem. the next time i will write sooner to this list! i could have saved a lot of time. thanks! Am Dienstag, 6. Januar 2004 08.14 schrieb Lionel Elie Mamane: > On Tue, Jan 06, 2004 at 02:33:00PM +0800, Parijat wrote: > > On Mon, Jan 05, 2004 at 03:04:12PM +0100, Andreas Hofmann wrote: > >> ip6client local6 ---> does not work > >> ip6client fe80::20b:cdff:fef8:1c32 ---> does not work > > > > The problem with the above two is that the clien is trying to make a > > connection to a "link-local" address. One requirement of sockets > > using or connecting to link-local addresses is that the interface on > > which the connection should be made must also be specified. > > Indeed. Try this: > > ip6client fe80::20b:cdff:fef8:1c32%eth0 > > >> the sources of these two small apps are below. where is the mistake i > >> made? any ideas? > >> if(connect(sockfd, res->ai_addr, res->ai_addrlen)==0){ > > > > Here, connect expects that res->ai_addr.sin6_scopeif would contain a > > valid interface id, and IMO getaddrinfo() does not set this. > > It does, if the address contains the %eth0 part. From chris at leishman.org Thu Jan 8 23:30:41 2004 From: chris at leishman.org (Chris Leishman) Date: Fri Jan 9 00:30:47 2004 Subject: [ds6-devel] Re: [nc6-commit] nc6/src connection.h, 1.18, 1.19 misc.c, 1.21, 1.22 misc.h, 1.20, 1.21 network.c, 1.48, 1.49 parser.c, 1.56, 1.57 In-Reply-To: <20040108171856.9C2EB1F7046@liston.ferrara.linux.it>; from mauro@deepspace6.net on Thu, Jan 08, 2004 at 06:18:56PM +0100 References: <20040108171856.9C2EB1F7046@liston.ferrara.linux.it> Message-ID: <20040108233041.A717@server2.24hostingnow.com> On Thu, Jan 08, 2004 at 06:18:56PM +0100, mauro@deepspace6.net wrote: > Update of /cvs/nc6/src > > Modified Files: > connection.h misc.c misc.h network.c parser.c > Log Message: > added bluez support. used SOMAXCONN as the backlog parameter in listen(2). cleaned up definition of the long_options array. Hi Mauro! Couple of comments: 1. You should define SOMAXCONN using autoconf (patch attached - don't have my ssh key handy). 2. Can you give a bit of detail on the bluetooth stuff? I noticed that you have defined totaly separate listen/connect function for IP and bluetooth - why is this needed? I would have thought the code was AF independant enough (thats the points of AF independance). Also, the name do_connect_ip isn't really correct since it's generic code (not required to be just ip). 3. I don't see where HAVE_BLUEZ is defined? Otherwise, hows things? Regards, Chris -------------- next part -------------- Index: configure.ac =================================================================== RCS file: /ds6/cvs/nc6/configure.ac,v retrieving revision 1.30 diff -u -u -r1.30 configure.ac --- configure.ac 18 Aug 2003 09:49:37 -0000 1.30 +++ configure.ac 8 Jan 2004 23:25:56 -0000 @@ -50,6 +50,7 @@ TYPE_SOCKLEN_T TYPE_STRUCT_SOCKADDR_STORAGE(, [AC_MSG_ERROR([Your system does not support 'struct sockaddr_storage', which is needed to compile nc6])]) +DEFINED_SOMAXCONN(,AC_DEFINE([SOMAXCONN], 5, [Backlog for listen.])) dnl Configure IPv6 support Index: src/misc.c =================================================================== RCS file: /ds6/cvs/nc6/src/misc.c,v retrieving revision 1.22 diff -u -u -r1.22 misc.c --- src/misc.c 8 Jan 2004 17:18:54 -0000 1.22 +++ src/misc.c 8 Jan 2004 23:25:57 -0000 @@ -37,7 +37,9 @@ #endif #ifdef HAVE_BLUEZ +#ifdef HAVE_STDINT_H #include /* needed for uint8_t */ +#endif #include #endif @@ -228,6 +230,8 @@ return ((int)res); } #endif + + #ifdef HAVE_BLUEZ int safe_ba2str(const bdaddr_t *ba, char *str, size_t strlen) Index: src/network.c =================================================================== RCS file: /ds6/cvs/nc6/src/network.c,v retrieving revision 1.49 diff -u -u -r1.49 network.c --- src/network.c 8 Jan 2004 17:18:54 -0000 1.49 +++ src/network.c 8 Jan 2004 23:25:58 -0000 @@ -52,13 +52,6 @@ #define CONNECTION_TIMEOUT -1 #define CONNECTION_FAILED -2 -/* for SOCK_STREAM and SOCK_SEQPACKET sockets, we need to listen for - * incoming connections. the backlog parameter is set to 5 for backward - * compatibility (as it seems that at least some BSD-derived system limit - * the backlog parameter to this value). */ -#ifndef SOMAXCONN -#define SOMAXCONN 5 -#endif static int connect_with_timeout(int fd, const struct sockaddr *sa, socklen_t salen, int timeout); --- /dev/null +++ config/somaxconn_constant.m4 2004-01-09 09:35:14.000000000 +1100 @@ -0,0 +1,22 @@ +AC_DEFUN([DEFINED_SOMAXCONN],[ + AC_CACHE_CHECK([if system defines SOMAXCONN], + [ds6_cv_defined_somaxconn],[ + AC_TRY_CPP([ +#include + +#ifndef SOMAXCONN +#error Missing SOMAXCONN +#endif + ],[ + ds6_cv_defined_somaxconn=yes + ],[ + ds6_cv_defined_somaxconn=no + ]) + ]) + + if test "X$ds6_cv_defined_somaxconn" = "Xyes"; then : + $1 + else : + $2 + fi +]) From mauro at deepspace6.net Fri Jan 9 01:08:09 2004 From: mauro at deepspace6.net (Mauro Tortonesi) Date: Fri Jan 9 01:30:10 2004 Subject: [ds6-devel] Re: [nc6-commit] nc6/src connection.h, 1.18, 1.19 misc.c, 1.21, 1.22 misc.h, 1.20, 1.21 network.c, 1.48, 1.49 parser.c, 1.56, 1.57 In-Reply-To: <20040108233041.A717@server2.24hostingnow.com> References: <20040108171856.9C2EB1F7046@liston.ferrara.linux.it> <20040108233041.A717@server2.24hostingnow.com> Message-ID: <200401090108.09661.mauro@deepspace6.net> On Friday 09 January 2004 00:30, Chris Leishman wrote: > On Thu, Jan 08, 2004 at 06:18:56PM +0100, mauro@deepspace6.net wrote: > > Update of /cvs/nc6/src > > > > Modified Files: > > connection.h misc.c misc.h network.c parser.c > > Log Message: > > added bluez support. used SOMAXCONN as the backlog parameter in > > listen(2). cleaned up definition of the long_options array. > > Hi Mauro! > > Couple of comments: > > 1. You should define SOMAXCONN using autoconf (patch attached - don't have > my ssh key handy). thanks, i will apply it tomorrow. > 2. Can you give a bit of detail on the bluetooth stuff? I noticed that you > have defined totaly separate listen/connect function for IP and bluetooth - > why is this needed? I would have thought the code was AF independant > enough (thats the points of AF independance). the problem with AF independance and bluez is that you can't resolve a bluez name with getaddrinfo. and this is quite a big problem... > Also, the name do_connect_ip isn't really correct since it's generic code > (not required to be just ip). right, but it's only a preliminary version ;-) > 3. I don't see where HAVE_BLUEZ is defined? in fact, i still have to code it :-P -- Aequam memento rebus in arduis servare mentem... Mauro Tortonesi mauro@deepspace6.net mauro@ferrara.linux.it Deep Space 6 - IPv6 on Linux http://www.deepspace6.net Ferrara Linux Users Group http://www.ferrara.linux.it From mtortonesi at ing.unife.it Wed Jan 14 15:09:31 2004 From: mtortonesi at ing.unife.it (Mauro Tortonesi) Date: Wed Jan 14 15:09:26 2004 Subject: [ds6-devel] nc6 development Message-ID: <200401141509.31269.mtortonesi@ing.unife.it> i have just committed filippo's rfc3493-compliance patch to the nc6 cvs repository. the only things remained to do before releasing nc6 0.6 are: * check i18n (upgrade included intl and check if the po stuff is broken) * add bluez detection to configure.ac * test and cleanup of the bluez code chris, can you help me to check the i18n support? i would really like to ship a few translations with nc6 0.7. anyone offers to help here? -- Aequam memento rebus in arduis servare mentem... Mauro Tortonesi mtortonesi@ing.unife.it mauro@deepspace6.net mauro@ferrara.linux.it Deep Space 6 - IPv6 with Linux http://www.deepspace6.net Ferrara Linux User Group http://www.ferrara.linux.it From chris at leishman.org Thu Jan 15 03:18:29 2004 From: chris at leishman.org (Chris Leishman) Date: Thu Jan 15 04:18:35 2004 Subject: [ds6-devel] nc6 development In-Reply-To: <200401141509.31269.mtortonesi@ing.unife.it>; from mtortonesi@ing.unife.it on Wed, Jan 14, 2004 at 03:09:31PM +0100 References: <200401141509.31269.mtortonesi@ing.unife.it> Message-ID: <20040115031829.A4003@server2.24hostingnow.com> On Wed, Jan 14, 2004 at 03:09:31PM +0100, Mauro Tortonesi wrote: > > i have just committed filippo's rfc3493-compliance patch to the nc6 cvs > repository. the only things remained to do before releasing nc6 0.6 are: > > * check i18n (upgrade included intl and check if the po stuff is broken) > * add bluez detection to configure.ac > * test and cleanup of the bluez code > > chris, can you help me to check the i18n support? Here's my thoughts: 1. Updated i18n to use the latest gettext. 2. Cleanup the bluez code - I think we should split network.c into network.c, generic.c and bluez.c. network.c would just direct calls to do_connect, etc, to the real implementation appropriate for the address family. Regards, chris From mtortonesi at ing.unife.it Fri Jan 16 10:57:57 2004 From: mtortonesi at ing.unife.it (Mauro Tortonesi) Date: Fri Jan 16 10:57:54 2004 Subject: [ds6-devel] nc6 development In-Reply-To: <20040115031829.A4003@server2.24hostingnow.com> References: <200401141509.31269.mtortonesi@ing.unife.it> <20040115031829.A4003@server2.24hostingnow.com> Message-ID: <200401161057.57901.mtortonesi@ing.unife.it> On Thursday 15 January 2004 04:18, you wrote: > On Wed, Jan 14, 2004 at 03:09:31PM +0100, Mauro Tortonesi wrote: > > i have just committed filippo's rfc3493-compliance patch to the nc6 cvs > > repository. the only things remained to do before releasing nc6 0.6 are: > > > > * check i18n (upgrade included intl and check if the po stuff is broken) > > * add bluez detection to configure.ac > > * test and cleanup of the bluez code > > > > chris, can you help me to check the i18n support? > > Here's my thoughts: > > 1. Updated i18n to use the latest gettext. do you mean you have already checked or updated the i18 support code? i haven't seen any commit on cvs. > 2. Cleanup the bluez code - I think we should split network.c into > network.c, generic.c and bluez.c. network.c would just direct calls to > do_connect, etc, to the real implementation appropriate for the address > family. good idea. we could also write a getaddrinfo_ex wrapper function to handle also the AF_BLUETOOTH case. -- Aequam memento rebus in arduis servare mentem... Mauro Tortonesi mtortonesi@ing.unife.it mauro@deepspace6.net mauro@ferrara.linux.it Deep Space 6 - IPv6 with Linux http://www.deepspace6.net Ferrara Linux User Group http://www.ferrara.linux.it