string dump_socket_status() {
    string ret = @END
        Fd    State      Mode       Local Address          Remote Address
        --  ---------  --------  ---------------------  ---------------------
        END;

    foreach (array item in socket_status()) {
        ret += sprintf("%2d  %|9s  %|8s  %-21s  %-21s\n", item[0], item[1], item[2], item[3], item[4]);
    }
Example #2
0
void
f_socket_status (void)
{
     array_t *info;
     int i;
     
     if (st_num_arg) {
	 info = socket_status(sp->u.number);
	 
	 if (!info) {
	     sp->u.number = 0;
	 } else {
	     sp->type = T_ARRAY;
	     sp->u.arr = info;
	 }
     } else {
	 info = allocate_empty_array(max_lpc_socks);
	 for (i = 0; i < max_lpc_socks; i++) {
	     info->item[i].type = T_ARRAY;
	     info->item[i].u.arr = socket_status(i);
	 }
	 push_refed_array(info);
     }
}
Example #3
0
uint8_t udp_ready(net_socket_t sockid)
{
    return socket_status(sockid) == SOCKET_STATUS_UDP;
}
Example #4
0
/*
********************************************************************************
*              MAKE DNS QUERY AND PARSE THE REPLY
*
* Description : This function makes DNS query message and parses the reply from DNS server.
* Arguments   : name - is a pointer to the domain name.
* Returns     : if succeeds : 1, fails : -1
* Note        :
********************************************************************************
*/
int DNS::query(char *name)
{
    int state;
    static uint32_t dns_wait_time = 0;
    struct dhdr dhp;
    uint8_t ip[4];
    uint16_t len, port;
    uint8_t dns_server_ip[4];
    uint8_t BUFPUB[100];

    get_local_dns(dns_server_ip);
    len = makequery(0, (uint8_t *)name, BUFPUB, MAX_DNS_BUF_SIZE);
    DNS_DBG("ÓòÃû:[%s]\r\n", name);
    DNS_DBG("ÓòÃû½âÎöÖÐ...\r\n");

    while(1)
    {
        state = socket_status(s);
        if(state == SOCK_CLOSED)
        {
            DNS_DBG("dns's socket closed!,socket: %d\r\n", s);
            DNS_DBG("openning dns's socket... !\r\n");
            if(_socket(s, Sn_MR_UDP, port, 0) == 1)
                DNS_DBG("open dns's socket seccusse!\r\n");
        }

        if(state == SOCK_UDP)
        {
            DNS_DBG("sending query cmd...\r\n");
            if(_sendto(s, BUFPUB, len, dns_server_ip, IPPORT_DOMAIN) > 0)
                DNS_DBG("send dns cmd ok!\r\n");

            if ((len = recv_available(s)) > 0)
            {
                if (len > MAX_DNS_BUF_SIZE)
                {
                    len = MAX_DNS_BUF_SIZE;
                }
                len = _recvfrom(s, BUFPUB, len, ip, &port);
                DNS_DBG("receiv dns's date ok!datelen:%d\r\n", len);
                if(parseMSG(&dhp, BUFPUB))
                {
                    _close(s);
                    DNS_DBG("query is ok!\r\n");
                    return 1;
                }
                else
                {
                    DNS_DBG("dns's date is bad!\r\n");
                    return -1;
                }
            }
            else
            {
                DNS_DBG("wait dns's date...!\r\n");
                delay_ms(1000);
                dns_wait_time++;
            }
            if(dns_wait_time >= 3)
            {
                _close(s);
                return -2;
            }
        }
    };
}
Example #5
0
static mixed read_callback(int fd, mixed data){
    debug("quitting. fd: "+fd+", "+identify(socket_status(fd)));
    debug(socket_close(fd));
    return 1;
}