/* ** File name: DAYTIMED.C ** Product: TCPware for OpenVMS ** Version: V5.6 ** Edit level: 12 ** ** Copyright (c) 2001, 2002 by ** Process Software LLC ** Framingham, Massachusetts ** ** Copyright (c) 1989-1999 by ** Process Software Corporation ** Framingham, Massachusetts ** ** This software is furnished under a license for use on a ** single computer system and may be copied only with the ** inclusion of the above copyright notice. This software, or ** any other copies thereof, may not be provided or otherwise ** made available to any other person except for use on such ** system and to one who agrees to these license terms. Title ** to and ownership of the software shall at all times remain ** in Process Software LLC's name. ** ** The information in this document is subject to change ** without notice and should not be construed as a commitment ** by Process Software LLC. Process Software LLC assumes no ** responsibility for any errors that may appear in this document. ** ** ** Abstract: ** Daytime Server ** ** ** To build on a VAX: ** $ CC /INCLUDE=TCPWARE_INCLUDE DAYTIMED.C ** $ LINK DAYTIMED,SYS$INPUT/OPTIONS ** SYS$SHARE:TCPWARE_SOCKLIB_SHR/SHARE ** SYS$SHARE:VAXCRTL/SHARE ** ** ** To build on an Alpha: ** $ CC /STANDARD=VAXC/NOMEMBER_ALIGN/ASSUME=NOALIGNED - ** /INCLUDE=TCPWARE_INCLUDE DAYTIMED.C ** $ LINK DAYTIMED,SYS$INPUT/OPTIONS ** SYS$SHARE:TCPWARE_SOCKLIB_SHR/SHARE */ #include #include #include #include #include #include "socket.h" #include "netdb.h" #include "in.h" #include "sockerr.h" #include "inet.h" /* ** Define constants */ #define ZONLEN 5 /* the length of the time zone string */ #define DATLEN 27 /* the length of the date string */ /* ** Global variables */ char time_zone [ZONLEN + 1]; /* The time zone string */ /* ** Format: ** format_date (str) ** ** Action: ** Formats the current date and time into the RFC-822 standard ** date-time format and returns it in the string passed. ** ** The string should be at least DATLEN bytes long. ** ** Return: ** none */ static format_date (str) char *str; /* out - the string to write the date and time to */ { unsigned long tim; struct tm *tm; static char *wkd[7] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }, *mon[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; /* get system date and time */ time (&tim); tm = localtime(&tim); /* format date and time */ sprintf(str, "%s %s %02d %02d:%02d:%02d %s %04d\n", wkd[tm->tm_wday], mon[tm->tm_mon], tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, time_zone, tm->tm_year+1900); } /* ** Main ** ** Action: ** Open a connection. Get the system date and time, format it and ** send it to the remote host. Then close the connection. Then do it ** all again. */ main ( ) { int sockp; /* the socket */ int status, len; char date_string[DATLEN + 1]; struct { unsigned short length; unsigned short icode; char *bufadr; unsigned short *lenadr; long end; } time_zone_itmlst = { sizeof(time_zone)-1, LNM$_STRING, time_zone, (unsigned short *)&len, 0 }; static $DESCRIPTOR (lnmsys_dsc, "LNM$SYSTEM"); #ifdef UCX_PRODUCT static $DESCRIPTOR (daytime_dsc, "UCX$TIMEZONE"); static $DESCRIPTOR (smtp_dsc, "UCX$SMTP_TIMEZONE"); #else static $DESCRIPTOR (daytime_dsc, "TCPWARE_TIMEZONE"); static $DESCRIPTOR (smtp_dsc, "TCPWARE_SMTP_TIMEZONE"); #endif status = tcpware_server(2,&sockp); if (status < 0) return; len = 0; status = SYS$TRNLNM(0,&lnmsys_dsc,&daytime_dsc,0,&time_zone_itmlst); if (!(status & 1)) status = SYS$TRNLNM(0,&lnmsys_dsc,&smtp_dsc,0,&time_zone_itmlst); if (!(status & 1)) len = 0; time_zone[len] = 0; format_date(date_string); /* send buffer */ status = socket_send(sockp,date_string,strlen(date_string),0); /* close the connection */ socket_close(sockp); }