Added upstream from http://ftp.icm.edu.pl/pub/loglan/
[loglan.git] / sources / int / net / ip / time.c
1 #include "sock.h"
2
3 char m[100];
4 int sock;
5
6 char *host;
7
8
9 #ifndef NO_PROTOTYPES
10 int main(int argc,char **argv);
11 #endif
12
13 static int bytes_received=0;
14 static char title[100];
15
16
17 static void usage(s) char *s;{
18    printf("usage: %s host\n",s);
19    exit(0);
20 }
21
22
23 static int do_rs( socket_type, protocol, host, service )
24    int socket_type;
25    char *host,*service,*protocol;
26 {
27    int size=0;
28    int sock = sock_open( socket_type, protocol, host, service, 0, AS_CLIENT );
29    if( sock>=0 ){
30       if( !sock_cli_send( sock, m, 1 ) ){
31          size=sock_cli_recv(sock,m,sizeof(m));
32          if( size>=0 )
33             printf("packet size %d\n",size);
34       }
35       close( sock );
36    }
37    return ( size > 0 );
38 }
39
40
41 int main(argc,argv) int argc; char** argv; {
42
43    int  size;
44
45    if( argc != 2 )  usage(argv[0]);
46    host = argv[1];
47    printf("ask for time on %s\n",host);
48
49    set_cli_recv_timeout( 5000 );
50
51    if( do_rs( SOCK_DGRAM, "udp", host, "time" ) )
52       printf("time on %s is %u s\n",host,ntohl(*(int *)m));
53
54    if( do_rs( SOCK_DGRAM, "udp", host, "daytime" ) )
55       printf("daytime on %s is %s\n",host,m);
56
57    if( do_rs( SOCK_STREAM, "tcp", host, "time" ) )
58       printf("time on %s is %u s\n",host,ntohl(*(int *)m));
59
60    if( do_rs( SOCK_STREAM, "tcp", host, "daytime" ) )
61       printf("daytime on %s is %s\n",host,m);
62
63    if( do_rs( SOCK_STREAM, "tcp", host, "ntp" ) )
64       printf("daytime on %s is %s\n",host,m);
65
66    return 0;
67 }
68