26 #define SPF_TEST_VERSION "3.0"
38 #ifdef HAVE_SYS_TYPES_H
39 #include <sys/types.h>
42 #ifdef HAVE_INTTYPES_H
49 # ifdef HAVE_STRINGS_H
54 #ifdef HAVE_ARPA_INET_H
55 # include <arpa/inet.h>
78 printf(
"Usage: spftest [spf \"<spf record>\" | domain <domain name>\n" );
79 printf(
" | ip <ip address> | exp \"<explanation string>\"\n" );
80 printf(
" | version ]\n" );
85 main(
int argc,
char *argv[] )
87 SPF_server_t *spf_server =
NULL;
88 SPF_request_t *spf_request =
NULL;
89 SPF_response_t *spf_response =
NULL;
90 SPF_record_t *spf_record =
NULL;
97 int major, minor, patch;
108 if ( strcmp( argv[1],
"version" ) == 0 ) {
109 fprintf( stderr,
"spftest version information:\n" );
110 fprintf( stderr,
"SPF test system version: %s\n",
112 fprintf( stderr,
"Compiled with SPF library version: %d.%d.%d\n",
116 fprintf( stderr,
"Running with SPF library version: %d.%d.%d\n",
117 major, minor, patch );
118 fprintf( stderr,
"\n" );
128 else if ( strcmp( argv[1],
"spf" ) == 0 )
130 else if ( strcmp( argv[1],
"domain" ) == 0 )
136 printf(
"DNS lookup for \"%s\" failed: %d\n",
137 argv[1], dns_rr->
herrno );
141 spf_rec = dns_rr->
rr[0]->
txt;
143 else if ( strcmp( argv[1],
"ip" ) == 0 )
146 ipv4.s_addr = 0x04030201;
152 printf(
"DNS lookup for \"%s\" failed: %d\n",
153 argv[1], dns_rr->
herrno );
157 spf_rec = dns_rr->
rr[0]->
txt;
163 else if ( strcmp( argv[1],
"exp" ) == 0 ) {
167 len = strlen( argv[2] );
168 spf_rec = malloc( len * 2 +
sizeof(
"v=spf1 exp-text=" ) );
170 strcpy( spf_rec,
"v=spf1 exp-text=" );
172 p = spf_rec +
sizeof(
"v=spf1 exp-text=" ) - 1;
175 while( *s !=
'\0' ) {
198 printf(
"SPF record in: %s\n", spf_rec );
200 &spf_record, spf_rec);
202 printf(
"Code is %d with %d messages, %d errors\n",
210 printf(
"%s: %s%s\n",
227 printf(
"Error: %s (null err_msg)\n",
SPF_strerror( err ) );
234 printf(
"no errors\n" );
240 if ( strcmp( argv[1],
"exp" ) == 0 )
246 SPF_set_rec_dom( spfcid,
"midwestcs.com" );
248 SPF_set_helo_dom( spfcid,
"example.com" );
249 SPF_set_ipv4_str( spfcid,
"192.0.2.3" );
250 SPF_set_env_from( spfcid,
"strong-bad@email.example.com" );
252 err = SPF_find_mod_value( spfcid, c_results.spfid, spfdcid,
"exp-text", &buf, &buf_len );
256 printf(
"err=%d buf_len = %d buf=\"%s\"\n", err, buf_len, buf );
259 if ( buf ) free( buf );