Exemplo n.º 1
0
void
overseer::fetch_apps_info(const inetv4_endpoints_t& endpoints,
						  int timeout)
{
	connect(endpoints);
	send_requests(endpoints);

	progress_timer t;
	int tmp_timeout = timeout;
	double elapsed = 0.0;

	while (elapsed < (timeout / 1000.0)) {
		tmp_timeout = timeout - (elapsed * 1000);

		if (tmp_timeout < 0) {
			tmp_timeout = 0;
		}

		if (receive_responces(endpoints, tmp_timeout)) {
			break;
		}

		elapsed = t.elapsed().as_double();
	}
}
Exemplo n.º 2
0
forensic1394_result platform_send_requests(forensic1394_dev *dev,
                                           request_type type,
                                           const forensic1394_req *req,
                                           size_t nreq)
{
    // Determine the maximum number of commands we can use
    int nmaxcmd = (type == REQUEST_TYPE_READ) ? FORENSIC1394_NUM_READ_CMD
                                              : FORENSIC1394_NUM_WRITE_CMD;
    int ncmd = (nreq > nmaxcmd) ? nmaxcmd : nreq;

    // Dispatch to the internal send_requests method
    return send_requests(dev, type, req, nreq, ncmd);
}
Exemplo n.º 3
0
static void send_request_to_all(Transaction *trans,
        void (*callback)(void *), void *env)
{
    List *requests = cons(trans, NULL);
    int i;

    for (i = 1; i < storage_server_count; i++) {
        Transaction *newtrans =
            trans_new(storage_servers[i], NULL, message_new());

        /* copy the whole mess over */
        memcpy(newtrans->out, trans->out, sizeof(Message));

        /* for tswrite, we need to copy the data payload as well */
        if (newtrans->out->raw != NULL) {
            struct Tswrite *req = &newtrans->out->msg.tswrite;

            assert(trans->out->id == TSWRITE);

            newtrans->out->raw = raw_new();
            req->data = newtrans->out->raw + TWRITE_DATA_OFFSET;
            memcpy(req->data, trans->out->raw + TWRITE_DATA_OFFSET, req->count);
        }

        requests = cons(newtrans, requests);
    }

    /* send request to all storage servers and wait for all to respond */
    send_requests(requests, callback, env);

    /* make sure they all succeeded */
    while (!null(requests)) {
        trans = car(requests);
        assert(trans->in != NULL && trans->in->id == trans->out->id + 1);
        requests = cdr(requests);
    }
}
Exemplo n.º 4
0
Arquivo: inarpd.c Projeto: ago/inarp
int main(int argc, char *argv[])
{
	int sock, devs = 0, ok, i;
	time_t last_xmit;
	device *dev;

	parse_args(argc, argv);

	read_ifaces();

	ok = 1;
	while(ifnum > 0) {
		if (add_iface(iflist[0], add_rt))
			ok = 0;
		else
			devs = 1;

		iflist++;
		ifnum--;
	}

	if (!ok)
		exit(1);

	if (!devs) {
		dev = first;
		while (dev) {
			dev->active = 1;
			dev->add_route = add_rt;
			dev = dev->next;
		}
	}

	dev = first;
	ok = 0;
	if (!dev) {
		error("inarpd: no network interfaces found\n");
		exit(1);
	}

	do {
		int ip4_cnt = 0, ip6_cnt = 0, peer = 0;

		if (!dev->active)
			continue;

		if (dev->has_name != 1) {
			error("Device %s has no name\n", dev->name);
			dev->active = 0;
			continue;
		}
		if ((dev->flags & IFF_POINTOPOINT) == 0) {
			if (verbose > 0 || devs)
				printf("Device %s is not point-to-point\n",
				       dev->name);
			dev->active = 0;
			continue;
		}
		if (dev->has_addr != 1) {
			if (verbose > 0 || devs)
				printf("Device %s has no hw address\n",
				       dev->name);
			dev->active = 0;
			continue;
		}
		if (dev->has_bcast != 1) {
			if (verbose > 0 || devs)
				printf("Device %s has no peer hw address\n",
				       dev->name);
			dev->active = 0;
			continue;
		}
		if (dev->ip_cnt == 0) {
			if (verbose > 0 || devs)
				printf("Device %s has no IP address\n",
				       dev->name);
			dev->active = 0;
			continue;
		}

		ok = 1;

		if (dev->type == ARPHRD_DLCI)
			memset(dev->addr, 0, dev->addr_len);

		if (!dev->add_route)
		continue;

		for (i = 0; (unsigned) i < dev->ip_cnt; i++) {
			if (dev->ip[i].family == AF_INET) {
				if (memcmp(dev->ip[i].addr, dev->ip[i].peer,
					   IP_ADDR_LEN) ||
				    dev->ip[i].bits != IP_ADDR_LEN * 8)
					peer = 1;
				ip4_cnt++;
			}
			if (dev->ip[i].family == AF_INET6) {
				if (memcmp(dev->ip[i].addr, dev->ip[i].peer,
					   IP6_ADDR_LEN) ||
				    dev->ip[i].bits != IP6_ADDR_LEN * 8)
					peer = 1;
				ip6_cnt++;
			}
		}

		if (ip4_cnt > 1 || ip6_cnt > 1) {
			if (verbose > 0 || devs)
				printf("Can't automatically add routes for"
				       " device %s having more than 1 IP"
				       " address\n", dev->name);
			dev->add_route = 0;
		} else if (peer) {
			if (verbose > 0 || devs)
				printf("Can't automatically add routes for"
				       " device %s with peer address\n",
				       dev->name);
			dev->add_route = 0;
		}
	}while ((dev = dev->next) != NULL);

	if (!ok) {
		error("inarpd: no usable interfaces found\n");
		exit(1);
	}

	if (verbose > 0) {
		dev = first;
		printf("Interfaces:\n");
		do {
			if (!dev->active)
				continue;
			printf("   %s%s", dev->name,
			       dev->add_route ? "(r)" : "");

			if (verbose <= 1) {
				putchar('\n');
				continue;
			}

			if (dev->type == ARPHRD_DLCI)
				printf(" [Q922 ");
			else {
				printf(" [");
				for (i = 0; (unsigned) i < dev->addr_len; i++)
					printf("%s%02X", i == 0 ? "" : ":",
					       dev->addr[i]);
				printf("->");
			}
			for (i = 0; (unsigned) i < dev->addr_len; i++)
				printf("%s%02X", i == 0 ? "" : ":",
				       dev->bcast[i]);
			printf("]");

			for (i = 0; (unsigned) i < dev->ip_cnt; i++) {
				putchar(' ');
				print_ip(dev->ip[i].family, dev->ip[i].addr);
				printf("->");
				print_ip(dev->ip[i].family, dev->ip[i].peer);
				printf("/%u", dev->ip[i].bits);
			}
			putchar('\n');
		}while ((dev = dev->next) != NULL);
	}


	if ((sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_ARP))) == -1) {
		perror("inarpd: socket() failed");
		exit(-1);
	}

	if (fcntl(sock, F_SETFL, O_NONBLOCK) < 0)
		perror("fcntl() failed");

	last_xmit = 0;
	while(1) {
		fd_set set;
                FD_ZERO(&set);
                FD_SET(sock, &set);
		time_t now = time(NULL);
		struct timeval tm;
		arp_packet buffer;
		struct sockaddr_ll addr;
		socklen_t addr_len = sizeof(addr);

		tm.tv_sec = last_xmit + INARP_DELAY - now;
		tm.tv_usec = 0;

 		if (tm.tv_sec <= 0) {
			send_requests(sock);
			last_xmit = now;
			continue;
		}

		expire_routes();
		if (verbose > 2)
			printf("calling select()\n");
		if (select(sock + 1, &set, NULL, NULL, &tm) < 0) {
                        perror("select() failed");
			continue;
		}

                if (!FD_ISSET(sock, &set))
			continue;

		if (verbose > 2)
			printf("calling recv()\n");

		int len = recvfrom(sock, &buffer, sizeof(buffer), 0,
				   (struct sockaddr*)&addr, &addr_len);
		dev = get_device(addr.sll_ifindex, GET_DEVICE_DONT_CREATE);
		if (!dev) {
			if (verbose > 1)
				printf("received packet on unknown device\n");
			continue;
		}
		inbound_inarp(sock, dev, &buffer, len);
	}
}