static int irda_discover_device(struct gn_statemachine *state) { struct irda_device_list *list; struct irda_device_info *dev; unsigned char *buf; int s, len, i, daddr = -1, fd; double t1, t2; fd = socket(AF_IRDA, SOCK_STREAM, 0); len = sizeof(*list) + sizeof(*dev) * MAX_DEVICES; buf = malloc(len); list = (struct irda_device_list *)buf; dev = list->dev; t1 = d_time(); dprintf("Expecting: %s\n", state->config.irda_string); do { s = len; memset(buf, 0, s); if (getsockopt(fd, SOL_IRLMP, IRLMP_ENUMDEVICES, buf, (socklen_t *)&s) == 0) { for (i = 0; (i < list->len) && (daddr == -1); i++) { if (strlen(state->config.irda_string) == 0) { /* We take first entry */ daddr = dev[i].daddr; dprintf("Default: %s\t%x\n", dev[i].info, dev[i].daddr); } else { if (strncmp(dev[i].info, state->config.irda_string, INFO_LEN) == 0) { daddr = dev[i].daddr; dprintf("Matching: %s\t%x\n", dev[i].info, dev[i].daddr); } else { dprintf("Not matching: %s\t%x\n", dev[i].info, dev[i].daddr); } } } } if (daddr == -1) { d_sleep(DISCOVERY_SLEEP); } t2 = d_time(); } while ((t2 - t1 < DISCOVERY_TIMEOUT) && (daddr == -1)); free(buf); close(fd); return daddr; }
VAL operator *() { return d_w->*d_time();};