BlinkenArea - GitList
Repositories
Blog
Wiki
BlinkenLib
Code
Commits
Branches
Tags
Search
Tree:
c3d5a66
Branches
Tags
master
v0.1
v0.2
v0.3
v0.3.1
v0.4
v0.4.1
v0.5
v0.5.1
v0.5.2
v0.5.3
v0.5.4
v0.5.5
v0.6.0
v0.6.1
v0.6.2
v0.6.3
v0.6.4
v0.6.5
v0.6.6
v0.6.7
v0.6.8
v0.6.9
v0.7.0
v0.7.1
v0.7.10
v0.7.2
v0.7.3
v0.7.4
v0.7.5
v0.7.6
v0.7.7
v0.7.8
v0.7.9
v0.8.0
v0.8.1
BlinkenLib
BlinkenLib
Tools2.c
update email address of author
Stefan Schuermans
commited
c3d5a66
at 2014-05-10 10:31:10
Tools2.c
Blame
History
Raw
/* BlinkenLib Copyright 2004-2014 Stefan Schuermans <stefan@schuermans.info> Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html a blinkenarea.org project */ #include <stdio.h> #include <stdlib.h> #include <string.h> #ifdef WIN32 #include <winsock2.h> #else #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #endif #include "Tools2.h" // convert text to IPv4 address int txt2addr(char *text, struct sockaddr_in *addr) { char txt[48]; unsigned short port; if (sscanf(text, "%32[0-9.]:%hu", txt, &port) == 2) { addr->sin_family = AF_INET; addr->sin_port = htons(port); addr->sin_addr.s_addr = inet_addr(txt); return 1; } else if (sscanf(text, "%32[0-9.]", txt) == 1) { addr->sin_family = AF_INET; addr->sin_port = htons(2323); addr->sin_addr.s_addr = inet_addr(txt); return 1; } else if (sscanf(text, "%hu", &port) == 1) { addr->sin_family = AF_INET; addr->sin_port = htons(port); addr->sin_addr.s_addr = htonl(INADDR_ANY); return 1; } else { return 0; } } // convert text to IPv6 address int txt2addr6(char *text, struct sockaddr_in6 *addr6) { char txt[128]; unsigned short port; if (sscanf(text, "[%96[0-9a-fA-F:]]:%hu", txt, &port) == 2) { addr6->sin6_family = AF_INET6; addr6->sin6_port = htons(port); if (inet_pton(AF_INET6, txt, &addr6->sin6_addr)) return 1; else return 0; } else if (sscanf(text, "[%96[0-9a-fA-F:]]", txt) == 1) { addr6->sin6_family = AF_INET6; addr6->sin6_port = htons(2323); if (inet_pton(AF_INET6, txt, &addr6->sin6_addr)) return 1; else return 0; } else if (sscanf(text, "%hu", &port) == 1) { addr6->sin6_family = AF_INET6; addr6->sin6_port = htons(port); if (inet_pton(AF_INET6, "::", &addr6->sin6_addr)) return 1; else return 0; } else { return 0; } }