Вы находитесь на странице: 1из 121

Introduction to IPv6 Programming

Rino Nucara GARR rino.nucara@garr.it EuChinaGRID IPv6 Tutorial Catania, June 6th, 2007

Rino Nucara - GARR

IPv6 Tutorial

Content
TheimportanceofbeinganIPv6programmer IPv4/IPv6Interoperability IntroductiontoIPv6Programmingfor
C
APIs PortingapplicationsinIPv6

Java Perl PHP

Bibliography

Rino Nucara - GARR

IPv6 Tutorial

The importance of being an IPv6 programmer


IPv6successfulspreadneedsIPv6compatible applications
Networkisready
MostNRENsandCommercialISPsofferIPv6connectivity sincealongtime Already800+ASregisteredundertheRIPEandIANADBs

GeneralizedlackIPv6compatibleapplicationsinorderto boostthemigration.

ItisimportantforprogrammerstothinkIPv6:

TospeedupIPv6adoption AvoidriskofrollingoutnoncompatibleIPv6programsonce IPv6willtakeplace


Rino Nucara - GARR

IPv6 Tutorial

IPv4/IPv6 Interoperability
Forsome(..2,5,200..:))yearswewillliveina dualIPprotocolversionworld. WewillseeprogressivespreadofIPv6deployment andaveryrelevantresidualusageofIPv4alloverthe world Waysforinteroperatingbetweentwoincompatible protocolsneedtobeidentified

Rino Nucara - GARR

IPv6 Tutorial

Dual stack and separated stack


DUALSTACK

BothIPv4andIPv6stackswillbeavailableduringthetransitionperiod. ToenabledataflowbetweenIPv4andIPv6,twosolutionarepossible: SEPARATEDSTACK

Rino Nucara - GARR

IPv6 Tutorial

IPv6/IPv4 clients connecting to an IPv4 server at an IPv4-only node

DualStack

SingleIPv4orIPv6stacks
Rino Nucara - GARR

IPv6 Tutorial

IPv6/IPv4 Clients connecting to an IPv6 server at IPv6-only node

DualStack

SingleIPv4orIPv6stacks
Rino Nucara - GARR

IPv6 Tutorial

IPv6/IPv4 Clients connecting to an IPv4 server at dual stack node

DualStack

SingleIPv4orIPv6stacks
Rino Nucara - GARR

IPv6 Tutorial

IPv6/IPv4 Clients connecting to an IPv6 server at dual stack node

DualStack

SingleIPv4orIPv6stacks
Rino Nucara - GARR

IPv6 Tutorial

IPv6/IPv4 Clients connecting to a separated stack (IPv4-only and IPv6-only) server.

DualStackorseparatedstack

SingleIPv4orIPv6stacks

10

Rino Nucara - GARR

IPv6 Tutorial

Summary
IPv4server IPv4/I IPv4 Pv6 IPv4 IPv4 IPv4 X IPv4 IPv4 X IPv4

IPv4 IPv4 client IPv4/I Pv6 IPv6 IPv6 client IPv4/I Pv6

IPv6server IPv4/I IPv6 Pv6 X IPv4 X IPv6 IPv6 IPv4 IPv6 IPv6

11

Rino Nucara - GARR

IPv6 Tutorial

Introduction to IPv6 Programming In C

12

Rino Nucara - GARR

IPv6 Tutorial

IPv6s API
IETFstandardizedtwosetsofextensions:RFC3493andRFC3542. RFC3493BasicSocketInterfaceExtensionsforIPv6
Isthelatestspecification(thesuccessortoRFC2133andRFC2553) Itisoftenreferredtoas2553bis ProvidesstandarddefinitionsforCoresocketfunctions,Addressdata structures, NametoAddress translation functions, Address conversionfunctions

RFC 3542 Advanced Sockets Application Program Interface (API)forIPv6

IsthelatestspecificationandisthesuccessortoRFC2292. Itisoftenreferredtoas2292bis DefinesinterfacesforaccessingspecialIPv6packetinformationsuch astheIPv6headerandtheextensionheaders. Advanced APIs are also used to extend the capability of IPv6 raw socket
Rino Nucara - GARR

13

IPv6 Tutorial

Interface Identification RFC3493defines

twofunctionsmappinganinterfacenametoanindex, athirdfunctionreturningallinterfacenamesandindexes, afourthfunctiontoreturnthedynamicmemoryallocatedbythe previousfunctions.

#include<net/if.h> unsignedintif_nametoindex(constchar*ifname); #include<net/if.h> char*if_indextoname(unsignedintifindex,char*ifname); structif_nameindex{ unsignedintif_index;/*1,2,...*/ char*if_name;/*nullterminatedname:"le0",...*/ }; #include<net/if.h> structif_nameindex*if_nameindex(void); #include<net/if.h> voidif_freenameindex(structif_nameindex*ptr);

14

Rino Nucara - GARR

IPv6 Tutorial

Example code: listing interfaces


#include<stdio.h> #include<net/if.h> intmain(intargc,char*argv[]) { $ipaddr 1:lo:[] 2:eth0:[] 3:sit0:[]

OUTPUT: 01lo 12eth0 23sit0

inti; structif_nameindex*ifs=if_nameindex(); if(ifs==NULL){perror("couldnotrunif_nameindex");return1;} for(i=0;(ifs[i].if_index!=0)&&(ifs[i].if_name!=NULL);i++) { printf("%3d%3d%s\n",i,ifs[i].if_index,ifs[i].if_name); }

if_freenameindex(ifs);
}

15

Rino Nucara - GARR

IPv6 Tutorial

new address family name


#define AF_INET610 #define PF_INET6AF_INET6

Anewaddressfamilyname,AF_INET6wasdefinedforIPv6;therelated protocolfamilyisPF_INET6,andnamesbelongingtoitaredefinedasfollow:

IPv4sourcecode:
socket(PF_INET,SOCK_STREAM,0);/*TCPsocket*/ socket(PF_INET,SOCK_DGRAM,0);/*UDPsocket*/

IPv6sourcecode:
socket(PF_INET6,SOCK_STREAM,0);/*TCPsocket*/ socket(PF_INET6,SOCK_DGRAM,0);/*UDPsocket*/

16

Rino Nucara - GARR

IPv6 Tutorial

Address structures
IPv4 IPv6

structsockaddr_in

structsockaddr_in6

IPv4/IPv6/

structsockaddr_storage

17

Rino Nucara - GARR

IPv6 Tutorial

Address Data Structure: Struct sockaddr structsockaddr{


sa_family_tsa_family;//addressfamily,AF_xxx charsa_data[14];//14bytesofprotocoladdress };

FunctionsprovidedbysocketAPIusesocketaddressstructurestodetermine thecommunicationserviceaccesspoint. Sincedifferentprotocolscanhandlesocketfunctions,agenericsocket addressstructurecalledsockaddrisusedasargumenttothesefunctions Fromanapplicationprogrammerspointofview,theonlyuseofthese genericsocketaddressstructuresistocastpointerstoprotocolspecific structures. sockaddrstructure(2+14bytes)holdssocketaddressinformationformany typesofsockets. sa_familyrepresentsaddressfamily. sa_datacontainsdataaboutaddress.

18

Rino Nucara - GARR

IPv6 Tutorial

Address Data Structure: Struct sockaddr_in (1/2) structin_addr{


uint32_ts_addr;//32bitIPv4address(4bytes) //networkbyteordered }; structsockaddr_in{ sa_family_tsin_family;//Addressfamily(2bytes) in_port_tsin_port;//Portnumber(2bytes) structin_addrsin_addr;//Internetaddress(4bytes) charsin_zero[8];//Empty(forpadding)(8bytes) }

sockaddr_inisaparallelstructuretodealwithstructsockaddrforIPv4addresses. sin_portcontainstheportnumberandmustbeinNetworkByteOrder. sin_familycorrespondstosa_family(inastructuresockaddr)andcontainsthetypeof addressfamily(AF_INETforIPv4).Assin_portalsosin_familymustbeinNetworkByte Order. sin_addrrepresentsInternetaddress(forIPv4).

19

Rino Nucara - GARR

IPv6 Tutorial

Address Data Structure: Struct sockaddr_in (2/2) structin_addr{


uint32_ts_addr;//32bitIPv4address(4bytes) //networkbyteordered }; structsockaddr_in{ sa_family_tsin_family;//Addressfamily(2bytes) in_port_tsin_port;//Portnumber(2bytes) structin_addrsin_addr;//Internetaddress(4bytes) charsin_zero[8];//Empty(forpadding)(8bytes) }

sin_zeroisincludedtopadthestructuretothelengthofastructsockaddr andshouldbesettoallzerousingthebzero()ormemset()functions.

20

Rino Nucara - GARR

IPv6 Tutorial

Casting
structsockaddr_inaddrIPv4; /*fillinaddrIPv4{}*/ Bind(sockfd,(structsockaddr*)&addrIPv4,sizeof(addrIPv4));

Apointertoastructsockaddr_in(16bytes)canbecasttoapointertoastruct sockaddr(16bytes)andviceversa.Soeventhoughsocket()wantsastruct sockaddr*itisnecessarytocastsockaddrwhilepassingtosocketfunction. FunctionsprovidedbysocketAPIusesocketaddressstructurestodetermine thecommunicationserviceaccesspoint. Asstatedbefore,thegenericsocketaddressstructuresockaddrisusedas argumenttothesefunctions(foranyofthesupportedcommunicationprotocol families).

21

Rino Nucara - GARR

IPv6 Tutorial

Address Data Structure: Sockaddr_in6 (1/3) structin6_addr{


uint8_ts6_addr[16];//128bitIPv6address(N.B.O.) }; structsockaddr_in6{ sa_family_tsin6_family;//AF_INET6 in_port_tsin6_port;//transportlayerport#(N.B.O.) uint32_tsin6_flowinfo;//IPv6flowinformation(N.B.O.) structin6_addrsin6_addr; //IPv6address uint32_tsin6_scope_id;//setofinterfacesforascope }

sockaddr_in6structureholdsIPv6addressesandisdefinedasaresultof includingthe<netinet/in.h>header. sin6_familyoverlaysthesa_familyfieldwhenthebufferiscasttoasockaddr datastructure.ThevalueofthisfieldmustbeAF_INET6. sin6_portcontainsthe16bitUDPorTCPportnumber.Thisfieldisusedin thesamewayasthesin_portfieldofthesockaddr_instructure.Theport numberisstoredinnetworkbyteorder.

22

Rino Nucara - GARR

IPv6 Tutorial

Address Data Structure: Sockaddr_in6 (2/3) structin6_addr{


uint8_ts6_addr[16];//128bitIPv6address(N.B.O.) }; structsockaddr_in6{ sa_family_tsin6_family;//AF_INET6 in_port_tsin6_port;//transportlayerport#(N.B.O.) uint32_tsin6_flowinfo;//IPv6flowinformation(N.B.O.) structin6_addrsin6_addr; //IPv6address uint32_tsin6_scope_id;//setofinterfacesforascope }

sin6_flowinfoisa32bitfieldintendedtocontainflowrelatedinformation. Theexactwaythisfieldismappedtoorfromapacketisnotcurrently specified.Untilitsexactusewillbespecified,applicationsshouldsetthisfield tozerowhenconstructingasockaddr_in6,andignorethisfieldina sockaddr_in6structureconstructedbythesystem. sin6_addrisasinglein6_addrstructure.Thisfieldholdsone128bitIPv6 address.Theaddressisstoredinnetworkbyteorder.

23

Rino Nucara - GARR

IPv6 Tutorial

Address Data Structure: Sockaddr_in6 (3/3) structin6_addr{


uint8_ts6_addr[16];//128bitIPv6address(N.B.O.) }; structsockaddr_in6{ sa_family_tsin6_family;//AF_INET6 in_port_tsin6_port;//transportlayerport#(N.B.O.) uint32_tsin6_flowinfo;//IPv6flowinformation(N.B.O.) structin6_addrsin6_addr; //IPv6address uint32_tsin6_scope_id;//setofinterfacesforascope }

sin6_scope_idisa32bitintegerthatidentifiesasetofinterfacesas appropriateforthescopeoftheaddresscarriedinthesin6_addrfield.The mappingofsin6_scope_idtoaninterfaceorsetofinterfacesisleftto implementationandfuturespecificationsonthesubjectofscopedaddresses. RFC3493didnotdefinetheusageofthesin6_scope_idfieldbecauseatthe timetherewassomedebateabouthowtousethatfield. Theintentwastopublishaseparatespecificationtodefineitsusage,butthat hasnothappened.

24

Rino Nucara - GARR

IPv6 Tutorial

Address Data Structure:Sockaddr_in6 (sin6_scope_id)


TocommunicatewithnodeAornodeC,nodeBhastodisambiguate betweenthemwithalinklocaladdressyouneedtospecifythescope identification. NodeA NodeB NodeC

ether0 fe80::1

ether1 fe80::1

StringrepresentationofascopedIPv6addressisaugmentedwithscope identifierafter%sign(es.Fe::1%ether1). NOTE!Scopeidentificationstringisimplementationdependent.

25

Rino Nucara - GARR

IPv6 Tutorial

Address Data Structure: Sockaddr_in6 in BSD structin6_addr{


uint8_ts6_addr[16];//128bitIPv6address(N.B.O.) }; structsockaddr_in6{ unit8_tsin6_len;//lengthofthisstruct sa_family_tsin6_family;//AF_INET6(8bit) in_port_tsin6_port;//transportlayerport#(N.B.O.) uint32_tsin6_flowinfo;//IPv6flowinformation(N.B.O.) structin6_addrsin6_addr; //IPv6address uint32_tsin6_scope_id;//setofinterfacesforascope }

The4.4BSDreleaseincludesasmall,butincompatiblechangetothesocketinterface. The"sa_family"fieldofthesockaddrdatastructurewaschangedfroma16bitvalueto an8bitvalue,andthespacesavedusedtoholdalengthfield,named"sa_len". Thesockaddr_in6datastructuregivenintheprevioussectioncannotbecorrectly castedintothenewersockaddrdatastructure. Forthisreason,thefollowingalternativeIPv6addressdatastructureisprovidedtobe usedonsystemsbasedon4.4BSD.Itisdefinedasaresultofincludingthe <netinet/in.h>header.

26

Rino Nucara - GARR

IPv6 Tutorial

Problem code example


Structsockaddrsa; Structsockaddr_in6*sin6=(structsockaddr*)&sa; Memeset(sin6,0,sizeof(*sin6));

Inthiscode,thememset()operationwilloverwritethememoryregion immediatelyfollowingthespacethatwasallocatedforthesockaddr{}structure. Itisthereforeimportanttouseanewaddressstructure:sockaddr_storage{} asasocketaddressplaceholderthroughoutthecodeinordertoavoid introducingthiskindofprogrammingbug.

27

Rino Nucara - GARR

IPv6 Tutorial

Address Data Structure:sockaddr_storage (1/2)


Inordertowriteportableandmultiprotocolapplications,anotherdata structureisdefined:thenewsockadd_storage. Thisfunctionisdesignedtostoreallprotocolspecificaddress structureswiththerightdimensionandalignment. Hence,portableapplicationsshouldusethesockaddr_storage structuretostoretheiraddresses,bothIPv4orIPv6ones. Thisnewstructurehidesthespecificsocketaddressstructure thattheapplicationisusing.

28

Rino Nucara - GARR

IPv6 Tutorial

Address Data Structure:sockaddr_storage (2/2) /*Desireddesignofmaximumsizeandalignment*/


#define_SS_MAXSIZE128/*Implementationspecificmaxsize*/ #define_SS_ALIGNSIZE(sizeof(int64_t))/*Implementationspecific desiredalignment*/ /*Definitionsusedforsockaddr_storagestructurepaddingsdesign.*/ #define_SS_PAD1SIZE(_SS_ALIGNSIZEsizeof(sa_family_t)) #define_SS_PAD2SIZE(_SS_MAXSIZE(sizeof(sa_family_t)+ _SS_PAD1SIZE+_SS_ALIGNSIZE)) structsockaddr_storage{ sa_family_tss_family;/*addressfamily*/ /*Followingfieldsareimplementationspecific*/ char__ss_pad1[_SS_PAD1SIZE]; /*6bytepad,thisistomakeimplementation /*specificpaduptoalignmentfieldthat*/ /*followsexplicitinthedatastructure*/ int64_t__ss_align;/*fieldtoforcedesiredstructure*/ /*storagealignment*/ char__ss_pad2[_SS_PAD2SIZE]; /*112bytepadtoachievedesiredsize,*/ /*_SS_MAXSIZEvalueminussizeofss_family*/ /*__ss_pad1,__ss_alignfieldsis112*/ };

29

Rino Nucara - GARR

IPv6 Tutorial

Socketcallswhereasocketaddressstructureis Pass addresses providedfromanapplicationtothekernel

IPv4: IPv6:

structsockaddr_inaddr; socklen_taddrlen=sizeof(addr); //filladdrstructureusinganIPv4address //beforecallingsocketfuntion bind(sockfd,(structsockaddr*)&addr,addrlen);

IPv4andIPv6:

structsockaddr_in6addr; socklen_taddrlen=sizeof(addr); //filladdrstructureusinganIPv6address //beforecallingsocketfunction bind(sockfd,(structsockaddr*)&addr,addrlen);

structsockaddr_storageaddr; socklen_taddrlen=sizeof(addr); //filladdrstructureusinganIPv4/IPv6address //andfilladdrlenbeforecallingsocketfunction bind(sockfd,(structsockaddr*)&addr,addrlen);a

30

Rino Nucara - GARR

IPv6 Tutorial

Socketcallswhereasocketaddressstructure Get adresses isprovidedfromthekerneltoanapplication

IPv4: structsockaddr_inaddr; IPv6:


socklen_taddrlen=sizeof(addr); accept(sockfd,(structsockaddr*)&addr,&addrlen); //addrstructurecontainsanIPv4address

IPv4andIPv6:

Astructsockaddr_in6addr; socklen_taddrlen=sizeof(addr); accept(sockfd,(structsockaddr*)&addr,&addrlen); //addrstructurecontainsanIPv6address

structsockaddr_storageaddr; socklen_taddrlen=sizeof(addr); accept(sockfd,(structsockaddr*)&addr,&addrlen); //addrstructurecontainsanIPv4/IPv6address //addrlencontainsthesizeoftheaddrstructurereturned

31

Rino Nucara - GARR

IPv6 Tutorial

IPv6 Wildcard Address (1/2) theIPv6WildcardAddressisprovidedintwoforms:


aglobalvariableandasymbolicconstant.

#include<netinet/in.h>: externconststructin6_addrin6addr_any;

Forexample,tobindasockettoportnumber23,butletthesystemselectthe sourceaddress,anapplicationcouldusethefollowingcode:
structsockaddr_in6sin6; ... sin6.sin6_family=AF_INET6; sin6.sin6_flowinfo=0; sin6.sin6_port=htons(23); sin6.sin6_addr=in6addr_any;/*structureassignment*/ ... if(bind(s,(structsockaddr*)&sin6,sizeof(sin6))==1) a ...

32

Rino Nucara - GARR

IPv6 Tutorial

IPv6 Wildcard Address (2/2) AnotheroptionisasymbolicconstantnamedIN6ADDR_ANY_INIT.


2
#include<netinet/in.h>. #defineIN6ADDR_ANY_INIT{{{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}}

Thisconstantcanbeusedtoinitializeanin6_addrstructure:
structin6_addranyaddr=IN6ADDR_ANY_INIT;

NotethatthisconstantcanbeusedONLYatdeclarationtime.Itcannotbe usedtoassignapreviouslydeclaredin6_addrstructure.Forexample,the followingcodewillnotwork:


/*ThisistheWRONGwaytoassignanunspecifiedaddress*/ structsockaddr_in6sin6; ... sin6.sin6_addr=IN6ADDR_ANY_INIT;/*willNOTcompile*/

33

Rino Nucara - GARR

IPv6 Tutorial

IPv6 Loopback Address (1/2) theIPv6loopbackaddressisprovidedintwoformsaglobal


variableandasymbolicconstant.

<netinet/in.h> externconststructin6_addrin6addr_loopback;

Applicationsusein6addr_loopbackastheywoulduseINADDR_LOOPBACKin IPv4applications.Forexample,toopenaTCPconnectiontothelocaltelnet server,anapplicationcouldusethefollowingcode:


structsockaddr_in6sin6; ... sin6.sin6_family=AF_INET6; sin6.sin6_flowinfo=0; sin6.sin6_port=htons(23); sin6.sin6_addr=in6addr_loopback;/*structureassignment*/ ... if(connect(s,(structsockaddr*)&sin6,sizeof(sin6))==1) ...

34

Rino Nucara - GARR

IPv6 Tutorial

IPv6 Loopback Address (2/2)


2

SecondwayisasymbolicconstantnamedIN6ADDR_LOOPBACK_INIT:
<netinet/in.h> #defineIN6ADDR_LOOPBACK_INIT{{{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}}}

ItcanbeusedatdeclarationtimeONLY. forexample:
structin6_addrloopbackaddr=IN6ADDR_LOOPBACK_INIT;

LikeIN6ADDR_ANY_INIT,thisconstantcannotbeusedinanassignment toapreviouslydeclaredIPv6addressvariable.

35

Rino Nucara - GARR

IPv6 Tutorial

Socket Options
AnumberofnewsocketoptionsaredefinedforIPv6:
IPV6_UNICAST_HOPS IPV6_MULTICAST_IF IPV6_MULTICAST_HOPS IPV6_MULTICAST_LOOP IPV6_JOIN_GROUP IPV6_LEAVE_GROUP

IPV6_V6ONLY
AllofthesenewoptionsareattheIPPROTO_IPV6level(specifiesthecode inthesystemtointerprettheoption). ThedeclarationforIPPROTO_IPV6isobtainedbyincludingtheheader <netinet/in.h>.

36

Rino Nucara - GARR

IPv6 Tutorial

Socket Options: Unicast Hop Limit


inthoplimit=10; if( setsockopt(s,IPPROTO_IPV6,IPV6_UNICAST_HOPS, (char*)&hoplimit,sizeof(hoplimit)) ==1)perror("setsockoptIPV6_UNICAST_HOPS"); inthoplimit; socklen_tlen=sizeof(hoplimit); if( getsockopt(s,IPPROTO_IPV6,IPV6_UNICAST_HOPS, (char*)&hoplimit,&len) ==1)perror("getsockoptIPV6_UNICAST_HOPS"); else printf("Using%dforhoplimit.\n",hoplimit);

IPV6_UNICAST_HOPSoptioncontrolsthehoplimitusedinoutgoingunicast IPv6packets.

37

Rino Nucara - GARR

IPv6 Tutorial

IPV6_V6ONLY
AF_INET6socketsmaybeusedforbothIPv4andIPv6comunications. thesocketcanbeusedtosendandreceiveIPv6packetsonly. takesanintvalue(butisabooleanoption). bydefaultisturnedoff.
inton=1; if(setsockopt(s,IPPROTO_IPV6,IPV6_V6ONLY,(char*)&on,sizeof(on))==1) perror("setsockoptIPV6_V6ONLY"); else printf("IPV6_V6ONLYset\n");

Anexampleuseofthisoptionistoallowtwoversionsofthesameserver processtorunonthesameport,oneprovidingserviceoverIPv6,theother providingthesameserviceoverIPv4.

38

Rino Nucara - GARR

IPv6 Tutorial

IPV6_V6ONLY EXAMPLE
structsockaddr_in6sin6,sin6_accept; socklen_tsin6_len;ints0,s;inton;charhbuf[NI_MAXHOST]; memset(&sin6,0,sizeof(sin6)); sin6.sin6_family=AF_INET6;sin6.sin6_len=sizeof(sin6); sin6.sin6_port=htons(5001); s0=socket(AF_INET6,SOCK_STREAM,IPPROTO_TCP); on=1;setsockopt=(s0,SOL_SOCKET,SO_REUSEADDR,&on,sizeof(on)); #ifdefUSE_IPV6_V6ONLY on=1; setsockopt(s0,IPPROTO_IPV6,IPV6_V6ONLY,&on,sizeof(on)); #endif bind(s0,(conststructsockaddr*)&sin6,sizeof(sin6)); listen(s0,1); while(1){ sin6_len=sizeof(sin6_accept); s=accept(s0,(structsockaddr*)&sin6_accept,&sin6_len); getnameinfo((structsockaddr*)&sin6_accept,sin6_len,hbuf, sizeof(hbuf),NULL,0,NI_NUMERICHOST); printf("acceptaconnectionfrom%s\n",hbuf); close(s); }

39

Rino Nucara - GARR

IPv6 Tutorial

Running example code


WithoutUSE_IPV6_V6ONLYandtheIPv4mappedaddressissupported
bythesystem:
telnet::15001 telnet127.0.0.15001 Acceptaconnectionfrom::1 Acceptaconnectionfrom::ffff:127.0.0.1

WithUSE_IPV6_V6ONLY
telnet::15001 telnet127.0.0.15001 Acceptaconnectionfrom::1

Trying127.0.0.1 telnet:connectiontoaddress127.0.0.1:Connectionrefused

40

Rino Nucara - GARR

IPv6 Tutorial

Dual stack and separated stack implementation


DUALSTACK SEPARATEDSTACK

Followingthereareimplementationexamplesaboutdualstackandseparated stackinC

41

Rino Nucara - GARR

IPv6 Tutorial

Server (Dual Stacks)


intServSock,csock; structsockaddraddr,from; ... ServSock=socket(AF_INET6,SOCK_STREAM,PF_INET6); bind(ServSock,&addr,sizeof(addr)); do{ csock=accept(ServSocket,&from,sizeof(from)); doClientStuff(csock); }while(!finished);

42

Rino Nucara - GARR

IPv6 Tutorial

Server (Separate Stacks)


SOCKETServSock[FD_SETSIZE]; ADDRINFOAI0,AI1; ServSock[0]=socket(AF_INET6,SOCK_STREAM,PF_INET6); ServSock[1]=socket(AF_INET,SOCK_STREAM,PF_INET); ... bind(ServSock[0],AI0>ai_addr,AI0>ai_addrlen); bind(ServSock[1],AI1>ai_addr,AI1>ai_addrlen); ... IPV6_V6ONLY select(2,&SockSet,0,0,0); option allows if(FD_ISSET(ServSocket[0],&SockSet)){ two versions of //IPv6connection the same csock=accept(ServSocket[0],(LPSOCKADDR)&From,FromLen); server process ... } to run on the if(FD_ISSET(ServSocket[1],&SockSet)){ same port, one //IPv4connection providing csock=accept(ServSocket[1],(LPSOCKADDR)&From,FromLen); service over ... IPv6, the other }

43

Rino Nucara - GARR

IPv6 Tutorial

providing the same service over IPv4.

Address conversion functions (1/3)


Addressconversionfunctions(workingwithbothIPv4andIPv6 addresses)tobeusedtoswitchbetweenabinaryrepresentationanda humanfriendlypresentation
#include<arpa/inet.h> //FrompresentationtoIPv4/IPv6binaryrepresentation intinet_pton(intfamily,constchar*src,void*dst); //FromIPv4/IPv6binarytopresentation constchar*inet_ntop(intfamily,constvoid*src,char*dst, size_tcnt);

src 2001:db8::1234

inet_pton() inet_ntop()

dst In6_addr={0x20,0x01,0x0 d,0xb8,,0x12,0x34}

44

Rino Nucara - GARR

IPv6 Tutorial

Address Convertion Functions (2/3)


in_addr{} 32bitbinary IPv4address in6_addr{} 128bitbinary IPv4mappedor IPv4compatible IPv6address
inet_ntop(AF_INET) inet_pton(AF_INET) Dotteddecimal IPv4address

inet_ntop(AF_INET6) x:x:x:x:x:x:a.b.c.d inet_pton(AF_INET6)

in6_addr{} 128bitbinary IPv6address

inet_ntop(AF_INET6) x:x:x:x:x:x:x:x inet_pton(AF_INET6)


Rino Nucara - GARR IPv6 Tutorial

45

Address Convertion example


structsockaddr_in6addr; charstraddr[INET6_ADDRSTRLEN]; memset(&addr,0,sizeof(addr)); addr.sin6_family=AF_INET6;/*family*/ addr.sin6_port=htons(MYPORT);/*port,networtbyteorder*/ //frompresentationtobinaryrepresentation inet_pton(AF_INET6,2001:720:1500:1::a100",&(addr.sin6_addr)); //frombinaryrepresentationtopresentation Straddr=inet_ntop(AF_INET6,&addr.sin6_addr,straddr,sizeof(straddr));

46

Rino Nucara - GARR

IPv6 Tutorial

Going to Network Transparent Programming


Newfunctionshavebeendefinedtosupportboth protocolversions(IPv4andIPv6). Aanewwayofprogrammingandmanagingthe sockethasbeenintroduced:networktrasparent programming. Accordingtothisnewapproachfollowingfunctions havebeenimplemented:
getaddrinfo getnameinfo.

47

Rino Nucara - GARR

IPv6 Tutorial

Going to Network Transparent Programming


ForNetworkTransparentProgrammingitisimportant topayattentionto:
Useofnameinsteadofaddressinapplicationsis advisable;infact,usuallythehostnameremainsthesame, whiletheaddressmaychangemoreeasily.From applicationpointofviewthenameresolutionisasystem indipendentprocess. Avoidtheuseofhardcodednumericaladdressandbinary representationofaddresses. Usegetaddrinfoandgetnameinfofunctions.

48

Rino Nucara - GARR

IPv6 Tutorial

Name to Address Translation Function


Thegethostbyname()forIPv4andgethostnyname2()functioncreatedfor IPv6wasdeprecatedinRFC2553andwasreplacedbygetaddrinfo() function.
#include<netdb.h> structhostent*gethostbyname(constchar*name)

DEPRECATED

#include<netdb.h> #include<sys/socket.h> structhostent*gethostbyname2(constchar*name,intaf)

DEPRECATED

#include<netdb.h> #include<sys/socket.h> intgetaddrinfo(constchar*nodename,constchar*servname, conststructaddrinfo*hints,structaddrinfo**res);

49

Rino Nucara - GARR

IPv6 Tutorial

Nodename and Service Name Translation


Nodenametoaddresstranslationisdoneinaprotocolindependentway usingthegetaddrinfo()function. getaddrinfo()takesasinputaservicenamelikehttporanumericport numberlike80aswellasanFQDNandreturnsalistofaddressesalong withthecorrespondingportnumber. Thegetaddrinfofunctionisveryflexibleandhasseveralmodesofoperation. Itreturnsadynamicallyallocatedlinkedlistofaddrinfostructures containingusefulinformation(forexample,sockaddrstructurereadyforuse).
#include<netdb.h> #include<sys/socket.h> intgetaddrinfo(constchar*nodename,constchar*servname, conststructaddrinfo*hints,structaddrinfo**res);

Nodename, Servname, Hints(otheroptions)

getaddrinfo
Rino Nucara - GARR

Addrinfo (desidereddata)

50

IPv6 Tutorial

getaddrinfo input arguments


intgetaddrinfo(constchar*nodename,constchar*servname, conststructaddrinfo*hints,structaddrinfo**res);

hostnameiseitherahostnameoranaddressstring. servnameiseitheraservicenameordecimalportnumberstring. hintsiseitheranullpointerorapointertoanaddrinfostructurethatthecaller fillsinwithhintsaboutthetypesofinformationhewantstobereturned. (seenextslide)

51

Rino Nucara - GARR

IPv6 Tutorial

getaddrinfo input arguments Thecallercansetonlythesevaluesinhintsstructure:


structaddrinfo{ intai_flags;//AI_PASSIVE,AI_CANONNAME,.. intai_family;//AF_xxx intai_socktype;//SOCK_xxx intai_protocol;//0orIPPROTO_xxxforIPv4andIPv6 socklen_tai_addrlen;//lengthofai_addr char*ai_canonname;//canonicalnamefornodename structsockaddr*ai_addr;//binaryaddress structaddrinfo*ai_next;//nextstructureinlinkedlist };

ai_family:Theprotocolfamilytoreturn(es.AF_INET,AF_INET6, AF_UNSPEC).Whenai_familyissettoPF_UNSPEC,itmeansthecallerwill acceptanyprotocolfamilysupportedbytheoperatingsystem. ai_socktype:Denotesthetypeofsocketthatiswanted:SOCK_STREAM, SOCK_DGRAM,orSOCK_RAW.Whenai_socktypeiszerothecallerwill acceptanysockettype. ai_protocol:Indicateswhichtransportprotocolisdesired,IPPROTO_UDPor IPPROTO_TCP.Ifai_protocoliszerothecallerwillacceptanyprotocol.

52

Rino Nucara - GARR

IPv6 Tutorial

getaddrinfo input arguments: ai_flag (1/3) structaddrinfo{


intai_flags;//AI_PASSIVE,AI_CANONNAME,.. [] };

ai_flagsshallbesettozeroorbethebitwiseinclusiveORofoneormoreof thevalues: AI_PASSIVE ifitisspecifiedthecallerrequiresaddressesthataresuitableforaccepting incomingconnections.Whenthisflagisspecified,nodenameisusuallyNULL, andaddressfieldoftheai_addrmemberisfilledwiththe"anyaddress(e.g. INADDR_ANYforanIPv4orIN6ADDR_ANY_INITforanIPv6). AI_CANONNAME thefunctionshallattempttodeterminethecanonicalnamecorrespondingto nodename(Thefirstelementofthereturnedlisthastheai_canonnamefilled inwiththeofficialnameofthemachine).

53

Rino Nucara - GARR

IPv6 Tutorial

getaddrinfo input arguments: ai_flag (2/3) structaddrinfo{


intai_flags;//AI_PASSIVE,AI_CANONNAME,.. [] };

AI_NUMERICHOST specifiesthatnodenameisanumerichostaddressstring.Otherwise,an [EAI_NONAME]errorisreturned.Thisflagshallpreventanytypeofname resolutionservice(forexample,theDNS)frombeinginvoked. AI_NUMERICSERV specifiesthatservnameisanumericportstring.Otherwise,an [EAI_NONAME]errorshallbereturned.Thisflagshallpreventanytypeof nameresolutionservice(forexample,NIS+)frombeinginvoked. AI_V4MAPPED ifnoIPv6addressesarematched,IPv4mappedIPv6addressesforIPv4 addressesthatmatchnodenameshallbereturned.Thisflagisapplicableonly whenai_familyisAF_INET6inthehintsstructure.

54

Rino Nucara - GARR

IPv6 Tutorial

getaddrinfo input arguments: ai_flag (3/3) structaddrinfo{


intai_flags;//AI_PASSIVE,AI_CANONNAME,.. [] };

AI_ALL IfthisflagissetalongwithAI_V4MAPPEDwhenlookingupIPv6addresses thefunctionwillreturnallIPv6addressesaswellasallIPv4addresses.The lattermappedtoIPv6format. AI_ADDRCONFIG onlyaddresseswhosefamilyissupportedbythesystemwillbereturned. AI_ADDRCONFIG IPv4addressesshallbereturnedonlyifanIPv4addressisconfiguredonthe localsystem,andIPv6addressesshallbereturnedonlyifanIPv6addressis configuredonthelocalsystem.Theloopbackaddressisnotconsideredfor thiscaseasvalidasaconfiguredaddress.

55

Rino Nucara - GARR

IPv6 Tutorial

getaddrinfo output
Ifgetaddrinforeturns0(success)resargumentisfilledinwithapointertoa linkedlistofaddrinfostructures(linkedthroughtheai_nextpointer.

Incaseofmultipleaddresses associatedwiththehostname onestructisreturnedforeach address(usablewith hint.ai_family,ifspecified). Onestructisreturnedalsofor eachsockettype(accordingto hint.ai_socktype).

56

Rino Nucara - GARR

IPv6 Tutorial

getaddrinfo output
structaddrinfo{ intai_flags;/*AI_PASSIVE,AI_CANONNAME,..*/ intai_family;/*AF_xxx*/ intai_socktype;/*SOCK_xxx*/ intai_protocol;/*0orIPPROTO_xxxforIPv4andIPv6*/ socklen_tai_addrlen;/*lengthofai_addr*/ char*ai_canonname;/*canonicalnamefornodename*/ structsockaddr*ai_addr;/*binaryaddress*/ structaddrinfo*ai_next;/*nextstructureinlinkedlist*/ };

Theinformationreturnedintheaddrinfostructuresisreadyforsocketcalls andreadytouseintheconnect,sendto(forclient)orbind(forserver) function. ai_addrisapointertoasocketaddressstructure. ai_addrlenisthelengthofthissocketaddressstructure. ai_canonnamememberofthefirstreturnedstructurepointstothecanonical nameofthehost(ifAI_CANONNAMEflagIsetinhintsstructure).

57

Rino Nucara - GARR

IPv6 Tutorial

gai_strerror handling) #include<netdb.h>

(error

char*gai_strerror(interror);

Thenonzeroerrorreturnvaluesfromgetaddrinfocanbetraslatedbythe gai_strerrorfunctionintoahumanreadablestring.
EAI_ADDRFAMILYThespecifiednetworkhostdoesnothaveany networkaddressesintherequestedaddress family. EAI_ADDRFAMILYaddressfamilyforhostnamenotsupported EAI_AGAINThenameserverreturnedatemporaryfailure indication.Tryagainlater. EAI_BADFLAGSai_flagscontainsinvalidflags. EAI_FAILunrecoverablefailureinnameresolution EAI_FAMILYTherequestedaddressfamilyisnotsupported atall. EAI_MEMORYOutofmemory. EAI_NODATAThespecifiednetworkhostexists,butdoesnot haveanynetworkaddressesdefined. EAI_NONAMEhostnameorservicenotprovidedorknown EAI_SERVICEservicenotsupportedforai_socktype EAI_SOCKTYPETherequestedsockettypeisnotsupportedat all. EAI_SYSTEMOthersystemerror,checkerrnofordetails.

58

Rino Nucara - GARR

IPv6 Tutorial

gai_strerror example
error=getaddrinfo("www.kame.net","http",&hints,&res0); if(error) { fprintf(stderr,"error:%s\n",gai_strerror(error)); exit(1); }

59

Rino Nucara - GARR

IPv6 Tutorial

freeaddrinfo ( memory release)


#include<netdb.h> voidfreeaddrinfo(structaddrinfo*ai);

Thefreeaddrinfo()functionfreesaddrinfostructurereturnedbygetaddrinfo(), alongwithanyadditionalstorageassociatedwiththosestructures (forexample,storagepointedtobytheai_canonnameandai_addrfields). Iftheai_nextfieldofthestructureisnotnull,theentirelistofstructuresis freed.

60

Rino Nucara - GARR

IPv6 Tutorial

freeaddrinfo example
n=getaddrinfo(hostname,service,&hints,&res); //Tryopensocketwitheachaddressgetaddrinforeturned,until gettingavalidsocket. resave=res; while(res){ sockfd=socket(res>ai_family, res>ai_socktype, res>ai_protocol); if(!(sockfd<0)) break; res=res>ai_next; }

freeaddrinfo(ressave);

61

Rino Nucara - GARR

IPv6 Tutorial

getnameinfo (1/4)
getnameinfoisthecomplementaryfunctiontogetaddrinfo: ittakesasocketaddressandreturnsacharacterstringdescribingthe hostandanothercharacterstringdescribingtheservice.
#include<sys/socket.h> #include<netdb.h> intgetnameinfo(conststructsockaddr*sa,socklen_tsalen, char*host,socklen_thostlen, char*service,socklen_tservicelen, intflags);

sockaddr, Options(flags)

getnameinfo

hostandservice

62

Rino Nucara - GARR

IPv6 Tutorial

getnameinfo (2/4) #include<sys/socket.h>


#include<netdb.h>

input and output

intgetnameinfo(conststructsockaddr*sa,socklen_tsalen, char*host,socklen_thostlen, char*service,socklen_tservicelen, intflags);

sa(input)pointstothesocketaddressstructurecontainingtheprotocol addresstobeconvertedintoahumanreadablestring.salen(input)is thelengthofthisstructure. host(output)pointstoabufferabletocontainuptohostlen(output) characterscontainingthehostnameasanullterminatedstring. service(output)pointstoabufferabletocontainuptoservicelenbytes thatreceivestheservicenameasanullterminatedstring.Iftheservice's namecannotbelocated,thenumericformoftheserviceaddress(for example,itsportnumber)shallbereturnedinsteadofitsname.

63

Rino Nucara - GARR

IPv6 Tutorial

getnameinfo output (3/4)

input and

Tohelpallocatearraystoholdstringpointedbyhostandservice,two constantsaredefined:NI_MAXHOSTandNIMAXSERV.
#include<netdb.h> NI_MAXHOST//=1025maximumsizeofreturnedhoststring NIMAXSERV//=32maximumsizeofreturnedservicestring

64

Rino Nucara - GARR

IPv6 Tutorial

getnameinfo (4/4)
#include<sys/socket.h> #include<netdb.h> intgetnameinfo(conststructsockaddr*sa,socklen_tsalen, char*host,socklen_thostlen, char*service,socklen_tservicelen, intflags);

flagschangesthedefaultactionsofthefunction. Bydefaultthefullyqualifieddomainname(FQDN)forthehostshallbe returned,but: IftheflagbitNI_NOFQDNisset,onlythenodenameportionofthe FQDNshallbereturnedforlocalhosts. IftheflagbitNI_NUMERICHOSTisset,thenumericformofthehost's addressshallbereturnedinsteadofitsname.

65

Rino Nucara - GARR

IPv6 Tutorial

getnameinfo (4/4)
#include<sys/socket.h> #include<netdb.h> intgetnameinfo(conststructsockaddr*sa,socklen_tsalen, char*host,socklen_thostlen, char*service,socklen_tservicelen, intflags);

[] IftheflagbitNI_NAMEREQDisset,anerrorshallbereturnedifthe host'snamecannotbelocated. theflagbitNI_NUMERICSERVisset,thenumericformoftheservice addressshallbereturned(forexample,itsportnumber)insteadofits name,underallcircumstances. IftheflagbitNI_DGRAMisset,thisindicatesthattheserviceisa datagramservice(SOCK_DGRAM).Thedefaultbehaviorshallassume thattheserviceisastreamservice(SOCK_STREAM).

66

Rino Nucara - GARR

IPv6 Tutorial

getnameinfo examples
Twoexampleswillnowfollow,illustratingtheusage ofgetaddrinfo():
Firstillustratestheusageoftheresultfromgetaddrinfo() forsubsequentcallstosocket()andtoconnect(). Secondpassivelyopenslisteningsocketstoaccept incomingHTTP.

67

Rino Nucara - GARR

IPv6 Tutorial

fo examples 1 structaddrinfohints,*res,*res0;interror;ints;
memset(&hints,0,sizeof(hints)); hints.ai_family=AF_UNSPEC; hints.ai_socktype=SOCK_STREAM; error=getaddrinfo("www.kame.net","http",&hints,&res0); [] s=1; for(res=res0;res;res=res>ai_next) { s=socket(res>ai_family,res>ai_socktype,res>ai_protocol); if(s<0)continue; if(connect(s,res>ai_addr,res>ai_addrlen)<0){ close(s);s=1;continue;} break;//wegotone! } if(s<0){fprintf(stderr,"Noaddressesarereachable");exit(1);} freeaddrinfo(res0); }

68

Rino Nucara - GARR

IPv6 Tutorial

fo examples structaddrinfohints,*res,*res0; 2 interror;ints[MAXSOCK];intnsock;constchar*cause=NULL;


memset(&hints,0,sizeof(hints)); hints.ai_family=AF_UNSPEC; hints.aisocktype=SOCK_STREAM; hints.ai_flags=AI_PASSIVE; error=getaddrinfo(NULL,"http",&hints,&res0); nsock=0; for(res=res0;res&&nsock<MAXSOCK;res=res>ai_next) { s[nsock]=socket(res>ai_family,res>ai_socktype,res>ai_protocol); if(s[nsock]<0)continue; #ifdefIPV6_V6ONLY if(res>ai_family==AF_INET6){inton=1; if(setsockopt(s[nsock],IPPROTO_IPV6,IPV6_V6ONLY,&on,sizeof(on))) {close(s[nsock]);continue;}} #endif if(bind(s[nsock],res>ai_addr,res>ai_addrlen)<0) {close(s[nsock]);continue;} if(listen(s[nsock],SOMAXCONN)<0){close(s[nsock]);continue;} nsock++; } if(nsock==0){/*nolisteningsocketisavailable*/} freeaddrinfo(res0); }

69

Rino Nucara - GARR

IPv6 Tutorial

Address Testing Macros #include<netinet/in.h>


intIN6_IS_ADDR_UNSPECIFIED(conststructin6_addr*); intIN6_IS_ADDR_LOOPBACK(conststructin6_addr*); intIN6_IS_ADDR_MULTICAST(conststructin6_addr*); intIN6_IS_ADDR_LINKLOCAL(conststructin6_addr*); intIN6_IS_ADDR_SITELOCAL(conststructin6_addr*); intIN6_IS_ADDR_V4MAPPED(conststructin6_addr*); intIN6_IS_ADDR_V4COMPAT(conststructin6_addr*); intIN6_IS_ADDR_MC_NODELOCAL(conststructin6_addr*); intIN6_IS_ADDR_MC_LINKLOCAL(conststructin6_addr*); intIN6_IS_ADDR_MC_SITELOCAL(conststructin6_addr*); intIN6_IS_ADDR_MC_ORGLOCAL(conststructin6_addr*); intIN6_IS_ADDR_MC_GLOBAL(conststructin6_addr*);

70

Rino Nucara - GARR

IPv6 Tutorial

Porting application to IPv6 (1/2)


ToportIPv4applicationsinamultiprotocolenvironment, developersshouldlookoutforthesebasicpoints
UseDNSnamesinsteadofnumericaladdresses Replaceincidentalhardcodedaddresseswithotherkinds Sequencesofzeroscanbereplacedbydoublecolonssequence ::onlyonetimeperaddress,e.g.Thepreviousaddresscanbe rewrittenas2001:760:40ec::12:3a IntheIPv6RFCsanddocumentation,theminimumsubnetmask isshownas/64,butinsomecases,likepointtopoint connections,asmallersubnet(suchas/126)canbeused. Innumericaladdressing,RFC2732specifiesthatsquared bracketsdelimitIPv6addresstoavoidmismatcheswiththeport separatorsuchashttp://[2001:760:40ec::12.3a]:8000

71

Rino Nucara - GARR

IPv6 Tutorial

Porting application to IPv6 (2/2)


ApplicationsinadualstackhostprefertouseIPv6 addressinsteadofIPv4 InIPv6,itisnormaltohavemultipleaddressesassociated toaninterface.InIPv4,noaddressisassociatedtoa networkinterface,whileatleastone(linklocaladdress)is inIPv6. AllfunctionsprovidedbybroadcastinIPv4are implementedonmulticastinIPv6. Thetwoprotocolscannotcommunicatedirectly,evenin dualstackhosts.Therearesomedifferentmethodsto implementsuchcommunication,buttheyareoutofscope ofthisdocument.

72

Rino Nucara - GARR

IPv6 Tutorial

Rewriting applications
TorewriteanapplicationwithIPv6compliantcode, thefirststepistofindallIPv4dependentfunctions. Asimplewayistocheckthesourceandheaderfile withUNIXgreputility.
$grepsockaddr_in*c*.h $grepin_addr*.c*.h $grepinet_aton*.c*.h $grepgethostbyname*.c*.h

73

Rino Nucara - GARR

IPv6 Tutorial

Rewriting applications
Developersshouldpayattentiontohardcoded numericaladdress,hostnames,andbinary representationofaddresses. Itisrecommendedtomadeallnetworkfunctionsina singlefile. Itisalsosuggestedtoreplaceallgethostbyname withthegetaddrinfofunction,asimpleswitchcanbe usedtoimplementprotocoldependentpartofthe code. Serverapplicationsmustbedevelopedtohandle multiplelistensockets,oneperaddressfamily,using theselectcall.

74

Rino Nucara - GARR

IPv6 Tutorial

Introduction to IPv6 Programming In JAVA

75

Rino Nucara - GARR

IPv6 Tutorial

IPv6 and Java (1/2)


JavaAPIsarealreadyIPv4/IPv6compliant.IPv6supportinJava isavailablesince1.4.0inSolarisandLinuxmachinesandsince 1.5.0forWindowsXPand2003server. IPv6supportinJavaisautomaticandtransparent.Indeedno sourcecodechangeandnobytecodechangesarenecessary. EveryJavaapplicationisalreadyIPv6enabledif:

Itdoesnotusehardcodedaddresses(nodirectreferencesto IPv4literaladdresses); AlltheaddressorsocketinformationisencapsulatedintheJava NetworkingAPI; Throughsettingsystemproperties,addresstypeand/orsocket typepreferencescanbeset; Itdoesnotusenonspecificfunctionsintheaddresstranslation.

76

Rino Nucara - GARR

IPv6 Tutorial

IPv6 and Java (2/2)


IPv4mappedaddresshassignificanceonlyatthe implementationofadualprotocolstackanditis neverreturned. FornewapplicationsIpv6specificnewclassesand APIscanbeused.

77

Rino Nucara - GARR

IPv6 Tutorial

Java code example (server)

importjava.io.*;importjava.net.*; ServerSocketserverSock=null;Socketcs=null; try{ serverSock=newServerSocket(5000); cs=serverSock.accept(); BufferedOutputStreamb=new BufferedOutputStream(cs.getOutputStream()); PrintStreamos=newPrintStream(b,false); os.println(hallo!);os.println("Stop"); cs.close(); os.close(); }catch(Exceptione){[...]}

78

Rino Nucara - GARR

IPv6 Tutorial

Java code example (client)


importjava.io.*;importjava.net.*; Sockets=null;DataInputStreamis=null; try{ s=newSocket("localhost",5000); is=newDataInputStream(s.getInputStream()); Stringline; while((line=is.readLine())!=null){ System.out.println("received:"+line); if(line.equals("Stop"))break; } is.close();s.close(); }catch(IOExceptione){[..]}

79

Rino Nucara - GARR

IPv6 Tutorial

InetAddress
ThisclassrepresentsanIPaddress.Itprovides addressstorage,nameaddresstranslationmethods, addressconversionmethods,aswellasaddress testingmethods. InJ2SE1.4,thisclassisextendedtosupportboth IPv4andIPv6addresses. Utilitymethodsareaddedtocheckaddresstypesand scopes.

80

Rino Nucara - GARR

IPv6 Tutorial

InetAddress Example
InetAddressia=InetAddress.getByName("www.garr.it"); //or InetAddressia=InetAddress.getByName([::1]");//or "::1" Stringhost_name=ia.getHostName(); System.out.println(host_name);//ip6localhost Stringaddr=ia.getHostAddress(); System.out.println(addr);//printIPADDRESS InetAddress[]alladr=ia.getAllByName("www.kame.net"); for(inti=0;i<alladr.length;i++){System.out.println(alladr[i]);} print: www.kame.net/203.178.141.194 www.kame.net/2001:200:0:8002:203:47ff:fea5:3085

81

Rino Nucara - GARR

IPv6 Tutorial

Inet4Address and Inet6Address


Thetwotypesofaddresses,IPv4andIPv6,canbe distinguishedbytheJavatypeInet4Addressand Inet6Address. V4andV6specificstateandbehaviorsare implementedinthesetwosubclasses. DuetoJava'sobjectorientednature,anapplication normallyonlyneedstodealwithInetAddressclass throughpolymorphismitwillgetthecorrectbehavior. Onlywhenitneedstoaccessprotocolfamilyspecific behaviors,suchasincallinganIPv6onlymethod,or whenitcarestoknowtheclasstypesoftheIP address,williteverbecomeawareofInet4Address andInet6Address.

82

Rino Nucara - GARR

IPv6 Tutorial

Inet4Address and Inet6Address


Java1.4.introducestwonewclassesinordertodistinguishIPv4addresses fromIPv6addresses: publicfinalclassInet4AddressextendsInetAddress publicfinalclassInet6AddressextendsInetAddress

InetAddress

Inet4Address

Inet6Address

83

Rino Nucara - GARR

IPv6 Tutorial

New metods
InInetAddressclassnewmetodshavebeenadded: InetAddress.isAnyLocalAddress() InetAddress.isLoopbackAddress() InetAddress.isLinkLocalAddress() InetAddress.isSiteLocalAddress() InetAddress.isMCGlobal() InetAddress.isMCNodeLocal() InetAddress.isMCLinkLocal() InetAddress.isMCSiteLocal() InetAddress.isMCOrgLocal() InetAddress.getCanonicalHostName() InetAddress.getByAddr() Inet6AddresshaveametodmorethanInet4Address: Inet6Address.isIPv4CompatibleAddress()

84

Rino Nucara - GARR

IPv6 Tutorial

Code Example
EnumerationnetInter=NetworkInterface.getNetworkInterfaces(); while(netInter.hasMoreElements()) { NetworkInterfaceni=(NetworkInterface)netInter.nextElement(); System.out.println("Net.Int.:"+ni.getDisplayName()); Enumerationaddrs=ni.getInetAddresses(); while(addrs.hasMoreElements()) { Objecto=addrs.nextElement(); if(o.getClass()==InetAddress.class|| o.getClass()==Inet4Address.class|| o.getClass()==Inet6Address.class) { InetAddressiaddr=(InetAddress)o; System.out.println(iaddr.getCanonicalHostName()); System.out.print("addrtype:"); if(o.getClass()==Inet4Address.class){println("IPv4");} if(o.getClass()==Inet6Address.class){println("IPv6");} System.out.println("IP:"+iaddr.getHostAddress()); System.out.println("Loopback?"+iaddr.isLoopbackAddress()); System.out.println("SiteLocal?"+iaddr.isSiteLocalAddress()); System.out.println("LinkLocal?"+iaddr.isLinkLocalAddress()); } } Rino Nucara - GARR IPv6 Tutorial 85 }

Output Example
Net.Int.:eth0 CanonicalHostName:fe80:0:0:0:212:79ff:fe67:683d%2 addrtype:IPv6IP:fe80:0:0:0:212:79ff:fe67:683d%2 Loopback?FalseSiteLocal?FalseLinkLocal?true CanonicalHostName:2001:760:40ec:0:212:79ff:fe67:683d%2 addrtype:IPv6IP:2001:760:40ec:0:212:79ff:fe67:683d%2 Loopback?FalseSiteLocal?FalseLinkLocal?false CanonicalHostName:pcgarr20.dir.garr.it addrtype:IPv4IP:193.206.158.140 Loopback?FalseSiteLocal?FalseLinkLocal?false Net.Int.:lo CanonicalHostName:ip6localhost addrtype:IPv6IP:0:0:0:0:0:0:0:1%1 Loopback?TrueSiteLocal?FalseLinkLocal?false CanonicalHostName:localhost addrtype:IPv4IP:127.0.0.1 Loopback?TrueSiteLocal?FalseLinkLocal?false

86

Rino Nucara - GARR

IPv6 Tutorial

IPv6 Networking Properties: preferIPv4Stack


java.net.preferIPv4Stack(default:false) IfIPv6isavailableontheoperatingsystem,theunderlyingnativesocket willbeanIPv6socket.ThisallowsJava(tm)applicationstoconnecttoo, andacceptconnectionsfrom,bothIPv4andIPv6hosts. IfanapplicationhasapreferencetoonlyuseIPv4sockets,thenthis propertycanbesettotrue.Theimplicationisthattheapplicationwill notbeabletocommunicatewithIPv6hosts.

87

Rino Nucara - GARR

IPv6 Tutorial

java.net.preferIPv4Stack Example (1/3) $javanetworkInt


Net.Int.:eth0 CanonicalHostName:fe80:0:0:0:212:79ff:fe67:683d%2 IP:fe80:0:0:0:212:79ff:fe67:683d%2 CanonicalHostName:2001:760:40ec:0:212:79ff:fe67:683d%2 IP:2001:760:40ec:0:212:79ff:fe67:683d%2 CanonicalHostName:pcgarr20.dir.garr.it IP:193.206.158.140 Net.Int.:lo CanonicalHostName:ip6localhost IP:0:0:0:0:0:0:0:1%1 CanonicalHostName:localhost IP:127.0.0.1

88

Rino Nucara - GARR

IPv6 Tutorial

java.net.preferIPv4Stack Example (2/3)


$javaDjava.net.preferIPv4Stack=truenetworkInt Net.Int.:eth0 CanonicalHostName:pcgarr20.dir.garr.it IP:193.206.158.140 Net.Int.:lo CanonicalHostName:localhost IP:127.0.0.1

89

Rino Nucara - GARR

IPv6 Tutorial

java.net.preferIPv4Stack Example (3/3) NOTE


java.net.preferIPv4StackischeckedonlyonceattheVMinitializationtime, sotherenootherwaytouseitthanasanDoption.

System.setProperty("java.net.preferIPv4Stack","true");

Doesnot Work!

Propertiesp=newProperties(System.getProperties()); p.setProperty("java.net.preferIPv6Addresses","true"); System.setProperties(p);

Doesnot Work!

90

Rino Nucara - GARR

IPv6 Tutorial

IPv6 Networking Properties: preferIPv6Addresses


java.net.preferIPv6Addresses(default:false) IfIPv6isavailableontheoperatingsystem,thedefaultpreferenceistoprefer anIPv4mappedaddressoveranIPv6address.Thisisforbackward compatibilityreasonsforexample,applicationsthatdependonaccesstoan IPv4onlyservice,orapplicationsthatdependonthe%d.%d.%d.%d representationofanIPaddress. ThispropertycanbesettotrytochangethepreferencestouseIPv6 addressesoverIPv4addresses.Thisallowsapplicationstobetestedand deployedinenvironmentswheretheapplicationisexpectedtoconnecttoIPv6 services.

91

Rino Nucara - GARR

IPv6 Tutorial

java.net.preferIPv6Addresses Example

//System.setProperty("java.net.preferIPv6Addresses",false"); InetAddressia=InetAddress.getByName("www.kame.net"); Stringss=ia.getHostAddress(); System.out.println(ss);//print203.178.141.194

System.setProperty("java.net.preferIPv6Addresses","true"); InetAddressia=InetAddress.getByName("www.kame.net"); Stringss=ia.getHostAddress(); System.out.println(ss);//print2001:200:0:8002:203:47ff:fea5:3085

$javaDjava.net.preferIPv6Addresses=truejartest.jar 2001:200:0:8002:203:47ff:fea5:3085 $javaDjava.net.preferIPv6Addresses=falsejartest.jar 203.178.141.194 $javajartest.jar 203.178.141.194

92

Rino Nucara - GARR

IPv6 Tutorial

setPerformancePrefe rences java.net.SocketImpl


publicvoidsetPerformancePreferences( intconnectionTime,intlatency,intbandwidth) Thismethodallowstheapplicationtoexpressitsownpreferencestotunethe performancecharacteristicsofthissocket.Performancepreferencesare describedbythreeintegerswhosevaluesindicatetherelativeimportanceof shortconnectiontime,lowlatency,andhighbandwidth.Withthismethod,the networkorientednotionofQualityofService(QoS)isintroduced.Any applicationcansetitspreferencestoadaptitsnetworktrafficandprovidethe bestQoS. connectionTime:Anintexpressingtherelativeimportanceofashort connectiontime. latency:Anintexpressingtherelativeimportanceoflowlatency. bandwidth:Anintexpressingtherelativeimportanceofhighbandwidth.
Iftheapplicationprefersshortconnectiontimeoverbothlowlatencyandhighbandwidth,forexample, thenitcouldinvokethismethodwiththevalues(1,0,0). Iftheapplicationprefershighbandwidthabovelowlatency,andlowlatencyaboveshortconnection time,thenitcouldinvokethismethodwiththevalues(0,1,2). Rino Nucara - GARR IPv6 Tutorial 93

Introduction to IPv6 Programming In PERL

94

Rino Nucara - GARR

IPv6 Tutorial

Perl for IPv6


AnIPv6functionsetfortheperllanguageisprovidedbytheSocket6module. LiketheSocketcoremoduleforIPv4,thismoduleprovidesaCStylesetof functionstoopenandmanipulatesocketsinIPv6.Thegeneralstructureofthe moduleandtheaddressdatastructuresaresimilartotheCprogramming interface. Developersshouldtakecareofthesamegeneralconceptsdescribedinsection aboutintroductionprogrammingIPv6inC. ThemoduleisavailableontheCPANwebsite.Toworkproperly,themodule mustbeincludedinthecodeinconjunctiontothecoremoduleSocket.

useSocket UseSocket6

95

Rino Nucara - GARR

IPv6 Tutorial

Function list
inet_pton(FAMILY,TEXT_ADDRESS)

ThisfunctionconvertsstringformatIPv4/IPv6addressestobinaryformat,the FAMILYargumentspecifythetypeofaddress(AF_INETorAF_INET6).

inet_ntop(FAMILY,BINARY_ADDRESS)

Thisfunctionconvertsanaddressinbinaryformattostringformat;likeforthe previousfunction(inet_pton),theFAMILYargumentmustbeusedtospecify thefamilytypeoftheaddress.

example
$a=inet_ntop(AF_INET6,inet_pton(AF_INET6,"::1")); print$a;//print::1 96
Rino Nucara - GARR IPv6 Tutorial

Function list
pack_sockaddr_in6(PORT,ADDRESS)

Thisfunctionreturnsasockaddr_in6structurefilledwithPORTandADDRESS argumentsinthecorrectfields.TheADDRESSargumentisa16bytestructure (asreturnedbyinet_pton).Theotherfieldsofthestructurearenotset.


unpack_sockaddr_in6(NAME)

Thisfunctionunpacksasockaddr_in6structuretoanarrayoftwoelements, wherethefirstelementistheportnumberandthesecondelementisthe addressincludedinthestructure.

example
$lh6=inet_pton(AF_INET6,"::1"); $p_saddr6=pack_sockaddr_in6(80,$lh6); ($port,$host)=unpack_sockaddr_in6($p_saddr6); printinet_ntop(AF_INET6,$host);//print::1 print$port;//print80 97
Rino Nucara - GARR IPv6 Tutorial

Function list
pack_sockaddr_in6_all(PORT,FLOWINFO,ADDRESS,SCOPEID)

Thisfunctionreturnsasockaddr_in6structurefilledwiththefourspecified arguments.
unpack_sockaddr_in6_all(NAME)

Thisfunctionunpacksasockaddr_in6structuretoanarrayoffourelement: Theportnumber Flowinformations Ipv6networkaddress(16byteformat) Thescopeoftheaddress

98

Rino Nucara - GARR

IPv6 Tutorial

Function list
)]getaddrinfo(NODENAME,SERVICENAME,[FAMILY,SOCKTYPE,PROTOCOL,FLAGS

T hisfunctionconvertsnodenamestoaddressesandservicenamestoport n umbers.AtleastoneofNODENAMEandSERVICENAMEmusthaveatrue v alue.Ifthelookupissuccessfulthisfunctionreturnsanarrayofinformation b locks.Eachinformationblockconsistsoffiveelements:addressfamily,socket type,protocol,addressandcanonicalnameifspecified. .Theargumentsinsquaredbracketsareoptional


getnameinfo(NAME,[FLAGS])

Thisfunctionreturnsanodeoraservicename.TheoptionalattributeFLAG controlswhatkindoflookupisperformed.

99

Rino Nucara - GARR

IPv6 Tutorial

Example
useSocket; useSocket6; @res=getaddrinfo('hishost.com','daytime',AF_UNSPEC,SOCK_STREAM); $family=1; while(scalar(@res)>=5){ ($family,$socktype,$proto,$saddr,$canonname,@res)=@res; ($host,$port)=getnameinfo($saddr,NI_NUMERICHOST|NI_NUMERICSERV); printSTDERR"Tryingtoconnectto$hostportport$port...\n"; socket(Socket_Handle,$family,$socktype,$proto)||next; connect(Socket_Handle,$saddr)&&last; close(Socket_Handle); $family=1; } if($family!=1){ printSTDERR"connectedto$hostportport$port\n"; }else{ die"connectattemptfailed\n"; }

100

Rino Nucara - GARR

IPv6 Tutorial

Function list
gethostbyname2(HOSTNAME,FAMILY)

Thisfunctionisthemultiprotocolimplementationofgethostbyname;the addressfamilyisselectedbytheFAMILYattribute.Thisfunctionconvertsnode namestoaddresses.


gai_strerror(ERROR_NUMBER)

Thisfunctionreturnsastringcorrespondingtotheerrornumberpassedinas anargument.
in6addr_any

Thisfunctionreturnsthe16octetwildcardaddress.
in6add_loopback

Thisfunctionreturnsthe16octetloopbackaddress.

101

Rino Nucara - GARR

IPv6 Tutorial

Function list
getipnodebyname(HOST,[FAMILY,FLAGS])

ThisfunctiontakeseitheranodenameoranIPaddressstringandperformsa lookuponthatname(orconversionofthestring).Itreturnsalistoffive elements:thecanonicalhostname,theaddressfamily,thelengthinoctetsof theIPaddressesreturned,areferencetoalistofIPaddressstructures,anda referencetoalistofaliasesforthehostname.Thisfunctionwasdeprecatedin RFC3493.Thegetnameinfofunctionshouldbeusedinstead.


getipnodebyaddr(FAMILY,ADDRESS)

ThisfunctiontakesanIPaddressfamilyandanIPaddressstructureand performsareverselookuponthataddress.Thisfunctionwasdeprecatedin RFC3493:thegetaddrinfofunctionshouldbeusedinstead.

102

Rino Nucara - GARR

IPv6 Tutorial

Introduction to IPv6 Programming In PHP

103

Rino Nucara - GARR

IPv6 Tutorial

PHP and IPv6


IPv6issupportedbydefaultinPHP4.3.4andPHP 5.2.3versions. FewfunctionshavebeendefinedtosupportIPv6. sparsedocumentationisprovidedforIPv6 programming

104

Rino Nucara - GARR

IPv6 Tutorial

inet_ntop
stringinet_ntop(string$in_addr)

Thisfunctionconvertsa32bitIPv4,or128bitIPv6address(ifPHPwasbuilt withIPv6supportenabled)intoanaddressfamilyappropriatestring representation.ReturnsFALSEonfailure. Note:ThisfunctionisnotimplementedonWindowsplatforms.


$packed=chr(127).chr(0).chr(0).chr(1); $expanded=inet_ntop($packed); echo$expanded;/*Outputs:127.0.0.1*/

$packed=str_repeat(chr(0),15).chr(1); $expanded=inet_ntop($packed); echo$expanded;/*Outputs:::1*/

105

Rino Nucara - GARR

IPv6 Tutorial

inet_pton
stringinet_pton(string$address)

ThisfunctionconvertsahumanreadableIPv4orIPv6address(ifPHPwas builtwithIPv6supportenabled)intoanaddressfamilyappropriate32bitor 128bitbinarystructure. Note:ThisfunctionisnotimplementedonWindowsplatforms.

$in_addr=inet_pton('127.0.0.1'); $in6_addr=inet_pton('::1');

106

Rino Nucara - GARR

IPv6 Tutorial

fsockopen
resourcefsockopen(string$target[,int$port[,int&$errno[, string&$errstr[,float$timeout]]]])

Initiatesasocketconnectiontotheresourcespecifiedbytarget.PHPsupports targetsintheInternetandUnixdomainsasdescribedinAppendixP,Listof SupportedSocketTransports.Alistofsupportedtransportscanalsobe retrievedusingstream_get_transports(). fsockopen()returnsafilepointerwhichmaybeusedtogetherwiththeotherfile functions(suchasfgets(),fgetss(),fwrite(),fclose(),andfeof()). Dependingontheenvironment,theUnixdomainortheoptionalconnect timeoutmaynotbeavailable.

107

Rino Nucara - GARR

IPv6 Tutorial

example code
$fp=fsockopen($ip,80,$errno,$errstr); if(!$fp){ echo"ERROR:$errno$errstr<br/>\n"; }else{ $status=socket_get_status($fp); var_dump($status); fwrite($fp,"GET\n"); $txt=fread($fp,1000); echo$txt; fclose($fp); }

kamenoanimesmall.gif
//www.kame.net $ip="203.178.141.194;

//www.kame.net $ip='[2001:200::8002:203:47ff:fea5:3085]';

kameanimesmall.gif

108

Rino Nucara - GARR

IPv6 Tutorial

checkdnsrr
intcheckdnsrr(string$host[,string$type])

CheckDNSrecordscorrespondingtoagivenInternethostnameorIP address. ReturnsTRUEifanyrecordsarefound;returnsFALSEifnorecordswere foundorifanerroroccurred. typemaybeanyoneof:A,MX,NS,SOA,PTR,CNAME,AAAA,A6,SRV, NAPTRorANY.ThedefaultisMX. hostmayeitherbetheIPaddressindottedquadnotationorthehostname.

Note:AAAAtypeaddedwithPHP5.0.0
Note:ThisfunctionisnotimplementedonWindowsplatforms. (usePEAR>>Net_DNS)
echocheckdnsrr('www.kame.net','AAAA');//return1.

109

Rino Nucara - GARR

IPv6 Tutorial

gethostbyname
stringgethostbyname(string$hostname)

ReturnstheIPaddressoftheInternethostspecifiedbyhostnameorastring containingtheunmodifiedhostnameonfailure. gethostbynameandgethostbynameldoesnotaskforAAAArecords. BUTwecanwritecodeforaskingAAAArecordsusingdns_get_record() function

110

Rino Nucara - GARR

IPv6 Tutorial

PEAR Net_IPv6 (1/8)


require_once'Net/IPv6.php';

PearNet_IPv6Providesfunctiontoworkwiththe'InternetProtocolv6. Net_IPv6::checkIPv6()ValidationofIPv6addresses Net_IPv6::compress()compressanIPv6address Net_IPv6::uncompress()UncompressesanIPv6address Net_IPv6::getAddressType()ReturnsthetypeofanIPaddress Net_IPv6::getNetmask()Calculatesthenetworkprefix Net_IPv6::isInNetmask()ChecksifanIPisinaspecificaddressspace Net_IPv6::removeNetmaskSpec()RemovestheNetmasklength specification Net_IPv6::splitV64()splitsanIPv6addressinitIPv6andIPv4part
booleanNet_IPv6::checkIPv6(string$ip)

ChecksanIPforIPv6compatibility.$ipisthiptocheck.

111

Rino Nucara - GARR

IPv6 Tutorial

PEAR Net_IPv6 (2/8)


stringNet_IPv6::compress(string$ip)

CompressesanIPv6address.RFC2373allowsyoutocompresszerosinan addressto'::'.ThisfunctionexpectsanvalidIPv6addressandcompresses successivezerosto':: Es.FF01:0:0:0:0:0:0:101>FF01::101 0:0:0:0:0:0:0:1>::1


stringNet_IPv6::uncompress(string$ip)

UncompressesanIPv6address.RFC2373allowsyoutocompresszerosinan addressto'::'.ThisfunctionexpectsanvalidIPv6addressandexpandsthe'::' totherequiredzeros. Es.FF01::101 >FF01:0:0:0:0:0:0:101 ::1>0:0:0:0:0:0:0:1

112

Rino Nucara - GARR

IPv6 Tutorial

PEAR Net_IPv6 (3/8)


intNet_IPv6::getAddressType(string$ip)

ReturnsthetypeofanIPaddress.RFC1883,Section2.3describesseveral typesofaddressesintheIPv6addressespace.Thismethodstriestofindthe typeofaddressforthegivenIP. Returntheaddresstype(int).thetypecanbeoneofthisconstants: NET_IPV6_MULTICAST NET_IPV6_UNICAST_PROVIDER NET_IPV6_LOCAL_LINK NET_IPV6_LOCAL_SITE NET_IPV6_UNKNOWN_TYPE NET_IPV6_RESERVED_UNICAST_GEOGRAPHIC NET_IPV6_RESERVED_IPX NET_IPV6_RESERVED NET_IPV6_RESERVED_NSAP NET_IPV6_UNASSIGNED
113
Rino Nucara - GARR IPv6 Tutorial

PEAR Net_IPv6 (4/8)


stringNet_IPv6::getNetmask(string$ip[,int$bits=null])

Calculatesthenetworkprefixbasedonthenetmaskbits. string$ip:theIPaddressinHexformat,compressedIPsareallowed int$bits:ifthenumberofnetmaskbitsisnotpartoftheIP,youmustprovide themumberofbits Returnvalue:stringthenetworkprefix note:Thisfunctioncanbecalledstatically.

114

Rino Nucara - GARR

IPv6 Tutorial

PEAR Net_IPv6 (5/8)


booleanNet_IPv6::isInNetmask(string$ip,string$netmask[,int $bits=null])

Checksifan(compressed)IPisinaspecificaddressspace.IftheIPdoesnot containthenumberofnetmaskbits(forexample:F8000::FFFF/16),thenyou havetousethe$bitsparameter. string$iptheIPaddressinHexformat,compressedIPsareallowed string$netmaskthenetmask(forexample:F800::) int$bitsifthenumberofnetmaskbitsisnotpartoftheIP,youmust providethemumberofbits Returnvalue booleanTRUE,iftheIPisintheaddressspace. Thisfunctioncanbecalledstatically.

115

Rino Nucara - GARR

IPv6 Tutorial

PEAR Net_IPv6 (6/8)


booleanNet_IPv6::isInNetmask(string$ip,string$netmask[,int $bits=null])

Checksifan(compressed)IPisinaspecificaddressspace.IftheIPdoesnot containthenumberofnetmaskbits(forexample:F8000::FFFF/16),thenyou havetousethe$bitsparameter. string$iptheIPaddressinHexformat,compressedIPsareallowed string$netmaskthenetmask(forexample:F800::) int$bitsifthenumberofnetmaskbitsisnotpartoftheIP,youmust providethemumberofbits Returnvalue booleanTRUE,iftheIPisintheaddressspace. Thisfunctioncanbecalledstatically.

116

Rino Nucara - GARR

IPv6 Tutorial

PEAR Net_IPv6 (7/8)


stringNet_IPv6::removeNetmaskSpec(string$ip)

RemovesapossibleexistingnetmasklengthspecificationinanIPaddresse. string$iptheIPaddressinHexformat,compressedIPsareallowed Returnvalue stringtheIPwithoutnetmasklengthspecification. Thisfunctioncanbecalledstatically.

117

Rino Nucara - GARR

IPv6 Tutorial

PEAR Net_IPv6 (8/8)


arrayNet_IPv6::splitV64(string$ip)

SplitsanIPv6addressintotheIPv6andapossibleIPv4formatedpart.RFC 2373allowsyoutonotethelasttwopartsofanIPv6addressintheIPv4 addressformat. Parameter string$iptheIPaddresstosplit Returnvalue arraykey[0]containstheIPv6part key[1]theIPv4formatedpart Thisfunctioncanbecalledstatically.

118

Rino Nucara - GARR

IPv6 Tutorial

Bibliography

119

Rino Nucara - GARR

IPv6 Tutorial

Bibliography (from Web)


ProgrammingguidelinesontransitiontoIPv6 TomsP.deMiguelandEvaM.Castro
http://java.sun.com/j2se/1.5.0/docs/guide/net/ipv6_guide/index.html http://www.lilik.it/~mirko/gapil/gapil.html

NetworkingIPv6UserGuideforJDK/JRE5.0 www.PHP.net JavaandIPv6(slides) JeanChristopheCollet

http://long.ccaba.upc.es/long/045Guidelines/LONG_Trans_app_IPv6.pdf

SimonePiccardi,GuidaallaProgrammazioneinLinux

http://72.34.43.90/IPV6/North_American_IPv6_Summit_2004/Wednesday/PDFs/ Jean_Christophe_Collet.pdf

120

Rino Nucara - GARR

IPv6 Tutorial

Bibliography (Books)
QingLiTatuyaJinmeiKeiichiShima IPv6CoreProtocolsImplementation MORGANKAUFMAN W.RichardStevens UnixNetworkProgramming(secondedition) PrenticeHall JunichiroitojunHagino IPv6NetworkProgramming ELSEVIERDIGITALPRESS ElliotteRustyHarold JavaNetworkProgramming OREILLY MerlinHughesMichaelShoffnerDerekHammer JavaNetworkProgramming2edition MANNING

121

Rino Nucara - GARR

IPv6 Tutorial

Вам также может понравиться