=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/dig/dig.c,v retrieving revision 1.18 retrieving revision 1.19 diff -c -r1.18 -r1.19 *** src/usr.bin/dig/dig.c 2020/09/15 11:47:42 1.18 --- src/usr.bin/dig/dig.c 2020/12/20 11:27:47 1.19 *************** *** 14,24 **** * PERFORMANCE OF THIS SOFTWARE. */ ! /* $Id: dig.c,v 1.18 2020/09/15 11:47:42 florian Exp $ */ /*! \file */ ! #include #include #include #include --- 14,27 ---- * PERFORMANCE OF THIS SOFTWARE. */ ! /* $Id: dig.c,v 1.19 2020/12/20 11:27:47 florian Exp $ */ /*! \file */ ! #include ! #include + #include + #include #include #include *************** *** 1275,1284 **** dns_rdatatype_t rdtype; dns_rdataclass_t rdclass; char textname[MXNAME]; ! struct in_addr in4; ! struct in6_addr in6; ! in_port_t srcport; ! char *hash, *cmd; uint32_t num; const char *errstr; --- 1278,1284 ---- dns_rdatatype_t rdtype; dns_rdataclass_t rdclass; char textname[MXNAME]; ! char *cmd; uint32_t num; const char *errstr; *************** *** 1346,1373 **** if (value == NULL) goto invalid_option; switch (opt) { ! case 'b': hash = strchr(value, '#'); if (hash != NULL) { - num = strtonum(hash + 1, 0, MAXPORT, &errstr); - if (errstr != NULL) - fatal("port number is %s: '%s'", errstr, - hash + 1); - srcport = num; *hash = '\0'; } else ! srcport = 0; ! if (have_ipv6 && inet_pton(AF_INET6, value, &in6) == 1) ! isc_sockaddr_fromin6(&bind_address, &in6, srcport); ! else if (have_ipv4 && inet_pton(AF_INET, value, &in4) == 1) ! isc_sockaddr_fromin(&bind_address, &in4, srcport); ! else fatal("invalid address %s", value); ! if (hash != NULL) ! *hash = '#'; specified_source = 1; return (value_from_next); case 'c': if ((*lookup)->rdclassset) { fprintf(stderr, ";; Warning, extra class option\n"); --- 1346,1384 ---- if (value == NULL) goto invalid_option; switch (opt) { ! case 'b': { ! struct addrinfo *ai = NULL, hints; ! int error; ! char *hash; ! ! memset(&hints, 0, sizeof(hints)); ! hints.ai_flags = AI_NUMERICHOST; ! hints.ai_socktype = SOCK_DGRAM; ! hash = strchr(value, '#'); if (hash != NULL) { *hash = '\0'; + error = getaddrinfo(value, hash + 1, &hints, &ai); + *hash = '#'; } else ! error = getaddrinfo(value, NULL, &hints, &ai); ! ! if (error) ! fatal("invalid address %s: %s", value, ! gai_strerror(error)); ! if (ai == NULL || ai->ai_addrlen > sizeof(bind_address)) fatal("invalid address %s", value); + if (!have_ipv4 && ai->ai_family == AF_INET) + fatal("%s: wrong address family", value); + if (!have_ipv6 && ai->ai_family == AF_INET6) + fatal("%s: wrong address family", value); ! memset(&bind_address, 0, sizeof(bind_address)); ! memcpy(&bind_address, ai->ai_addr, ai->ai_addrlen); ! specified_source = 1; return (value_from_next); + } case 'c': if ((*lookup)->rdclassset) { fprintf(stderr, ";; Warning, extra class option\n");