Lines Matching refs:iter
104 isc_interfaceiter_t *iter;
113 iter = isc_mem_get(mctx, sizeof(*iter));
114 if (iter == NULL)
119 iter->mctx = mctx;
120 iter->buf4 = NULL;
121 iter->buf6 = NULL;
122 iter->pos4 = NULL;
123 iter->pos6 = 0;
124 iter->v6loop = ISC_TRUE;
125 iter->pos6zero = ISC_TRUE;
126 iter->buf6size = 0;
127 iter->buf4size = 0;
128 iter->result = ISC_R_FAILURE;
129 iter->numIF = 0;
130 iter->v4IF = 0;
136 iter->socket = socket(AF_INET, SOCK_DGRAM, 0);
137 if (iter->socket == INVALID_SOCKET) {
153 iter->buf4size = IFCONF_SIZE_INITIAL*sizeof(INTERFACE_INFO);
156 iter->buf4 = isc_mem_get(mctx, iter->buf4size);
157 if (iter->buf4 == NULL) {
162 if (WSAIoctl(iter->socket, SIO_GET_INTERFACE_LIST,
163 0, 0, iter->buf4, iter->buf4size,
187 (bytesReturned < iter->buf4size))
190 if (iter->buf4size >= IFCONF_SIZE_MAX*sizeof(INTERFACE_INFO)) {
197 isc_mem_put(mctx, iter->buf4, iter->buf4size);
199 iter->buf4size += IFCONF_SIZE_INCREMENT *
207 iter->v4IF = bytesReturned/sizeof(INTERFACE_INFO);
210 closesocket(iter->socket);
217 iter->socket = socket(AF_INET6, SOCK_DGRAM, 0);
218 if (iter->socket == INVALID_SOCKET) {
234 iter->buf6size = sizeof(SOCKET_ADDRESS_LIST) +
238 iter->buf6 = isc_mem_get(mctx, iter->buf6size);
239 if (iter->buf6 == NULL) {
244 if (WSAIoctl(iter->socket, SIO_ADDRESS_LIST_QUERY,
245 0, 0, iter->buf6, iter->buf6size,
264 if (iter->buf6size >= IFCONF_SIZE_MAX*sizeof(SOCKET_ADDRESS)) {
271 isc_mem_put(mctx, iter->buf6, iter->buf6size);
273 iter->buf6size += IFCONF_SIZE_INCREMENT *
277 closesocket(iter->socket);
280 iter->magic = IFITER_MAGIC;
281 *iterp = iter;
285 isc_mem_put(mctx, iter->buf6, iter->buf6size);
288 if (iter->buf4 != NULL)
289 isc_mem_put(mctx, iter->buf4, iter->buf4size);
292 if (iter->socket != INVALID_SOCKET)
293 (void) closesocket(iter->socket);
296 isc_mem_put(mctx, iter, sizeof(*iter));
301 * Get information about the current interface to iter->current.
309 internal_current(isc_interfaceiter_t *iter) {
313 REQUIRE(VALID_IFITER(iter));
314 REQUIRE(iter->numIF >= 0);
316 memset(&iter->current, 0, sizeof(iter->current));
317 iter->current.af = AF_INET;
319 get_addr(AF_INET, &iter->current.address,
320 (struct sockaddr *)&(iter->IFData.iiAddress));
326 iter->current.flags = 0;
327 flags = iter->IFData.iiFlags;
330 iter->current.flags |= INTERFACE_F_UP;
333 iter->current.flags |= INTERFACE_F_POINTTOPOINT;
334 snprintf(iter->current.name, sizeof(iter->current.name),
335 "PPP Interface %d", iter->numIF);
340 iter->current.flags |= INTERFACE_F_LOOPBACK;
341 snprintf(iter->current.name, sizeof(iter->current.name),
342 "Loopback Interface %d", iter->numIF);
349 if ((iter->current.flags & INTERFACE_F_POINTTOPOINT) != 0) {
350 get_addr(AF_INET, &iter->current.dstaddress,
351 (struct sockaddr *)&(iter->IFData.iiBroadcastAddress));
355 snprintf(iter->current.name, sizeof(iter->current.name),
356 "TCP/IP Interface %d", iter->numIF);
361 get_addr(AF_INET, &iter->current.netmask,
362 (struct sockaddr *)&(iter->IFData.iiNetmask));
368 internal_current6(isc_interfaceiter_t *iter) {
372 REQUIRE(VALID_IFITER(iter));
373 REQUIRE(iter->buf6 != NULL);
375 memset(&iter->current, 0, sizeof(iter->current));
376 iter->current.af = AF_INET6;
378 if (!iter->pos6zero) {
379 if (iter->pos6 == 0U)
380 iter->pos6zero = ISC_TRUE;
381 get_addr(AF_INET6, &iter->current.address,
382 iter->buf6->Address[iter->pos6].lpSockaddr);
388 iter->current.flags = INTERFACE_F_UP;
390 snprintf(iter->current.name, sizeof(iter->current.name),
391 "TCP/IPv6 Interface %d", iter->pos6 + 1);
394 iter->current.netmask.type.in6.s6_addr[i] = 0xff;
395 iter->current.netmask.family = AF_INET6;
396 if (IN6_IS_ADDR_LOOPBACK(&iter->current.address.type.in6))
397 iter->v6loop = ISC_TRUE;
404 iter->v6loop = ISC_TRUE; /* So we don't loop forever. */
418 iter->current.flags = INTERFACE_F_UP | INTERFACE_F_LOOPBACK;
419 snprintf(iter->current.name, sizeof(iter->current.name),
423 iter->current.address.type.in6.s6_addr[i] = 0;
425 iter->current.address.type.in6.s6_addr[i] = 1;
426 iter->current.netmask.type.in6.s6_addr[i] = 0xff;
428 iter->current.address.family = AF_INET6;
429 iter->current.netmask.family = AF_INET6;
442 internal_next(isc_interfaceiter_t *iter) {
443 if (iter->numIF >= iter->v4IF)
453 if (iter->numIF == 0)
454 iter->pos4 = (INTERFACE_INFO *)(iter->buf4 + (iter->v4IF));
456 iter->pos4--;
457 if (&(iter->pos4) < &(iter->buf4))
460 memset(&(iter->IFData), 0, sizeof(INTERFACE_INFO));
461 memmove(&(iter->IFData), iter->pos4, sizeof(INTERFACE_INFO));
462 iter->numIF++;
468 internal_next6(isc_interfaceiter_t *iter) {
469 if (iter->pos6 == 0U && iter->v6loop)
471 if (iter->pos6 != 0U)
472 iter->pos6--;
477 isc_interfaceiter_current(isc_interfaceiter_t *iter,
479 REQUIRE(iter->result == ISC_R_SUCCESS);
480 memmove(ifdata, &iter->current, sizeof(*ifdata));
485 isc_interfaceiter_first(isc_interfaceiter_t *iter) {
487 REQUIRE(VALID_IFITER(iter));
489 if (iter->buf6 != NULL) {
490 iter->pos6 = iter->buf6->iAddressCount;
491 iter->v6loop = ISC_FALSE;
492 iter->pos6zero = ISC_TF(iter->pos6 == 0U);
494 iter->result = ISC_R_SUCCESS;
495 return (isc_interfaceiter_next(iter));
499 isc_interfaceiter_next(isc_interfaceiter_t *iter) {
502 REQUIRE(VALID_IFITER(iter));
503 REQUIRE(iter->result == ISC_R_SUCCESS);
506 result = internal_next(iter);
508 result = internal_next6(iter);
511 result = internal_current6(iter);
517 result = internal_current(iter);
521 iter->result = result;
527 isc_interfaceiter_t *iter;
529 iter = *iterp;
530 REQUIRE(VALID_IFITER(iter));
532 if (iter->buf4 != NULL)
533 isc_mem_put(iter->mctx, iter->buf4, iter->buf4size);
534 if (iter->buf6 != NULL)
535 isc_mem_put(iter->mctx, iter->buf6, iter->buf6size);
537 iter->magic = 0;
538 isc_mem_put(iter->mctx, iter, sizeof(*iter));