/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Iain Hibbert.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* If AttributeIDList is given as NULL, request all attributes.
* (this is actually const data but we can't declare it const)
*/
static uint8_t ail_default[] = { 0x0a, 0x00, 0x00, 0xff, 0xff };
/*
* This provides the maximum size that the response buffer will be
* allowed to grow to.
*
* Default is UINT16_MAX but it can be overridden at runtime.
*/
static size_t
sdp_response_max(void)
{
static size_t max = UINT16_MAX;
static unsigned int check = 1;
char *env, *ep;
unsigned long v;
while (atomic_swap_uint(&check, 0)) { /* only check env once */
env = getenv("SDP_RESPONSE_MAX");
if (env == NULL)
break;
errno = 0;
v = strtoul(env, &ep, 0);
if (env[0] == '\0' || *ep != '\0')
break;
if (errno == ERANGE && v == ULONG_MAX)
break;
/* lower limit is arbitrary */
if (v < UINT8_MAX || v > UINT32_MAX)
break;