/*==================================================================== * * BUILD INSTRUCTIONS: * * To build this example program use commands of the form, * * using the DEC "C" compiler: * * $ cc/prefix=all SYSLOGCLIENT.C * $ link SYSLOGCLIENT * * using the DEC "C++" compiler: * * $ cxx/prefix=all/define=VMS SYSLOGCLIENT.C * $ link SYSLOGCLIENT * */ /* * * INCLUDE FILES * */ #include /* VMS descriptor stuff */ #include /* Unix style error codes for IO routines. */ #include /* internet system Constants and structures. */ #include /* Network address info. */ #include /* I/O FUNCTION CODE DEFS */ #include /* LIB$ RTL-routine signatures. */ #include /* Network database library info. */ #include /* UNIX style Signal Value Definitions */ #include /* TCP/IP socket definitions. */ #include /* SS$_ sys ser return stati <8-) */ #include /* Sys ser calls */ #include /* UNIX 'Standard I/O' Definitions */ #include /* General Utilities */ #include /* String handling function definitions */ #include /* UCX network definitions */ #include /* Prototypes for UNIX emulation functions */ #include /* Logical Name Translation definitions */ /*-----------------------------------------------------------*/ cleanup(int socket) { int retval; /* * Shutdown socket completely. */ retval = shutdown(socket,2); if (retval == -1) perror ("shutdown"); /* * Close socket. */ retval = close (socket); if (retval) perror ("close"); exit( 1 ); } /* end cleanup */ get_serv_addr( void *addrptr ) { typedef struct _item_list_3 { unsigned short int buffer_length; unsigned short int item_code; char *buffer_address; unsigned short* return_length_address; } ITEM_LIST_3; struct hostent *host; struct in_addr val; ITEM_LIST_3 itmlst[2]; char logical[256]; unsigned short loglen; unsigned int attr; int status; $DESCRIPTOR(tabnam,"LNM$DCL_LOGICAL"); $DESCRIPTOR(lognam,"SYSLOG_HOST"); itmlst[0].buffer_length = sizeof(logical); itmlst[0].item_code = LNM$_STRING; itmlst[0].buffer_address = (char*)&logical; itmlst[0].return_length_address = &loglen; itmlst[1].buffer_length = 0; itmlst[1].item_code = 0; attr=LNM$M_CASE_BLIND; status = SYS$TRNLNM(&attr,&tabnam,&lognam,0,&itmlst); if ((status!=SS$_NORMAL) && (status!=SS$_NOLOGNAM)) { fprintf(stderr,"The SYSLOG_HOST logical is not defined.\n"); exit( 1 ); } if (status == SS$_NOLOGNAM) { fprintf(stderr,"The SYSLOG_HOST logical is not defined.\n"); exit( 1 ); } logical[loglen] = 0; val.s_addr = inet_addr( logical ); if ( val.s_addr != INADDR_NONE ) { memcpy( addrptr, &val, sizeof(struct in_addr) ); } if ( (host = gethostbyname(logical)) ) { memcpy( addrptr, host->h_addr, sizeof(struct in_addr) ); } } /* * Functional Description * * This example creates a socket of type SOCK_DGRAM (UDP), * binds it, and sends a message to the given host and port number. * Error messages are printed to the screen. * * IPC calls used: * bind * close * gethostbyname * sendto * shutdown * socket * * Formal Parameters * The client program expects two parameters: * hostname ... name of remote host * portnumber ... port where remote host(server) is listening * * * Routine Value * * Status */ /*--------------------------------------------------------------------*/ main( int argc, char **argv ) { int sock_1; /* Socket 1 descriptor. */ int tolen; char sendbuf[256]; static struct sockaddr_in sock2_name; /* Address struct for socket2.*/ int namelength; struct hostent hostentstruct; /* Storage for hostent data. */ struct hostent *hostentptr; /* Pointer to hostent data. */ static char hostname[256]; /* Name of local host. */ int flag; int retval; int priority; /* * Check input parameters. */ if (argc != 4 ) { printf("Usage: syslogclient facility level message.\n"); printf(" Facility Values:\n"); printf(" 0=Kernel 8=UUCP 16=Local0\n"); printf(" 1=User-Level 9=Clock 17=Local1\n"); printf(" 2=Mail System 10=Security 18=Local2\n"); printf(" 3=System Daemons 11=FTP Daemon 19=Local3\n"); printf(" 4=Security 12=NTP 20=Local4\n"); printf(" 5=Internal 13=Log Audit 21=Local5\n"); printf(" 6=Line Printer 14=Log Alert 22=Local6\n"); printf(" 7=Network News 15=Clock 23=Local7\n"); printf(" Level Values:\n"); printf(" 0=Emergency 3=Error 6=Informational\n"); printf(" 1=Alert 4=Warning 7=Debug\n"); printf(" 2=Critical 5=Notice\n"); exit( 1 ); } priority = atoi(argv[1]); if ((priority < 0) || (priority > 23)) { printf("The facility must be in the range 0..23.\n"); exit( 1 ); } priority = atoi(argv[2]); if ((priority < 0) || (priority > 7)) { printf("The level must be in the range 0..7.\n"); exit( 1 ); } priority = atoi(argv[1])*8; priority = priority + atoi(argv[2]); /* * Open socket 1: AF_INET, SOCK_DGRAM. */ if ((sock_1 = socket (AF_INET, SOCK_DGRAM, 0)) == -1) { perror( "socket"); exit( 1 ); } /* * Fill in the address structure for socket 2 (to receive message). */ sock2_name.sin_family = AF_INET; sock2_name.sin_port = htons(514); get_serv_addr( &sock2_name.sin_addr ); /* * Initialize send block. */ tolen = sizeof sock2_name; flag = 0; /* flag may be MSG_OOB */ /* * Send message from socket 1 to socket 2. */ sprintf( sendbuf, "<%d>%s", priority, argv[3] ); retval = sendto( sock_1, sendbuf, strlen(sendbuf), flag, (struct sockaddr*)&sock2_name, tolen); if (retval == -1) { perror ( "sendto"); cleanup(sock_1); } /* * Call cleanup to shutdown and close socket. */ cleanup(sock_1); } /* end main */