diff options
Diffstat (limited to 'misc.c')
-rw-r--r-- | misc.c | 44 |
1 files changed, 43 insertions, 1 deletions
@@ -23,7 +23,7 @@ | |||
23 | */ | 23 | */ |
24 | 24 | ||
25 | #include "includes.h" | 25 | #include "includes.h" |
26 | RCSID("$OpenBSD: misc.c,v 1.27 2004/12/11 01:48:56 dtucker Exp $"); | 26 | RCSID("$OpenBSD: misc.c,v 1.28 2005/03/01 10:09:52 djm Exp $"); |
27 | 27 | ||
28 | #include "misc.h" | 28 | #include "misc.h" |
29 | #include "log.h" | 29 | #include "log.h" |
@@ -275,6 +275,48 @@ convtime(const char *s) | |||
275 | return total; | 275 | return total; |
276 | } | 276 | } |
277 | 277 | ||
278 | /* | ||
279 | * Search for next delimiter between hostnames/addresses and ports. | ||
280 | * Argument may be modified (for termination). | ||
281 | * Returns *cp if parsing succeeds. | ||
282 | * *cp is set to the start of the next delimiter, if one was found. | ||
283 | * If this is the last field, *cp is set to NULL. | ||
284 | */ | ||
285 | char * | ||
286 | hpdelim(char **cp) | ||
287 | { | ||
288 | char *s, *old; | ||
289 | |||
290 | if (cp == NULL || *cp == NULL) | ||
291 | return NULL; | ||
292 | |||
293 | old = s = *cp; | ||
294 | if (*s == '[') { | ||
295 | if ((s = strchr(s, ']')) == NULL) | ||
296 | return NULL; | ||
297 | else | ||
298 | s++; | ||
299 | } else if ((s = strpbrk(s, ":/")) == NULL) | ||
300 | s = *cp + strlen(*cp); /* skip to end (see first case below) */ | ||
301 | |||
302 | switch (*s) { | ||
303 | case '\0': | ||
304 | *cp = NULL; /* no more fields*/ | ||
305 | break; | ||
306 | |||
307 | case ':': | ||
308 | case '/': | ||
309 | *s = '\0'; /* terminate */ | ||
310 | *cp = s + 1; | ||
311 | break; | ||
312 | |||
313 | default: | ||
314 | return NULL; | ||
315 | } | ||
316 | |||
317 | return old; | ||
318 | } | ||
319 | |||
278 | char * | 320 | char * |
279 | cleanhostname(char *host) | 321 | cleanhostname(char *host) |
280 | { | 322 | { |