4 * Copyright (C) 2001, 2002 by
5 * Jeffrey Fulmer <jdfulmer@armstrong.com>
6 * This file is part of LIBPING
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #endif/*HAVE_CONFIG_H*/
36 #ifdef HAVE_SYS_TIMES_H
37 # include <sys/times.h>
38 #endif /*HAVE_SYS_TIMES_H*/
39 #if TIME_WITH_SYS_TIME
40 # include <sys/time.h>
44 # include <sys/time.h>
48 #endif /*TIME_WITH_SYS_TIME*/
57 int send_cmd( CONN *C, char *cmd, char *val );
65 struct timeval mytime;
67 C = (CONN*)xmalloc( sizeof( CONN ));
69 C->timeout = ( P->timeout == 0 )?60:P->timeout;
71 if(( C->sock = JOEsocket( C, P->hostname )) <= 0 ){
75 /* set the rrt timer */
76 (void) gettimeofday( &mytime, (struct timezone *)NULL);
78 if(( ret = JOEreadline( C, buf, MSGBUF )) < 0 ){
81 if( !strncmp( buf, "+OK", 3 )) ret = 1;
83 if(( ret = send_cmd( C, "QUIT", NULL )) < 0 ){
88 P->rtt = elapsed_time( &mytime );
94 send_cmd( CONN *C, char *cmd, char *val )
100 snprintf( buf, sizeof( buf ), "%s %s\r\n", cmd, val );
102 snprintf( buf, sizeof( buf ), "%s\r\n", cmd );
104 if( JOEsocket_write( C, buf, sizeof( buf )) < 0 )
107 JOEreadline( C, rec, MSGBUF );
110 if( !strncmp( rec, "-ERR", 4 )){
118 pingpop3( const char *hostname )
122 P = (POP3DATA*)xmalloc( sizeof( POP3DATA ));
123 P->hostname = (char*)strdup( hostname );
130 pingtpop3( const char *hostname, int t )
135 P = (POP3DATA*)xmalloc( sizeof( POP3DATA ));
136 P->hostname = (char*)strdup( hostname );
145 tpingpop3( const char *hostname )
150 P = (POP3DATA*)xmalloc( sizeof( POP3DATA ));
151 P->hostname = (char*)strdup( hostname );
156 if( ret > 0 ){ return P->rtt; }
161 tpingtpop3( const char *hostname, int t )
166 P = (POP3DATA*)xmalloc( sizeof( POP3DATA ));
167 P->hostname = (char*)strdup( hostname );
172 if( ret > 0 ){ return P->rtt; }