Programmation Avancée en C


bind_ipv6.c

00001 #include <stdio.h>     
00002 #include <stdlib.h>
00003 #include <netinet/in.h>
00004 #include <sys/types.h>
00005 #include <sys/socket.h>
00006 #include <unistd.h>
00007 
00008 
00009 int main()
00010 {
00011         int sockfd;
00012 
00013         struct sockaddr_in6 server;
00014         server.sin6_family = AF_INET6;
00015         server.sin6_port   = 6666;
00016         server.sin6_addr   = in6addr_any; // wildcard
00017         // Création d'une socket.
00018         if ((sockfd = socket(PF_INET6, SOCK_STREAM, 0)) == -1) {
00019                 perror("[socket]");
00020                 return(EXIT_FAILURE);
00021         }
00022         // Attachement à l'adresse serveur.
00023         if (bind(sockfd, (struct sockaddr *) &server, sizeof(server))) {
00024                 perror("[bind]");
00025         }
00026         close(sockfd);
00027         return EXIT_SUCCESS;
00028 }
00029