예제 #1
0
void Dispatcher::apply(
        const std::string & source,
        void * buffer, size_t len) {

    Rule::Array dests = _rule.parse(source);
    Poco::Net::DatagramSocket sender;
    Poco::Logger & logger = Poco::Logger::get("TestLogger");


    for (Rule::Array::iterator it = dests.begin();
            it != dests.end(); ++it) {
        Poco::Net::SocketAddress addr(*it);
        int l = sender.sendTo(buffer, len, addr);
        assert(l == (int)len);
        logger.information("from %s to %s %d", source, addr.toString(), l);
    }


    // write to file

}
예제 #2
0
void dispatcher_handler(u_char *temp1,const struct pcap_pkthdr *header, const u_char *pkt_data)
{
    u_int i = 0;
    struct tm *ltime;
    char timestr[16];
    ip_header *ih;
    udp_header *uh;
    rtp_header *rh;
    u_int ip_len;
    u_short sport, dport;
    time_t local_tv_sec;
    
    int L2Count = 0;
    for(; L2Count < 16 ; L2Count++)
    {
        if(pkt_data[L2Count] == 0x08 && pkt_data[L2Count + 1] == 0x00)
        {
            break;
        }
    }

    /* retireve the position of the ip header */
    //ih = (ip_header *)(pkt_data + 14); //length of ethernet header 14Byte of L2
    ih = (ip_header *)(pkt_data + (L2Count + 2)); //length of ethernet header 14Byte of L2

    //printf("proto : %d\n",ih->proto);
    if (ih->proto == UDP)
    {
        static int sendCount = 0;
        //if(++sendCount > 10)
        {
            //usleep(1000);
            sendCount = 0;
        }

        /* retireve the position of the udp header */
        ip_len = (ih->ver_ihl & 0xf) * 4;
        uh = (udp_header *)((u_char*)ih + ip_len);

        int ret = 0;
        char *rtp = ((char*)ih + ip_len + 8);
        int rtp_len = ntohs(uh->len) - 8;
        rh = (rtp_header *)((u_char*)ih + ip_len + 8);
        //  视频
        {
            if (ntohs(uh->sport) == 4130 && ntohs(uh->dport) == 5002)   // DANBIN
                m_ss.sendTo(rtp, rtp_len, Poco::Net::SocketAddress("localhost", 45250));
            if (ntohs(uh->sport) == 10014 && ntohs(uh->dport) == 5002)  // FANGWEI
            //if (ntohs(uh->sport) == 10198 && ntohs(uh->dport) == 45252)  // FANGWEI u-law
                m_ss.sendTo(rtp, rtp_len, Poco::Net::SocketAddress("localhost", 45252));
            //if (ntohs(uh->sport) == 11782 && ntohs(uh->dport) == 5002)  // YILIAN
            if (ntohs(uh->sport) == 11788 && ntohs(uh->dport) == 45254)  // YILIAN
                m_ss.sendTo(rtp, rtp_len, Poco::Net::SocketAddress("localhost", 45254));
            if (ntohs(uh->sport) == 8216 && ntohs(uh->dport) == 55456)  // RTSP
                m_ss.sendTo(rtp, rtp_len, Poco::Net::SocketAddress("localhost", 45256));
            if (ntohs(uh->sport) == 15060 && ntohs(uh->dport) == 31000)  // PS
                m_ss.sendTo(rtp, rtp_len, Poco::Net::SocketAddress("localhost", 45258));
            if (ntohs(uh->sport) == 5006 && ntohs(uh->dport) == 45252)  // CHAOLIU
                m_ss.sendTo(rtp, rtp_len, Poco::Net::SocketAddress("localhost", 45260));
            if (ntohs(uh->sport) == 50170 && ntohs(uh->dport) == 45252)  // XINGWANG
                m_ss.sendTo(rtp, rtp_len, Poco::Net::SocketAddress("localhost", 45262));
			//printf("video seq = %d, udp_len=%d \n", ntohs(rh->seq), rtp_len);
        }

        // 音频
        {                
            if (ntohs(uh->sport) == 13274 && ntohs(uh->dport) == 5000)  // DANBIN
                m_ss.sendTo(rtp, rtp_len, Poco::Net::SocketAddress("localhost", 45251));
            if (ntohs(uh->sport) == 10012 && ntohs(uh->dport) == 5000)  // FANGWEI
            //if (ntohs(uh->sport) == 10196 && ntohs(uh->dport) == 45253)  // FANGWEI u-law
                m_ss.sendTo(rtp, rtp_len, Poco::Net::SocketAddress("localhost", 45253));
            //if (ntohs(uh->sport) == 11780 && ntohs(uh->dport) == 5000)  // YILIAN
            if (ntohs(uh->sport) == 11786 && ntohs(uh->dport) == 45255)  // YILIAN
                m_ss.sendTo(rtp, rtp_len, Poco::Net::SocketAddress("localhost", 45255));
            if (ntohs(uh->sport) == 5004 && ntohs(uh->dport) == 45253)  // CHAOLIU
                m_ss.sendTo(rtp, rtp_len, Poco::Net::SocketAddress("localhost", 45261));
            if (ntohs(uh->sport) == 50168 && ntohs(uh->dport) == 45253)  // XINGWANG
                m_ss.sendTo(rtp, rtp_len, Poco::Net::SocketAddress("localhost", 45263));
			//printf("audio seq = %d, udp_len=%d \n", ntohs(rh->seq), rtp_len);
		}
    }
    return;
}