X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=ngircd-alex.git;a=blobdiff_plain;f=src%2Ftool%2Ftool.c;h=dc2384519cd54e6337a0fd2cdc35722a83ecb257;hp=effa640da84ad625e73647d0b361c880e975fdcc;hb=82d32ffb28262b302fb435739e4c81bd3c1a1b85;hpb=cba9270845a6a6b03b4e163eb7fd5d3b9df96a50 diff --git a/src/tool/tool.c b/src/tool/tool.c index effa640d..dc238451 100644 --- a/src/tool/tool.c +++ b/src/tool/tool.c @@ -14,7 +14,7 @@ #include "portab.h" -static char UNUSED id[] = "$Id: tool.c,v 1.4 2006/03/22 08:05:10 alex Exp $"; +static char UNUSED id[] = "$Id: tool.c,v 1.7 2007/11/23 16:26:05 fw Exp $"; #include "imp.h" #include @@ -22,6 +22,11 @@ static char UNUSED id[] = "$Id: tool.c,v 1.4 2006/03/22 08:05:10 alex Exp $"; #include #include +#include +#ifdef HAVE_ARPA_INET_H +# include +#endif + #include "exp.h" #include "tool.h" @@ -40,11 +45,18 @@ ngt_TrimStr(char *String) start = String; /* Remove whitespaces at the beginning of the string ... */ - while (*start == ' ' || *start == '\t') + while (*start == ' ' || *start == '\t' || + *start == '\n' || *start == '\r') start++; + if (!*start) { + *String = '\0'; + return; + } + /* ... and at the end: */ end = strchr(start, '\0'); + end--; while ((*end == ' ' || *end == '\t' || *end == '\n' || *end == '\r') && end >= start) end--; @@ -52,7 +64,7 @@ ngt_TrimStr(char *String) /* New trailing NULL byte */ *(++end) = '\0'; - memmove(String, start, (size_t)(end - start)); + memmove(String, start, (size_t)(end - start)+1); } /* ngt_TrimStr */ @@ -98,4 +110,22 @@ ngt_TrimLastChr( char *String, const char Chr) } /* ngt_TrimLastChr */ +GLOBAL bool +ngt_IPStrToBin(const char *ip_str, struct in_addr *inaddr) +{ + /* AF is always AF_INET for now */ +#ifdef HAVE_INET_ATON + if (inet_aton(ip_str, inaddr) == 0) + return false; +#else + inaddr->s_addr = inet_addr(ip_str); + if (inaddr->s_addr == (unsigned)-1) + return false; +#endif + return true; +} + + + + /* -eof- */