int main (int UNUSED (argc), char *argv[]) { int chan; /* temporary channel number */ #ifdef SYSV_IPC struct msgbuf *msgp; /* message buffer */ #else int ils = -1; /* internet domain listen socket */ int uls = -1; /* unix domain listen socket */ #endif /* SYSV_IPC */ progname = argv[0]; for(chan=3; chan < _NFILE; close(chan++)) /* close unwanted channels */ ; #ifdef WIN32_NATIVE tmpdir = getenv ("TEMP"); if (!tmpdir) tmpdir = getenv ("TMP"); if (!tmpdir) tmpdir = "c:\\"; #else #ifdef USE_TMPDIR tmpdir = getenv ("TMPDIR"); #endif if (!tmpdir) tmpdir = "/tmp"; #endif /* WIN32_NATIVE */ #ifdef USE_LITOUT { /* this is to allow ^D to pass to emacs */ int d = LLITOUT; (void) ioctl(fileno(stdout), TIOCLBIS, &d); } #endif #ifdef SYSV_IPC ipc_init(&msgp); /* get a msqid to listen on, and a message buffer */ #endif /* SYSV_IPC */ #ifdef INTERNET_DOMAIN_SOCKETS ils = internet_init(); /* get an internet domain socket to listen on */ #endif /* INTERNET_DOMAIN_SOCKETS */ #ifdef UNIX_DOMAIN_SOCKETS uls = unix_init(); /* get a unix domain socket to listen on */ #endif /* UNIX_DOMAIN_SOCKETS */ while (1) { #ifdef SYSV_IPC handle_ipc_request(msgp); #else /* NOT SYSV_IPC */ fd_set rmask; FD_ZERO(&rmask); FD_SET(fileno(stdin), &rmask); if (uls >= 0) FD_SET(uls, &rmask); if (ils >= 0) FD_SET(ils, &rmask); if (select(max2(fileno(stdin),max2(uls,ils)) + 1, &rmask, (fd_set *)NULL, (fd_set *)NULL, (struct timeval *)NULL) < 0) { perror(progname); fprintf(stderr,"%s: unable to select\n",progname); return 1; } /* if */ #ifdef UNIX_DOMAIN_SOCKETS if (uls > 0 && FD_ISSET(uls, &rmask)) handle_unix_request(uls); #endif #ifdef INTERNET_DOMAIN_SOCKETS if (ils > 0 && FD_ISSET(ils, &rmask)) handle_internet_request(ils); #endif /* INTERNET_DOMAIN_SOCKETS */ if (FD_ISSET(fileno(stdin), &rmask)) /* from stdin (gnu process) */ handle_response(); #endif /* NOT SYSV_IPC */ } /* while (1) */ } /* main */
/*---------------------------------------------------------------------------*/ int main(void) { EEPROM_main(); int i; uip_ipaddr_t ipaddr; struct timer periodic_timer, arp_timer; memcpy (&uip_ethaddr.addr[0], &eeprom.MAC[0], 6); AVR_init(); egpio_init(); clock_init(); mbuf_init(); adlc_init(); GICR = (1 << INT0); timer_set(&periodic_timer, CLOCK_SECOND / 2); timer_set(&arp_timer, CLOCK_SECOND * 10); nic_init(); uip_ipaddr(ipaddr, eeprom.IPAddr[0],eeprom.IPAddr[1],eeprom.IPAddr[2],eeprom.IPAddr[3]); uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr, eeprom.Gateway[0],eeprom.Gateway[1],eeprom.Gateway[2],eeprom.Gateway[3]); uip_setdraddr(ipaddr); uip_ipaddr(ipaddr, eeprom.Subnet[0],eeprom.Subnet[1],eeprom.Subnet[2],eeprom.Subnet[3]); uip_setnetmask(ipaddr); telnetd_init(); aun_init(); internet_init(); egpio_write (EGPIO_STATUS_GREEN); while(1) { // check the econet for complete packets adlc_poller(); aun_poller (); uip_len = nic_poll(); if(uip_len > 0) { if(BUF->type == htons(UIP_ETHTYPE_IP)) { uip_arp_ipin(); uip_input(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ maybe_send(); } else if(BUF->type == htons(UIP_ETHTYPE_ARP)) { uip_arp_arpin(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { nic_send(NULL); } } } else if(timer_expired(&periodic_timer)) { timer_reset(&periodic_timer); for(i = 0; i < UIP_CONNS; i++) { uip_periodic(i); maybe_send(); } #if UIP_UDP for(i = 0; i < UIP_UDP_CONNS; i++) { uip_udp_periodic(i); maybe_send(); } #endif /* UIP_UDP */ /* Call the ARP timer function every 10 seconds. */ if(timer_expired(&arp_timer)) { timer_reset(&arp_timer); uip_arp_timer(); } } } }