int host(const char *s, struct bgpd_addr *h, u_int8_t *len) { int done = 0; int mask; char *p, *ps; const char *errstr; if ((p = strrchr(s, '/')) != NULL) { mask = strtonum(p + 1, 0, 128, &errstr); if (errstr) { log_warnx("prefixlen is %s: %s", errstr, p + 1); return (0); } if ((ps = malloc(strlen(s) - strlen(p) + 1)) == NULL) fatal("host: malloc"); strlcpy(ps, s, strlen(s) - strlen(p) + 1); } else { if ((ps = strdup(s)) == NULL) fatal("host: strdup"); mask = 128; } bzero(h, sizeof(struct bgpd_addr)); /* IPv4 address? */ if (!done) done = host_v4(s, h, len); /* IPv6 address? */ if (!done) { done = host_v6(ps, h); *len = mask; } free(ps); return (done); }
int host(const char *s, struct ntp_addr **hn) { struct ntp_addr *h = NULL; if (!strcmp(s, "*")) if ((h = calloc(1, sizeof(struct ntp_addr))) == NULL) fatal(NULL); /* IPv4 address? */ if (h == NULL) h = host_v4(s); /* IPv6 address? */ if (h == NULL) h = host_v6(s); if (h == NULL) return (0); *hn = h; return (1); }