Esempio n. 1
0
/*----------------------------------------------------------------------------*/
int main(int argc, char *argv[])
{
    ushort     port;
    uchar      nclients;
    udps_err_t rc;

    /* Check server initialization arguments. */
    if(argc != 3) {
        udps_print_usage(argv[0]);
    }

    /* Load configuration. */
    port     = atoi(argv[1]);
    nclients = atoi(argv[2]);

    /* Handle signals.
     * SIGINT  = When the user types the INTR character (normally C-c).
     * SIGTERM = Generic signal used to cause program termination. */
    signal(SIGINT, udps_signal_handler);
    signal(SIGTERM, NULL);

    /* Initialize. */
    rc = udps_init(port, nclients);
    if(rc != UDPS_OK) {
        LOG_MAIN(UDPS_LOG_EMERG, ("Unable to initialize  UDP server"));
        exit(EXIT_FAILURE);
    }

    /* Accept. */
    rc = udps_accept();
    if(rc != UDPS_OK) {
        LOG_MAIN(UDPS_LOG_EMERG, ("Unable to start accepting"));
        exit(EXIT_FAILURE);
    }

    /* Close. */
    udps_close();

    return EXIT_SUCCESS;
}
Esempio n. 2
0
int main(int argc, char** argv) {
    unsigned char flags = 0;
    init_cpu();
    hw_init_flags();
    hw_write_flags(0);
    link_init();
    
    POINTER c = (POINTER)(ADDR_BASE_XIL + 0x06);
    *c = 0x100;
    UINT16 len = 0;
    
    /* IP address */
    localmachine.localip = 0xC0A80146 + flags;  /* 192.168.0.*	*/
    /* Default gateway */
    localmachine.defgw   = 0xC0A80101;  /* 192.168.0.1	*/
    /* Subnet mask */
    localmachine.netmask = 0xFFFFFF00;
    /* Ethernet (MAC) address */
    localmachine.localHW[5] = 0x00;
    localmachine.localHW[4] = 0x33;
    localmachine.localHW[3] = 0xCC;
    localmachine.localHW[2] = 0xAB;
    localmachine.localHW[1] = 0xBA;
    localmachine.localHW[0] = 0x11 + flags;

    data_port = UDP_DATA_PORT + flags;
    
    timer_pool_init();
    NE2000Init(&localmachine.localHW[0]);
    arp_init();
    udp_init();
    tcp_init();

    /* Initialize applications	*/
    tcps_init();
    udps_init();

    while(1) {
        if (NETWORK_CHECK_IF_RECEIVED() == TRUE) {
            switch( received_frame.protocol) {
                case PROTOCOL_ARP:
                    process_arp(&received_frame);	
                    break;

                case PROTOCOL_IP:
                    len = process_ip_in(&received_frame);
                    if(len < 0) 
                    break;
                    
                switch(received_ip_packet.protocol){
                    case IP_ICMP:
                        process_icmp_in (&received_ip_packet, len);
                        break;

                    case IP_UDP:
                        process_udp_in (&received_ip_packet,len);
                        break;

                    case IP_TCP:
                        process_tcp_in (&received_ip_packet, len);				
                        break;
                }

                break;
            }

        /* discard received frame */    		
        NETWORK_RECEIVE_END();
    }

        /* Application main loops */
        /* Do not forget this!!! These don't get invoked magically :-) */
    	tcps_run();
        udps_run();
        /* manage arp cache tables */
        arp_manage();
        /* manage opened TCP connections (retransmissions, timeouts,...)*/
        tcp_poll();
    }
    return (EXIT_SUCCESS);
}