2017-11-09 21:13:42 +00:00
|
|
|
#include <cc65.h>
|
|
|
|
#include <time.h>
|
2018-02-22 21:33:47 +00:00
|
|
|
#include <fcntl.h>
|
2017-11-09 21:13:42 +00:00
|
|
|
#include <conio.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2018-02-22 21:33:47 +00:00
|
|
|
#include <unistd.h>
|
2017-11-09 21:13:42 +00:00
|
|
|
|
|
|
|
#include "../inc/ip65.h"
|
|
|
|
|
|
|
|
void error_exit(void)
|
|
|
|
{
|
|
|
|
switch (ip65_error)
|
|
|
|
{
|
|
|
|
case IP65_ERROR_DEVICE_FAILURE:
|
|
|
|
printf("- No device found\n");
|
|
|
|
break;
|
|
|
|
case IP65_ERROR_ABORTED_BY_USER:
|
|
|
|
printf("- User abort\n");
|
|
|
|
break;
|
|
|
|
case IP65_ERROR_TIMEOUT_ON_RECEIVE:
|
|
|
|
printf("- Timeout\n");
|
|
|
|
break;
|
|
|
|
case IP65_ERROR_DNS_LOOKUP_FAILED:
|
|
|
|
printf("- Lookup failed\n");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("- Error $%X\n", ip65_error);
|
|
|
|
}
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void confirm_exit(void)
|
|
|
|
{
|
2017-11-10 10:53:27 +00:00
|
|
|
printf("\nPress any key ");
|
2017-11-09 21:13:42 +00:00
|
|
|
cgetc();
|
|
|
|
}
|
|
|
|
|
|
|
|
void main(void)
|
|
|
|
{
|
|
|
|
unsigned long server, time;
|
2018-02-22 21:33:47 +00:00
|
|
|
unsigned char drv_init = DRV_INIT_DEFAULT;
|
2017-11-09 21:13:42 +00:00
|
|
|
|
|
|
|
if (doesclrscrafterexit())
|
|
|
|
{
|
|
|
|
atexit(confirm_exit);
|
|
|
|
}
|
|
|
|
|
2018-02-22 21:33:47 +00:00
|
|
|
#ifdef __APPLE2__
|
|
|
|
{
|
|
|
|
int file;
|
|
|
|
|
|
|
|
printf("\nSetting slot ");
|
|
|
|
file = open("ethernet.slot", O_RDONLY);
|
|
|
|
if (file != -1)
|
|
|
|
{
|
|
|
|
read(file, &drv_init, 1);
|
|
|
|
close(file);
|
|
|
|
drv_init &= ~'0';
|
|
|
|
}
|
|
|
|
printf("- %d\n", drv_init);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-11-10 10:53:27 +00:00
|
|
|
printf("\nInitializing ");
|
2018-02-22 21:33:47 +00:00
|
|
|
if (ip65_init(drv_init))
|
2017-11-09 21:13:42 +00:00
|
|
|
{
|
|
|
|
error_exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("- Ok\n\nObtaining IP address ");
|
|
|
|
if (dhcp_init())
|
|
|
|
{
|
|
|
|
error_exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("- Ok\n\nResolving pool.ntp.org ");
|
|
|
|
server = dns_resolve("pool.ntp.org");
|
|
|
|
if (!server)
|
|
|
|
{
|
|
|
|
error_exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("- Ok\n\nGetting UTC ");
|
|
|
|
time = sntp_get_time(server);
|
|
|
|
if (!time)
|
|
|
|
{
|
|
|
|
error_exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert time from seconds since 1900 to
|
|
|
|
// seconds since 1970 according to RFC 868.
|
|
|
|
time -= 2208988800UL;
|
|
|
|
|
|
|
|
printf("- %s", ctime(&time));
|
|
|
|
}
|