/* Initialise the resolver. Open a socket and bind it to the address of the server. return -1 if something goes wrong, otherwise 0. If we are being called a second time we have to be careful to allow any ongoing lookups to finish before we close the socket and connect to a different DNS server. The danger here is that we may have to wait for upto 32 seconds if the DNS server is down. */ int cyg_dns_res_init(struct in_addr *dns_server) { struct sockaddr_in server; struct servent *sent; static int init =0; CYG_REPORT_FUNCNAMETYPE( "cyg_dns_res_init", "returning %d" ); CYG_REPORT_FUNCARG1( "dns_server=%08x", dns_server ); CYG_CHECK_DATA_PTR( dns_server, "dns_server is not a valid pointer!" ); if (init) { cyg_drv_mutex_lock(&dns_mutex); cyg_thread_free_data_index(ptdindex); if (s >= 0) { close(s); } } else { init = 1; cyg_drv_mutex_init(&dns_mutex); cyg_drv_mutex_lock(&dns_mutex); } s = socket(PF_INET, SOCK_DGRAM, 0); if (s < 0) { cyg_drv_mutex_unlock(&dns_mutex); CYG_REPORT_RETVAL( -1 ); return -1; } sent = getservbyname("domain", "udp"); if (sent == (struct servent *)0) { s = -1; cyg_drv_mutex_unlock(&dns_mutex); CYG_REPORT_RETVAL( -1 ); return -1; } memcpy((char *)&server.sin_addr, (const void *)dns_server, sizeof(server.sin_addr)); server.sin_port = sent->s_port; server.sin_family = AF_INET; server.sin_len = sizeof(server); if (connect(s, (struct sockaddr *)&server, sizeof(server)) < 0) { s = -1; cyg_drv_mutex_unlock(&dns_mutex); CYG_REPORT_RETVAL( -1 ); return -1; } ptdindex = cyg_thread_new_data_index(); cyg_drv_mutex_unlock(&dns_mutex); CYG_REPORT_RETVAL( 0 ); return 0; }
externC void cyg_drv_interrupt_unmask_intunsafe( cyg_vector_t vector ) { CYG_REPORT_FUNCTION(); CYG_REPORT_FUNCARG1("vector=%d", vector); CYG_ASSERT( vector >= CYGNUM_HAL_ISR_MIN, "Invalid vector"); CYG_ASSERT( vector <= CYGNUM_HAL_ISR_MAX, "Invalid vector"); HAL_INTERRUPT_UNMASK( vector ); CYG_REPORT_RETURN(); }
externC void cyg_drv_interrupt_unmask( cyg_vector_t vector ) { CYG_INTERRUPT_STATE old_ints; CYG_REPORT_FUNCTION(); CYG_REPORT_FUNCARG1("vector=%d", vector); CYG_ASSERT( vector >= CYGNUM_HAL_ISR_MIN, "Invalid vector"); CYG_ASSERT( vector <= CYGNUM_HAL_ISR_MAX, "Invalid vector"); HAL_DISABLE_INTERRUPTS(old_ints); HAL_INTERRUPT_UNMASK( vector ); HAL_RESTORE_INTERRUPTS(old_ints); CYG_REPORT_RETURN(); }
externC cyg_cpu_t cyg_drv_interrupt_get_cpu( cyg_vector_t vector ) { cyg_cpu_t cpu = 0; CYG_REPORT_FUNCTION(); CYG_REPORT_FUNCARG1("vector = %d", vector); CYG_ASSERT( vector >= CYGNUM_HAL_ISR_MIN, "Invalid vector"); CYG_ASSERT( vector <= CYGNUM_HAL_ISR_MAX, "Invalid vector"); #ifdef CYGPKG_HAL_SMP_SUPPORT HAL_INTERRUPT_GET_CPU( vector, cpu ); #endif CYG_REPORT_RETURN(); return cpu; }