Esempio n. 1
0
/*
 * sip_config_get_nat_ipaddr()
 *
 * Get the nat IP address.
 * Note: the IP Address is returned in the non-Telecaster
 *       SIP format, which is not byte reversed.
 *       Eg. 0xac2c33f8 = 161.44.51.248
 */
void
sip_config_get_nat_ipaddr (cpr_ip_addr_t *ip_addr)
{
    cpr_ip_addr_t IPAddress;
    char address[MAX_IPADDR_STR_LEN];
    int dnsErrorCode = 1;

    if (redirected_nat_ipaddr.type == CPR_IP_ADDR_INVALID) {
        config_get_string(CFGID_NAT_ADDRESS, address, sizeof(address));
        if ((cpr_strcasecmp(address, UNPROVISIONED) != 0) && (address[0] != 0)) {
            dnsErrorCode = dnsGetHostByName(address, &IPAddress, 100, 1);
        }

        if (dnsErrorCode == 0) {
            util_ntohl(ip_addr, &IPAddress);
            return ;
        } else {
            /*
             * If the NAT address is not provisioned or
             * unavailable, return the local address instead.
             */
            sip_config_get_net_device_ipaddr(ip_addr);
            return;
        }
    } else {
        *ip_addr = redirected_nat_ipaddr;
        return ;
    }

}
Esempio n. 2
0
/*
 * sip_config_get_net_device_ipaddr()
 *
 * Get the device IP address.
 * Note: the IP Address is returned in the non-Telecaster
 *       SIP format, which is not byte reversed.
 *
 */
void
sip_config_get_net_ipv6_device_ipaddr (cpr_ip_addr_t *ip_addr)
{
    cpr_ip_addr_t ip_addr1 = {0,{0}};

    platform_get_ipv6_address(&ip_addr1);
    util_ntohl(ip_addr, &ip_addr1);
}
static int
ip_fprint(FILE * const fp,
          const struct sockaddr_storage * const client_addr,
          const size_t client_addr_len)
{
    if (client_addr->ss_family == AF_INET) {
        struct sockaddr_in in;
        uint32_t           a;

        memcpy(&in, client_addr, sizeof in);
        a = (uint32_t) in.sin_addr.s_addr;
        util_ntohl(&a);
        fprintf(fp, "%u.%u.%u.%u",
                (a >> 24) & 0xff, (a >> 16) & 0xff,
                (a >> 8) & 0xff, a  & 0xff);
    } else if (client_addr->ss_family == AF_INET6) {
Esempio n. 4
0
void ccsip_dump_recv_msg_info (sipMessage_t *pSIPMessage,
                               cpr_ip_addr_t *cc_remote_ipaddr,
                               uint16_t cc_remote_port)
{
    char *disp_buf;
    const char *req_uri;
    const char *cseq;
    const char *callid;
    char ipaddr_str[MAX_IPADDR_STR_LEN];
    cpr_ip_addr_t cc_ipaddr;
    static const char fname[] = "ccsip_dump_recv_msg_info";

    util_ntohl(&cc_ipaddr, cc_remote_ipaddr);
    ipaddr2dotted(ipaddr_str, &cc_ipaddr);

    req_uri = sippmh_get_cached_header_val(pSIPMessage, FROM);
    if (req_uri == NULL) {
        /* No REQ URI, fill with blank */
        req_uri = "";
    }
    cseq = sippmh_get_cached_header_val(pSIPMessage, CSEQ);
    if (cseq == NULL) {
        /* No REQ CSEQ, fill with blank */
        cseq = "";
    }
    callid = sippmh_get_cached_header_val(pSIPMessage, CALLID);
    if (callid == NULL) {
        /* No REQ CSEQ, fill with blank */
        callid = "";
    }

    if (!dump_reg_msg) {
       if (strstr(cseq, SIP_METHOD_REGISTER) != NULL) {
          return;
       }
    }

    /* For messages starting with SIP add 8 byte. default
     * debugs do not show all the SIP message information
     * rather show initial msg.
     */
    if (pSIPMessage->mesg_line != NULL) {
        if (pSIPMessage->mesg_line[0] == 'S' &&
            pSIPMessage->mesg_line[1] == 'I' &&
            pSIPMessage->mesg_line[2] == 'P') {
            disp_buf = &(pSIPMessage->mesg_line[8]);
        } else {
            disp_buf = pSIPMessage->mesg_line;
        }
    } else {
        /*
         * It is possible that this function is called with
         * invalid message or partially received.
         */
        disp_buf = NULL;
    }

    if (disp_buf != NULL) {
        DEF_DEBUG(DEB_F_PREFIX"<%s:%-4d>:%c%c%c%c%c%c%c: %-10s :%-6s::%s\n",
                    DEB_F_PREFIX_ARGS(SIP_MSG_RECV, fname),
                    ipaddr_str, cc_remote_port,
                    disp_buf[0],
                    disp_buf[1],
                    disp_buf[2],
                    disp_buf[3],
                    disp_buf[4],
                    disp_buf[5],
                    disp_buf[6],
                    req_uri,
                    cseq, callid);
    } else {
        /* No line received */
        DEF_DEBUG(DEB_F_PREFIX"<%s:%-4d>: empty message\n",
                  DEB_F_PREFIX_ARGS(SIP_MSG_RECV, fname),
                  ipaddr_str, cc_remote_port);
    }
}
Esempio n. 5
0
uint8_t dhcp_read_packet(uint8_t sockid)
{
//    uint16_t start_time = 0;
    uint8_t type = 0;

    net_size_t data_len = -1;
    do {
        if (data_len >= 0) // That means the packet was rejected by the while
        {
            udp_tx_flush(sockid);
        }
        data_len = udp_rx_available(sockid);
    } while (data_len < DHCP_OPTIONS_OFFSET); // Minimum dhcp message
    
#if DHCP_USE_MALLOC
    struct dhcp_header *header = malloc(sizeof(struct dhcp_header));
#else
    struct dhcp_header _header;
    struct dhcp_header *header = &_header;
#endif

    udp_rx_read(sockid, 0, sizeof(struct dhcp_header), (uint8_t *)header);

    uint8_t hwaddr[6];
    w5100_get_hwaddr(hwaddr);

    if (header->op == DHCP_OP_REPLY 
        && util_ntohl(header->xid) == dhcp_xid
        && memcmp(header->chaddr,hwaddr, 6) == 0)
    {
        type = 0xff;
        w5100_set_ipaddr(header->yiaddr);
        net_size_t option_len = data_len - DHCP_OPTIONS_OFFSET;
        uint8_t *buffer = malloc(option_len);
        udp_rx_read(sockid, DHCP_OPTIONS_OFFSET, option_len, buffer);

        uint8_t *p = buffer;
        uint8_t *e = p + option_len;

        
        while (p < e)
        {
            switch (p[0])
            {
            case DHCP_END:
                p = e; // End the loop
                break;
            case DHCP_MSGTYPE:
                type = p[2];
                break;
            case DHCP_SUBNET:
                w5100_set_subnet(p + 2);
                break;
            case DHCP_ROUTER:
                w5100_set_gateway(p + 2);
                break;
            case DHCP_SERVER_ID:
                memcpy(dhcp_server, p + 2, 4);
                break;
            default:
               break;
            }
            
            if (p[0] != DHCP_END) // The end do not have a length option
                p += p[1] + 2;
        }

        free(buffer);
    }
#if DHCP_USE_MALLOC
    free(header);
#endif
    udp_rx_flush(sockid);
    return type;
}