-/* $OpenBSD: parse.y,v 1.84 2023/12/18 16:56:01 martijn Exp $ */
+/* $OpenBSD: parse.y,v 1.85 2023/12/18 16:58:26 martijn Exp $ */
/*
* Copyright (c) 2007, 2008, 2012 Reyk Floeter <reyk@openbsd.org>
static int32_t enginepen;
static size_t engineidlen;
-int host(const char *, const char *, int,
+int host(const char *, const char *, int, int,
struct sockaddr_storage *, int);
int listen_add(struct sockaddr_storage *, int, int);
}
for (i = 0; i < addresslen; i++) {
- nhosts = host(address[i], port, $1, ss, nitems(ss));
- if (nhosts < 1) {
+ if ((nhosts = host(address[i], port, AF_UNSPEC,
+ $1, ss, nitems(ss))) < 1) {
yyerror("invalid address: %s", $2);
free($2);
free($3);
YYERROR;
}
- if (host($1, SNMPTRAP_PORT, SOCK_DGRAM, &ss, 1) <= 0) {
+ if (host($1, SNMPTRAP_PORT, AF_UNSPEC, SOCK_DGRAM,
+ &ss, 1) <= 0) {
yyerror("invalid host: %s", $1);
free($1);
free($2);
free($1);
memcpy(&(tr->ta_ss), &ss, sizeof(ss));
if ($4 != NULL) {
- if (host($4, "0", SOCK_DGRAM, &ss, 1) <= 0) {
+ if (host($4, "0", ss.ss_family, SOCK_DGRAM,
+ &ss, 1) <= 0) {
yyerror("invalid source-address: %s",
$4);
free($2);
/* Setup default listen addresses */
if (TAILQ_EMPTY(&conf->sc_addresses)) {
- if (host("0.0.0.0", SNMP_PORT, SOCK_DGRAM, &ss, 1) != 1)
+ if (host("0.0.0.0", SNMP_PORT, AF_INET, SOCK_DGRAM,
+ &ss, 1) != 1)
fatal("Unexpected resolving of 0.0.0.0");
if (listen_add(&ss, SOCK_DGRAM, 0) == -1)
fatal("calloc");
- if (host("::", SNMP_PORT, SOCK_DGRAM, &ss, 1) != 1)
+ if (host("::", SNMP_PORT, AF_INET6, SOCK_DGRAM, &ss, 1) != 1)
fatal("Unexpected resolving of ::");
if (listen_add(&ss, SOCK_DGRAM, 0) == -1)
fatal("calloc");
}
int
-host(const char *s, const char *port, int type, struct sockaddr_storage *ss,
- int max)
+host(const char *s, const char *port, int family, int type,
+ struct sockaddr_storage *ss, int max)
{
struct addrinfo hints, *res0, *res;
int error, i;
bzero(&hints, sizeof(hints));
- hints.ai_family = PF_UNSPEC;
+ hints.ai_family = family;
hints.ai_socktype = type;
/*
* Without AI_NUMERICHOST getaddrinfo might not resolve ip addresses