4 * Copyright (C) 2001 Jeffrey Fulmer <jdfulmer@armstrong.com>
5 * This file is part of LIBPING
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #endif/*HAVE_CONFIG_H*/
35 #ifdef HAVE_SYS_TIMES_H
36 # include <sys/times.h>
37 #endif /*HAVE_SYS_TIMES_H*/
38 #if TIME_WITH_SYS_TIME
39 # include <sys/time.h>
43 # include <sys/time.h>
47 #endif /*TIME_WITH_SYS_TIME*/
53 int smtp_cmd( CONN *C, char *format, ... );
61 struct timeval mytime;
63 C = (CONN*)xmalloc( sizeof( CONN ));
65 C->timeout = ( S->timeout == 0 )?60:S->timeout;
67 /* set the rtt timer */
68 (void) gettimeofday( &mytime, (struct timezone *)NULL);
70 if(( C->sock=JOEsocket( C, S->hostname )) < 0 ){ JOEclose( C ); return -1; }
71 if(( ret = JOEreadline( C, buf, MSGBUF )) < 0 ){ JOEclose( C ); return ret; }
72 if(( ret = smtp_cmd( C, "%s", "HELO dude" )) < 0 ){ JOEclose( C ); return ret; }
73 if(( ret = smtp_cmd( C, "%s", "QUIT" )) < 0 ){ JOEclose( C ); return ret; }
76 S->rtt = elapsed_time( &mytime );
82 smtp_cmd( CONN *C, char *format, ... )
89 bzero( buf, sizeof( buf ));
90 bzero( rec, sizeof( rec));
92 va_start( args, format );
93 if(( vsnprintf( buf, MSGBUF-3, format, args )) < 0 ){
94 perror( "message too large" );
98 (void)strcat( buf, "\015\012" );
100 if( JOEsocket_write( C, buf, sizeof( buf )) < 0 )
103 if(( ret = JOEreadline( C, rec, MSGBUF )) <= 0 ){
109 if(( ret = atoi( rec )) > 400 ){
115 pingsmtp( const char *hostname )
119 S = (SMTPDATA*)xmalloc( sizeof( SMTPDATA ));
120 S->hostname = (char*)strdup( hostname );
127 pingtsmtp( const char *hostname, int t )
131 S = (SMTPDATA*)xmalloc( sizeof( SMTPDATA ));
132 S->hostname = (char*)strdup( hostname );
139 tpingsmtp( const char *hostname )
144 S = (SMTPDATA*)xmalloc( sizeof( SMTPDATA ));
145 S->hostname = (char*)strdup( hostname );
150 if( ret > 0 ){ return S->rtt; }
155 tpingtsmtp( const char *hostname, int t )
160 S = (SMTPDATA*)xmalloc( sizeof( SMTPDATA ));
161 S->hostname = (char*)strdup( hostname );
166 if( ret > 0 ){ return S->rtt; }