context.c revision a4987cc03171e0ff3e3b07e7aac0f6bde8e09bf2
28d9fd53819cc163629c867466b20d8ebcae8842David Lawrence * Copyright (C) 2000 Internet Software Consortium.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * Permission to use, copy, modify, and distribute this software for any
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * purpose with or without fee is hereby granted, provided that the above
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * copyright notice and this permission notice appear in all copies.
15a44745412679c30a6d022733925af70a38b715David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
15a44745412679c30a6d022733925af70a38b715David Lawrence * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
15a44745412679c30a6d022733925af70a38b715David Lawrence * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
15a44745412679c30a6d022733925af70a38b715David Lawrence * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
15a44745412679c30a6d022733925af70a38b715David Lawrence * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15a44745412679c30a6d022733925af70a38b715David Lawrence * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
15a44745412679c30a6d022733925af70a38b715David Lawrence * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencestatic void lwres_free(void *, void *, size_t);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafssonlwres_context_create(lwres_context_t **contextp, void *arg,
eb6bd543c7d072efdca509eb17f8f301c1467b53Mark Andrews REQUIRE(contextp != NULL && *contextp == NULL);
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence * If we were not given anything special to use, use our own
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence * functions. These are just wrappers around malloc() and free().
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence if (malloc_function == NULL || free_function == NULL) {
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence ctx = malloc_function(arg, sizeof(lwres_context_t));
0b056755b2f423ba5f6adac8f7851d78f7d11437David Lawrence * Set up the context.
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence ctx->serial = (isc_uint32_t)ctx; /* XXXMLG */
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafssonlwres_context_destroy(lwres_context_t **contextp)
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence REQUIRE(contextp != NULL && *contextp != NULL);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencelwres_context_nextserial(lwres_context_t *ctx)
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencelwres_context_initserial(lwres_context_t *ctx, isc_uint32_t serial)
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencelwres_context_freemem(lwres_context_t *ctx, void *mem, size_t len)
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencelwres_context_allocmem(lwres_context_t *ctx, size_t len)
7ab0e69f61e61e81d489c95c7ebd981e74e7ef16Andreas Gustafsson localhost.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews ret = connect(s, (struct sockaddr *)&localhost, sizeof(localhost));
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews ret = sendto(ctx->sock, sendbase, sendlen, 0, NULL, 0);
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington ret2 = select(ctx->sock + 1, &readfds, NULL, NULL, &timeout);
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington * What happened with select?
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews ret = recvfrom(ctx->sock, recvbase, recvlen, 0,
bcd7fdf06ca76eb2f6eb157f56b612c503e062a7Mark Andrews * If we got something other than what we expect, re-issue our
bcd7fdf06ca76eb2f6eb157f56b612c503e062a7Mark Andrews * recvfrom() call. This can happen if an old result comes in,
bcd7fdf06ca76eb2f6eb157f56b612c503e062a7Mark Andrews * or if someone is sending us random stuff.