[ds6-devel] why I MUST set a value to scope_id?
Eva M. Castro
eva at gsyc.escet.urjc.es
Tue Aug 19 11:12:50 CEST 2003
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 <stdio.h>
>
>#include <sys/socket.h>
>#include <sys/types.h>
>#include <netdb.h>
>#include <errno.h>
>
>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; i<res1->ai_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 at deepspace6.net
>http://lists.deepspace6.net/listinfo/ds6-devel
>
>
>
More information about the ds6-devel
mailing list