Re: προσπάθεια σύνδεσης με IPv6
Kάνοντας ένα strace το telnet, βλέπω ότι πρώτα γίνεται μια προ-σύνδεση
και στην ipv4 και στην ipv6:
8ymasai oles ekeines tis vlakeies pou legame ston kosmo gia to open
source kai to ti xrhsimo pou einai na exeis dia8esimo ton source kwdika?
E loipon, mantepse! Merikes fores einai ONTWS xrhsimo!
As psaksoume loipon na bgaloume ki ena symperasmataki gia to unix kai to
IPv6 application support genikotera, psaxnontas na doume ti pragmatika
kanei to telnet.
Poio telnet?
Ti erwthsh, ma fysika ayto poy trexei grafontas telnet! To opoio bebaia
einai ena apo ta 23957392057932 pou mporei na exei linked to debian sto
/etc/alternatives/telnet :
telnet 0.17-36
telnet-ssl 0.17.24+0.1-21
heimdal-clients 1.2.dfsg.1-2.1
krb5-clients 1.6.dfsg.4~beta1-5lenny2
inetutils-telnet 2:1.5.dfsg.1-9
8a dialeksw ena sthn tyxh. As poume to krb5-clients.
...
sr_sin4.sin_addr.s_addr = temp;
sr_sin4.sin_family = AF_INET;
#ifdef HAVE_SA_LEN
sr_sin4.sin_len = sizeof (sr_sin4);
#endif
sr_addr.ai_family = AF_INET;
sr_addr.ai_addrlen = sizeof (sr_sin4);
sr_addr.ai_addr = (struct sockaddr *) &sr_sin4;
sr_addr.ai_next = 0;
sr_addr.ai_canonname = hostname;
addrs = &sr_addr;
... mpa, poutses, ayto den yposthrizei kan IPv6. As dokimasoume kati
allo. Na poume to inetutils-telnet? Ante, as to poume, fainetai wraio,
gyalistero, kai yposthrizei kai shishi (den kserete ti einai to shishi?
Ntroph sas, pws tolmate! olos o kosmos to kserei ektos apo sas).
Ax, ti wraia, ayto einai ontws IPv6 capable. Gia na doume...
Teleia, ta panta einai properly #ifdef-ed gia thn periptwsh pou pame na
to kanoyme compile se kanena PDP-11. Mporoume etsi na sygkrinoume kai to
IPv4 socket implementation me to IPv6. An kataferoume na xtenisoume th
makaronada me ta #ifdefs.
IPv4-only case :
struct hostent *host = 0;
struct sockaddr_in sin;
struct servent *sp = 0;
in_addr_t temp;
memset ((char *) &sin, 0, sizeof (sin));
temp = inet_addr (hostp);
if (temp != (in_addr_t) - 1) {
...what the... A, nai. Edw blepoume ena ekplhktiko paradeigma tou ti
yperoxa mporei na diabazetai o "swsta" grammenos kwdikas. Oxi, den
afairei 1 apo kammia metablhth in_addr_t. Typecasted pointer einai.
Logiko pou to grafei etsi omws, ama egrafe apla if (temp != -1) h estw
if (temp != (inaddr_t)(-1)) - mpas kai to katalabei kanenas - 8a epefte
panw tou olh h comp.lang.c.pedantic.anal.retentive.assholes na ton faei...
sin.sin_addr.s_addr = temp;
sin.sin_family = AF_INET;
} else {
host = gethostbyname (hostp);
if (host) {
sin.sin_family = host->h_addrtype;
memmove (&sin.sin_addr, host->h_addr_list[0], host->h_length);
} else {
printf ("Can't lookup hostname %s\n", hostp);
return 0;
}
}
sin.sin_port = atoi (portp);
if (sin.sin_port == 0) {
sp = getservbyname (portp, "tcp");
if (sp == 0) {
printf ("tcp/%s: unknown service\n", portp);
return 0;
}
sin.sin_port = sp->s_port;
} else {
sin.sin_port = htons (sin.sin_port);
}
OK ws edw...
printf ("Trying %s...\n", inet_ntoa (sin.sin_addr));
do {
net = socket (AF_INET, SOCK_STREAM, 0);
if (net < 0) {
perror ("telnet: socket");
return 0;
}
if (connect (net, (struct sockaddr *) &sin, sizeof (sin)) < 0) {
if (host && host->h_addr_list[1]) {
int oerrno = errno;
fprintf (stderr, "telnet: connect to address %s: ",
inet_ntoa (sin.sin_addr));
errno = oerrno;
perror ((char *) 0);
host->h_addr_list++;
memmove ((caddr_t) & sin.sin_addr,
host->h_addr_list[0], host->h_length);
close (net);
continue;
}
perror ("telnet: Unable to connect to remote host");
return 0;
}
connected++;
}
while (connected == 0);
Olh ayth thn ahdia me to list traversal thn kanei apla kai mono gia na
dokimasei OLES tis diey8ynseis pou epistrefei h gethostbyname, gia thn
periptwsh pou kapoios exei kanei ayto :
1.2.3.4 i.want.sex # h IP ths gkomenas mou
1.2.3.5 i.want.sex # h grammateas mou
1.2.3.6 i.want.sex # mia filh pou exw gia ksepetes
1.2.3.7 i.want.sex # mia geitonissa pou kanei psyxika
1.2.3.8 i.want.sex # mia prwhn
1.2.3.9 i.want.sex # h gynaika mou
opote
$ telnet i.want.sex
Trying 1.2.3.4...
Connection failed: Connection refused
Trying 1.2.3.5...
Connection failed: Connection refused
Trying 1.2.3.6...
Connection failed: Connection refused
Trying 1.2.3.7...
Connection failed: Connection refused
Trying 1.2.3.8...
Connection failed: Connection refused
Trying 1.2.3.9...Connected.
login: ^]
telnet> ase, gama to, paw gia mpyres
?Invalid command
telnet> quit
Oso gia to IPv6 case, einai entelws analogo :
struct addrinfo *result, *aip, hints;
memset (&hints, 0, sizeof (hints));
# ifdef AI_ADDRCONFIG
hints.ai_flags = AI_ADDRCONFIG;
# endif
hints.ai_socktype = SOCK_STREAM;
err = getaddrinfo (hostp, portp, &hints, &result);
aip = result;
do
{
char buf[256];
err = getnameinfo (aip->ai_addr, aip->ai_addrlen, buf, sizeof
(buf),NULL, 0, NI_NUMERICHOST);
if (err) { /* error handling */ }
printf ("Trying %s...\n", buf);
net = socket (aip->ai_family, SOCK_STREAM, 0);
if (net < 0) {
perror ("telnet: socket");
return 0;
}
err = connect (net, (struct sockaddr *) aip->ai_addr,
aip->ai_addrlen);
if (err < 0) {
if (aip->ai_next) {
perror ("Connection failed");
aip = aip->ai_next;
close (net);
continue;
}
perror ("telnet: Unable to connect to remote host");
return 0;
}
connected++;
}
An sas fainetai ligaki pio kseka8aro edw, einai giati EINAI pio
kseka8aro. Me th diafora oti h getnameinfo() *mporei na epistrepsei
olous tous valid syndiasmous prwtokollwn kai address families*
1:2::3:5 i.want.sex # h kainouria mou gkomena einai IPv6 capable
1.2.3.4 i.want.sex # h palia den einai
$ telnet i.want.sex
Trying 1.2.3.4...
Connection failed: Connection refused
Trying 1:2::3:5...
telnet: Unable to connect to remote host: Connection refused
Nai, alla me poia seira tis dokimazei?
Rikste mia matia sto /etc/gai.conf kai (isws) 8a katalabete. Ti? Kaneis
de sas milhse pote gia to /etc/gai.conf? Oute emena.
Gia na doume twra pws diapistwnoume an exoume h oxi default gateway
# netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt
Iface
155.207.130.0 0.0.0.0 255.255.255.0 U 0 0 0
eth0
0.0.0.0 155.207.130.100 0.0.0.0 UG 0 0 0
eth0
"A, wraia. Den exw default IPv6 gateway. Ara de 8a prospa8hsei na
xrhsimopoihsei IPv6 katw apo th myth moy".
Nai, kala.
# netstat -rn6
Kernel IPv6 routing table
Destination Next Hop Flag Met Ref
Use If
::/96 :: Un 256 0
1 sit0
2002::/16 :: U 256 0
0 sit0
fe80::/64 :: U 256 0
0 eth0
fe80::/64 :: U 256 0
0 sit0
::/0 ::192.88.99.1 UG 1 0
1 sit0
::/0 :: !n -1 1
4828 lo
::1/128 :: Un 0 1
1486 lo
::127.0.0.1/128 :: Un 0 1
0 lo
::155.207.130.36/128 :: Un 0 1
0 lo
2002:9bcf:8224::1/128 :: Un 0 1
0 lo
fe80::218:f3ff:feeb:a792/128 :: Un 0 1
0 lo
ff00::/8 :: U 256 0
0 eth0
ff00::/8 :: U 256 0
0 sit0
::/0 :: !n -1 1
4828 lo
#
What...the....
...Nai. Ki egw 8elw na tous skotwsw.
Symperasma. To IPv6 sto Linux leitourgei. Me to localhost. Ka8e Deytera
tou Pasxa. Disektou etous. Afou sfaksete mia gida.
Reply to: