c9469b64fc3933d0565ffba8a45be8a39df6b927
Stefan Schuermans add IPv6 support to Blinken...

Stefan Schuermans authored 10 years ago

BlinkenLib/Tools2.c   1) /* BlinkenLib
Stefan Schuermans update email address of author

Stefan Schuermans authored 10 years ago

BlinkenLib/Tools2.c   2)    Copyright 2004-2014 Stefan Schuermans <stefan@schuermans.info>
Stefan Schuermans add IPv6 support to Blinken...

Stefan Schuermans authored 10 years ago

BlinkenLib/Tools2.c   3)    Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html
BlinkenLib/Tools2.c   4)    a blinkenarea.org project */
BlinkenLib/Tools2.c   5) 
BlinkenLib/Tools2.c   6) #include <stdio.h>
BlinkenLib/Tools2.c   7) #include <stdlib.h>
BlinkenLib/Tools2.c   8) #include <string.h>
BlinkenLib/Tools2.c   9) #ifdef WIN32
BlinkenLib/Tools2.c  10) #include <winsock2.h>
Stefan Schuermans update Windows support

Stefan Schuermans authored 7 years ago

BlinkenLib/Tools2.c  11) #include <ws2tcpip.h>
Stefan Schuermans add IPv6 support to Blinken...

Stefan Schuermans authored 10 years ago

BlinkenLib/Tools2.c  12) #else
BlinkenLib/Tools2.c  13) #include <sys/types.h>
BlinkenLib/Tools2.c  14) #include <sys/socket.h>
BlinkenLib/Tools2.c  15) #include <netinet/in.h>
BlinkenLib/Tools2.c  16) #include <arpa/inet.h>
BlinkenLib/Tools2.c  17) #endif
BlinkenLib/Tools2.c  18) 
BlinkenLib/Tools2.c  19) #include "Tools2.h"
BlinkenLib/Tools2.c  20) 
Stefan Schuermans update Windows support

Stefan Schuermans authored 7 years ago

BlinkenLib/Tools2.c  21) #ifdef WIN32
BlinkenLib/Tools2.c  22) static int inet_pton(int af, const char *src, void *dst)
BlinkenLib/Tools2.c  23) {
BlinkenLib/Tools2.c  24)   struct sockaddr_storage ss;
BlinkenLib/Tools2.c  25)   int size = sizeof(ss);
BlinkenLib/Tools2.c  26)   char src_copy[INET6_ADDRSTRLEN + 1];
BlinkenLib/Tools2.c  27) 
BlinkenLib/Tools2.c  28)   ZeroMemory(&ss, sizeof(ss));
BlinkenLib/Tools2.c  29)   strncpy (src_copy, src, sizeof(src_copy));
BlinkenLib/Tools2.c  30)   src_copy[sizeof(src_copy) - 1] = 0;
BlinkenLib/Tools2.c  31) 
BlinkenLib/Tools2.c  32)   if (WSAStringToAddress(src_copy, af, NULL, (struct sockaddr *)&ss, &size) == 0) {
BlinkenLib/Tools2.c  33)     switch(af) {
BlinkenLib/Tools2.c  34)       case AF_INET:
BlinkenLib/Tools2.c  35)         *(struct in_addr *)dst = ((struct sockaddr_in *)&ss)->sin_addr;
BlinkenLib/Tools2.c  36)         return 1;
BlinkenLib/Tools2.c  37)       case AF_INET6:
BlinkenLib/Tools2.c  38)         *(struct in6_addr *)dst = ((struct sockaddr_in6 *)&ss)->sin6_addr;
BlinkenLib/Tools2.c  39)         return 1;
BlinkenLib/Tools2.c  40)     }
BlinkenLib/Tools2.c  41)   }
BlinkenLib/Tools2.c  42)   return 0;
BlinkenLib/Tools2.c  43) }
BlinkenLib/Tools2.c  44) #endif
BlinkenLib/Tools2.c  45)