19
IPv6 Intro & Demo Yuxin Ouyang Yuhui Feng

IPv6 Intro & Demo Yuxin Ouyang Yuhui Feng. Why IPv6 Space allowed by IPv4 is saturating IPv4 is not secure by itself Data prioritization in IPv4 is not

Embed Size (px)

Citation preview

IPv6

Intro & Demo

Yuxin OuyangYuhui Feng

Why IPv6

• Space allowed by IPv4 is saturating

• IPv4 is not secure by itself

• Data prioritization in IPv4 is not up to date

• Does not provide a mechanism to have a globally unique IP address

Features

• Larger address space

• Simplified Header

• End-to-end Connectivity

• and more…

IPv6 - Addressing Modes

• Unicast

• Multicast

• And…Anycast

IPv6 - Anycast

• When a host wishes to communicate with a host equipped with an Anycast IP address, it sends a Unicast message. With the help of complex routing mechanism, that Unicast message is delivered to the host closest to the Sender in terms of Routing cost.

IPv6 - Anycast

IPv6 Subnetting

• The second half of the address (least significant 64 bits) is always used for hosts only. Therefore, there is no compromise if we sub-net the network.

• /48 prefix can be allocated to an organization providing it the ben-efit of ha-ving up to /64 subnet prefixes

• 16 bits of subnet is equivalent to IPv4’s Class B Network. Using these sub-net bits, an organization can have another 65 thou-sands of subnets which is by far, more than enough.

IPv6 Subnetting

IPv6 - Header• Version (4-bits)

• Traffic Class (8-bits)

• Flow Label (20-bits)

• Payload Length (16-bits)

• Next Header (8-bits)

• Hop Limit (8-bits)

• Source Address (128-bits)

• Destination Address (128-bits)

IPv6 – Mobility(connected to home link)

IPv6 – Mobility(connected to foreign link)

include <netinet/in.h>struct sockaddr_in6 {

u_int16_t sin6_family; // address family, AF_INET6

u_int16_t sin6_port; // port number, Network Byte Order

u_int32_t sin6_flowinfo; // IPv6 flow informationstruct in6_addr sin6_addr; // IPv6 addressu_int32_t sin6_scope_id; // Scope ID

};

struct in6_addr {unsigned char s6_addr[16]; // load with inet_pton()

};

IPv6 socket programming

// General socket address holding structure, big enough to hold either// struct sockaddr_in or struct sockaddr_in6 data:

struct sockaddr_storage {sa_family_t ss_family; // address familychar __ss_pad1[_SS_PAD1SIZE];int64_t __ss_align;char __ss_pad2[_SS_PAD2SIZE];

};

IPv6 socket programming

IPv6 socket programming

IPv4 IPv6

Family AF_INET AF_INET6

IP address Structure sockaddr_in sockaddr_in6

Wildcard address INADDR_ANY in6addr_any

string->IP address inet_aton( ) inet_pton( )

IP address-> string inet_ntoa( ) inet_ntop( )

Get IP address by host name gethostbyname( ) getaddrinfo( )

Get host name by IP address gethostbyaddr( ) getnameinfo( )

int main(int argc, const char * argv[]) { unsigned int client_s; //Connection socket descriptor struct sockaddr_in6 server_addr; //Server Internet address char out_buf[BUFSIZE]; //Output buffer char in_buf[BUFSIZE]; //Input buffer const char *ip_num="::1"; const char *port_num="10501"; const char *file_name="1.jpg"; int port=atoi(port_num); server_addr.sin6_family =AF_INET6; server_addr.sin6_port =htons(port); inet_pton(AF_INET6, ip_num, &server_addr.sin6_addr); //Socket client_s=socket(AF_INET6,SOCK_STREAM,0); //Connection connect(client_s,(struct sockaddr *)&server_addr,sizeof(server_addr)); //Start file and find the size of it FILE *fp=fopen(file_name,"r"); //Send the file name to server bzero(out_buf,BUFSIZE); strncpy(out_buf,file_name,strlen(file_name)); send(client_s,out_buf,(strlen(out_buf)+1),0); //Start to transfer the file data long int send_length=0; bzero(out_buf,BUFSIZE); while ((send_length=fread(out_buf,sizeof(char),BUFSIZE,fp))>0){ if (send(client_s,out_buf,send_length,0)<0){ perror("File send failed."); exit(1); } bzero(out_buf,BUFSIZE); } fclose(fp); close(client_s); return 0;}

Client TCP

int main(int argc, const char * argv[]) { unsigned int server_s; //Server socket descriptor and bind indicator struct sockaddr_in6 server_addr, client_addr; //Server and Client internet address unsigned int connect_s; //Connection socket descriptor unsigned int addr_len; //Internet address length char out_buf[BUFSIZE]; //Output buffer for data char in_buf[BUFSIZE]; //Input buffer for data char file_name[FILENAME_SIZE+1]; //File name for transferred onst char *port_num="10501"; long int port =atoi(port_num); server_addr.sin6_family =AF_INET6; server_addr.sin6_port =htons(port); server_addr.sin6_addr =in6addr_any; //Socket server_s=socket(AF_INET6,SOCK_STREAM,0); //Bind bind(server_s,(struct sockaddr *)&server_addr,sizeof(server_addr)); //Listen listen(server_s,SERVER_QUEUE); //Accept conncection addr_len=sizeof(client_addr); connect_s=accept(server_s,(struct sockaddr *)&client_addr,&addr_len); //Receive the file name from client bzero(in_buf,BUFSIZE); bzero(file_name,FILENAME_SIZE+1); recv(connect_s,in_buf,sizeof(in_buf),0); strncpy(file_name,in_buf,FILENAME_SIZE); //Create a file to write the data; FILE *fp=fopen(file_name,"w");

Server TCP

//Receive data from client to buffer and write them into the file long int recv_length; bzero(in_buf,BUFSIZE); while ((recv_length=recv(connect_s,in_buf,sizeof(in_buf),0))>0){ if(fwrite(in_buf,sizeof(char),recv_length,fp)<recv_length){ perror("File write filed.\n"); exit(1); } bzero(in_buf,BUFSIZE); } char str[40]; //IPv6 address in string inet_ntop(AF_INET6, &(client_addr.sin6_addr), str, 40); printf("File '%s' recieved successful!(From IP= '%s' port ='%d')\n", file_name, str, ntohs(client_addr.sin6_port)); fclose(fp); close(connect_s); close(server_s); return 0;}