From guo364 at oki.com Tue Aug 19 12:54:05 2003 From: guo364 at oki.com (guo zhenglin) Date: Tue Aug 19 05:54:22 2003 Subject: [ds6-devel] why I MUST set a value to scope_id? Message-ID: <003901c36605$8d453ae0$584911ac@t80c88> 1) I use "getaddrinfo" , then socket(), then connect() it return "Inavlid argument" error 2) then I use: ((struct sockaddr_in6 *)(res1->ai_addr))->sin6_scope_id =3 /* 3 is my eth0 index */ then connect() is ok ,and send,recv also ok 3) I have test it on linux kernel 2.4.7-10 and 2.4.20 both linux kernel have this problem. 4) my client program is following: #include #include #include #include #include int main(void) { int mysock, myerr; int i; struct addrinfo hints, *res0, *res1; char rcvmsg[100]; char sndmsg[100]; int rcvlen; memset(&hints, 0, sizeof(hints)); hints.ai_family = PF_UNSPEC; hints.ai_socktype = SOCK_STREAM; myerr = getaddrinfo("fe80::210:5cff:fed7:46c6","5001", &hints, &res0); if(myerr) return -1; printf("\n getaddrinfo success"); for(res1 = res0; res1; res1 = res1->ai_next) { printf("\n--------------------------------"); printf("\n ai_flags:%d", res1->ai_flags); printf("\n ai_family:%d", res1->ai_family); printf("\n ai_socktype:%d", res1->ai_socktype); printf("\n ai_protocol:%d", res1->ai_protocol); printf("\n ai_addrlen:%d", res1->ai_addrlen); printf("\n ai_cannonname:%s", res1->ai_canonname); printf("\n ai_next:%p", res1->ai_next); printf("\n ai_addr:"); for(i=0; iai_addrlen; i++) printf("%02X ",(*((char *)(res1->ai_addr)+i))&0xFF); printf("\n IP:%d", (res1->ai_family==PF_INET6)? 6:4); printf("\n------------------------------------"); mysock = socket(res1->ai_family, res1->ai_socktype, res1->ai_protocol); if(mysock<0){ printf("\n socket fail"); continue;} printf("\n socket success"); ((struct sockaddr_in6 *)(res1->ai_addr))->sin6_scope_id =3 ; /* ??? */ printf("\n connecting...\n"); if(connect(mysock, res1->ai_addr, res1->ai_addrlen)<0) { perror("\n connect fail"); close(mysock); continue; } printf("\n connect succ"); memset(rcvmsg, 0, 100); rcvlen = recv(mysock, rcvmsg, 100, 0); printf("\n recvlen:%d", rcvlen); printf("\n recvmsg:%s", rcvmsg); strcpy(sndmsg, "THIS is a MSG from CLIENT side"); send(mysock, sndmsg, strlen(sndmsg),0); } close(mysock); printf("\n bye \n"); } From eva at gsyc.escet.urjc.es Tue Aug 19 11:12:50 2003 From: eva at gsyc.escet.urjc.es (Eva M. Castro) Date: Tue Aug 19 10:14:23 2003 Subject: [ds6-devel] why I MUST set a value to scope_id? In-Reply-To: <003901c36605$8d453ae0$584911ac@t80c88> References: <003901c36605$8d453ae0$584911ac@t80c88> Message-ID: <3F41DC02.5070904@gsyc.escet.urjc.es> Suppose you have multiple ethernet adapters, if you use a link local address as destination, your host does not know which ethernet adapter use to send the packet. It is an ambiguos destination address if you dont use the scope identifier in order to specify which ethernet adapter should be used. IMHO you should avoid using link local addresses from applications. regards, eva guo zhenglin wrote: >1) I use "getaddrinfo" , > then socket(), >then connect() >it return "Inavlid argument" error > >2) then I use: > >((struct sockaddr_in6 *)(res1->ai_addr))->sin6_scope_id =3 > /* 3 is my eth0 index */ > >then connect() is ok ,and send,recv also ok > >3) I have test it on linux kernel 2.4.7-10 and 2.4.20 > both linux kernel have this problem. > >4) my client program is following: > >#include > >#include >#include >#include >#include > >int main(void) >{ > int mysock, myerr; > int i; > struct addrinfo hints, *res0, *res1; > char rcvmsg[100]; > char sndmsg[100]; > int rcvlen; > > memset(&hints, 0, sizeof(hints)); > hints.ai_family = PF_UNSPEC; > hints.ai_socktype = SOCK_STREAM; > > myerr = getaddrinfo("fe80::210:5cff:fed7:46c6","5001", &hints, &res0); > if(myerr) return -1; > > printf("\n getaddrinfo success"); > > for(res1 = res0; res1; res1 = res1->ai_next) > { > printf("\n--------------------------------"); > printf("\n ai_flags:%d", res1->ai_flags); > printf("\n ai_family:%d", res1->ai_family); > printf("\n ai_socktype:%d", res1->ai_socktype); > printf("\n ai_protocol:%d", res1->ai_protocol); > printf("\n ai_addrlen:%d", res1->ai_addrlen); > printf("\n ai_cannonname:%s", res1->ai_canonname); > printf("\n ai_next:%p", res1->ai_next); > printf("\n ai_addr:"); > for(i=0; iai_addrlen; i++) > printf("%02X ",(*((char *)(res1->ai_addr)+i))&0xFF); > printf("\n IP:%d", (res1->ai_family==PF_INET6)? 6:4); > > printf("\n------------------------------------"); > > mysock = socket(res1->ai_family, res1->ai_socktype, res1->ai_protocol); > if(mysock<0){ printf("\n socket fail"); continue;} > printf("\n socket success"); > > ((struct sockaddr_in6 *)(res1->ai_addr))->sin6_scope_id =3 ; /* ??? */ > > printf("\n connecting...\n"); > if(connect(mysock, res1->ai_addr, res1->ai_addrlen)<0) > { > perror("\n connect fail"); > close(mysock); > continue; > } > printf("\n connect succ"); > memset(rcvmsg, 0, 100); > rcvlen = recv(mysock, rcvmsg, 100, 0); > printf("\n recvlen:%d", rcvlen); > printf("\n recvmsg:%s", rcvmsg); > strcpy(sndmsg, "THIS is a MSG from CLIENT side"); > send(mysock, sndmsg, strlen(sndmsg),0); > > } > close(mysock); > printf("\n bye \n"); > >} > > >_______________________________________________ >ds6-devel mailing list >ds6-devel@deepspace6.net >http://lists.deepspace6.net/listinfo/ds6-devel > > > From guo364 at oki.com Tue Aug 19 17:49:02 2003 From: guo364 at oki.com (guo zhenglin) Date: Tue Aug 19 10:49:44 2003 Subject: [ds6-devel] why I MUST set a value to scope_id? References: <003901c36605$8d453ae0$584911ac@t80c88> <3F41DC02.5070904@gsyc.escet.urjc.es> Message-ID: <004701c3662e$bec8df30$584911ac@t80c88> thanks very much!! My linux machine have TWO ethernet adapters. now I config ip address on one adapter to 3ffe:2400:xxxx, then from another linux machine ,CAN connect to it without set scope_id=3 value ( default scope_id=0) !! ----- Original Message ----- From: "Eva M. Castro" To: "guo zhenglin" Cc: Sent: Tuesday, August 19, 2003 4:12 PM Subject: Re: [ds6-devel] why I MUST set a value to scope_id? > Suppose you have multiple ethernet adapters, if you use a link local > address as destination, your host does not know which ethernet adapter > use to send the packet. It is an ambiguos destination address if you > dont use the scope identifier in order to specify which ethernet adapter > should be used. > > IMHO you should avoid using link local addresses from applications. > > regards, > > eva > > guo zhenglin wrote: > > >1) I use "getaddrinfo" , > > then socket(), > >then connect() > >it return "Inavlid argument" error > > > >2) then I use: > > > >((struct sockaddr_in6 *)(res1->ai_addr))->sin6_scope_id =3 > > /* 3 is my eth0 index */ > > > >then connect() is ok ,and send,recv also ok > > > >3) I have test it on linux kernel 2.4.7-10 and 2.4.20 > > both linux kernel have this problem. > > > >4) my client program is following: > > > >#include > > > >#include > >#include > >#include > >#include > > > >int main(void) > >{ > > int mysock, myerr; > > int i; > > struct addrinfo hints, *res0, *res1; > > char rcvmsg[100]; > > char sndmsg[100]; > > int rcvlen; > > > > memset(&hints, 0, sizeof(hints)); > > hints.ai_family = PF_UNSPEC; > > hints.ai_socktype = SOCK_STREAM; > > > > myerr = getaddrinfo("fe80::210:5cff:fed7:46c6","5001", &hints, &res0); > > if(myerr) return -1; > > > > printf("\n getaddrinfo success"); > > > > for(res1 = res0; res1; res1 = res1->ai_next) > > { > > printf("\n--------------------------------"); > > printf("\n ai_flags:%d", res1->ai_flags); > > printf("\n ai_family:%d", res1->ai_family); > > printf("\n ai_socktype:%d", res1->ai_socktype); > > printf("\n ai_protocol:%d", res1->ai_protocol); > > printf("\n ai_addrlen:%d", res1->ai_addrlen); > > printf("\n ai_cannonname:%s", res1->ai_canonname); > > printf("\n ai_next:%p", res1->ai_next); > > printf("\n ai_addr:"); > > for(i=0; iai_addrlen; i++) > > printf("%02X ",(*((char *)(res1->ai_addr)+i))&0xFF); > > printf("\n IP:%d", (res1->ai_family==PF_INET6)? 6:4); > > > > printf("\n------------------------------------"); > > > > mysock = socket(res1->ai_family, res1->ai_socktype, res1->ai_protocol); > > if(mysock<0){ printf("\n socket fail"); continue;} > > printf("\n socket success"); > > > > ((struct sockaddr_in6 *)(res1->ai_addr))->sin6_scope_id =3 ; /* ??? */ > > > > printf("\n connecting...\n"); > > if(connect(mysock, res1->ai_addr, res1->ai_addrlen)<0) > > { > > perror("\n connect fail"); > > close(mysock); > > continue; > > } > > printf("\n connect succ"); > > memset(rcvmsg, 0, 100); > > rcvlen = recv(mysock, rcvmsg, 100, 0); > > printf("\n recvlen:%d", rcvlen); > > printf("\n recvmsg:%s", rcvmsg); > > strcpy(sndmsg, "THIS is a MSG from CLIENT side"); > > send(mysock, sndmsg, strlen(sndmsg),0); > > > > } > > close(mysock); > > printf("\n bye \n"); > > > >} > > > > > >_______________________________________________ > >ds6-devel mailing list > >ds6-devel@deepspace6.net > >http://lists.deepspace6.net/listinfo/ds6-devel > > > > > > > > >