2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001-2005 Alexander Barton (alex@barton.de)
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * Please read the file COPYING, README and AUTHORS for more information.
17 static char UNUSED id[] = "$Id: tool.c,v 1.7 2007/11/23 16:26:05 fw Exp $";
25 #include <netinet/in.h>
26 #ifdef HAVE_ARPA_INET_H
27 # include <arpa/inet.h>
35 * Removes all leading and trailing whitespaces of a string.
36 * @param String The string to remove whitespaces from.
39 ngt_TrimStr(char *String)
43 assert(String != NULL);
47 /* Remove whitespaces at the beginning of the string ... */
48 while (*start == ' ' || *start == '\t' ||
49 *start == '\n' || *start == '\r')
57 /* ... and at the end: */
58 end = strchr(start, '\0');
60 while ((*end == ' ' || *end == '\t' || *end == '\n' || *end == '\r')
64 /* New trailing NULL byte */
67 memmove(String, start, (size_t)(end - start)+1);
72 ngt_LowerStr( char *String )
74 /* String in Kleinbuchstaben konvertieren. Der uebergebene
75 * Speicherbereich wird durch das Ergebnis ersetzt, zusaetzlich
76 * wird dieser auch als Pointer geliefert. */
80 assert( String != NULL );
82 /* Zeichen konvertieren */
86 *ptr = tolower( *ptr );
95 ngt_TrimLastChr( char *String, const char Chr)
97 /* If last character in the string matches Chr, remove it.
98 * Empty strings are handled correctly. */
102 assert( String != NULL );
104 len = strlen( String );
105 if( len == 0 ) return;
109 if( String[len] == Chr ) String[len] = '\0';
110 } /* ngt_TrimLastChr */
114 ngt_IPStrToBin(const char *ip_str, struct in_addr *inaddr)
116 /* AF is always AF_INET for now */
117 #ifdef HAVE_INET_ATON
118 if (inet_aton(ip_str, inaddr) == 0)
121 inaddr->s_addr = inet_addr(ip_str);
122 if (inaddr->s_addr == (unsigned)-1)