Exemplo n.º 1
0
static void
idnsSendQuery(idns_query * q)
{
    int x;
    int ns;
    if (DnsSocket < 0) {
	debug(78, 1) ("idnsSendQuery: Can't send query, no DNS socket!\n");
	return;
    }
    /* XXX Select nameserver */
    assert(nns > 0);
    assert(q->lru.next == NULL);
    assert(q->lru.prev == NULL);
    ns = q->nsends % nns;
    x = comm_udp_sendto(DnsSocket,
	&nameservers[ns].S,
	sizeof(nameservers[ns].S),
	q->buf,
	q->sz);
    if (x < 0) {
	debug(50, 1) ("idnsSendQuery: FD %d: sendto: %s\n",
	    DnsSocket, xstrerror());
    } else {
	fd_bytes(DnsSocket, x, FD_WRITE);
	commSetSelect(DnsSocket, COMM_SELECT_READ, idnsRead, NULL, 0);
    }
    q->nsends++;
    q->sent_t = current_time;
    nameservers[ns].nqueries++;
    dlinkAdd(q, &q->lru, &lru_list);
    idnsTickleQueue();
}
Exemplo n.º 2
0
static void
send_announce(const ipcache_addrs * ia, void *junk)
{
    LOCAL_ARRAY(char, tbuf, 256);
    LOCAL_ARRAY(char, sndbuf, BUFSIZ);
    struct sockaddr_in S;
    char *host = Config.Announce.host;
    char *file = NULL;
    u_short port = Config.Announce.port;
    int l;
    int n;
    int fd;
    int x;
    cbdataFree(junk);
    if (ia == NULL) {
	debug(27, 1) ("send_announce: Unknown host '%s'\n", host);
	return;
    }
    debug(27, 1) ("Sending Announcement to %s\n", host);
    sndbuf[0] = '\0';
    snprintf(tbuf, 256, "cache_version SQUID/%s\n", version_string);
    strcat(sndbuf, tbuf);
    assert(Config.Sockaddr.http);
    snprintf(tbuf, 256, "Running on %s %d %d\n",
	getMyHostname(),
	(int) ntohs(Config.Sockaddr.http->s.sin_port),
	(int) Config.Port.icp);
    strcat(sndbuf, tbuf);
    if (Config.adminEmail) {
	snprintf(tbuf, 256, "cache_admin: %s\n", Config.adminEmail);
	strcat(sndbuf, tbuf);
    }
    snprintf(tbuf, 256, "generated %d [%s]\n",
	(int) squid_curtime,
	mkhttpdlogtime(&squid_curtime));
    strcat(sndbuf, tbuf);
    l = strlen(sndbuf);
    if ((file = Config.Announce.file) != NULL) {
	fd = file_open(file, O_RDONLY);
	if (fd > -1 && (n = read(fd, sndbuf + l, BUFSIZ - l - 1)) > 0) {
	    fd_bytes(fd, n, FD_READ);
	    l += n;
	    sndbuf[l] = '\0';
	    file_close(fd);
	} else {
	    debug(50, 1) ("send_announce: %s: %s\n", file, xstrerror());
	}
    }
    memset(&S, '\0', sizeof(S));
    S.sin_family = AF_INET;
    S.sin_port = htons(port);
    S.sin_addr = ia->in_addrs[0];
    assert(theOutIcpConnection > 0);
    x = comm_udp_sendto(theOutIcpConnection,
	&S, sizeof(S),
	sndbuf, strlen(sndbuf) + 1);
    if (x < 0)
	debug(27, 1) ("send_announce: FD %d: %s\n", theOutIcpConnection,
	    xstrerror());
}
Exemplo n.º 3
0
int
icpUdpSend(int fd,
    const struct sockaddr_in *to,
    icp_common_t * msg,
    log_type logcode,
    int delay)
{
    icpUdpData *queue;
    int x;
    int len;
    len = (int) ntohs(msg->length);
    debug(12, 5) ("icpUdpSend: FD %d sending %s, %d bytes to %s:%d\n",
	fd,
	icp_opcode_str[msg->opcode],
	len,
	inet_ntoa(to->sin_addr),
	ntohs(to->sin_port));
    x = comm_udp_sendto(fd, to, sizeof(*to), msg, len);
    if (x >= 0) {
	/* successfully written */
	icpLogIcp(to->sin_addr, logcode, len, (char *) (msg + 1), delay);
	icpCount(msg, SENT, (size_t) len, delay);
	safe_free(msg);
    } else if (0 == delay) {
	/* send failed, but queue it */
	queue = xcalloc(1, sizeof(icpUdpData));
	queue->address = *to;
	queue->msg = msg;
	queue->len = (int) ntohs(msg->length);
	queue->queue_time = current_time;
	queue->logcode = logcode;
	if (IcpQueueHead == NULL) {
	    IcpQueueHead = queue;
	    IcpQueueTail = queue;
	} else if (IcpQueueTail == IcpQueueHead) {
	    IcpQueueTail = queue;
	    IcpQueueHead->next = queue;
	} else {
	    IcpQueueTail->next = queue;
	    IcpQueueTail = queue;
	}
	commSetSelect(fd, COMM_SELECT_WRITE, icpUdpSendQueue, NULL, 0);
	statCounter.icp.replies_queued++;
    } else {
	/* don't queue it */
	statCounter.icp.replies_dropped++;
    }
    return x;
}