<commit_before>/*
 * Copyright (c) 2003 Regents of The University of Michigan.
 * All Rights Reserved.  See COPYRIGHT.
 */

/*****     dip.c     *****/
#include "config.h"

#include <sys/param.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/param.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#ifdef HAVE_LIBSSL
#include <openssl/ssl.h>
#include <openssl/rand.h>
#include <openssl/err.h>
#endif /* HAVE_LIBSSL */

#include <inttypes.h>
#include <sysexits.h>
#include <netdb.h>
#include <unistd.h>
#include <strings.h>
#include <string.h>
#include <syslog.h>

#include <snet.h>

#include "queue.h"
#include "line_file.h"
#include "envelope.h"
#include "smtp.h"
#include "denser.h"
#include "bprint.h"
#include "argcargv.h"
#include "timeval.h"
#include "simta.h"
#include "mx.h"

int simta_debug = 1;
struct stab_entry	*simta_hosts = NULL;

    int
main( int argc, char *argv[])
{
    struct sockaddr_in		sin;
    DNSR			*dnsr;
    struct dnsr_result		*result;

    if ( argc != 2 ) {
	fprintf( stderr, "usage: %s hostname\n", argv[ 0 ]);
	exit( EX_USAGE );
    }

    if (( dnsr = dnsr_new( )) == NULL ) {
	syslog( LOG_ERR, "dnsr_new: %m" );
	return( SMTP_ERR_REMOTE );
    }

    if (( result = get_mx( dnsr, argv[ 1 ])) == NULL ) {
	if ( simta_debug ) fprintf( stderr, "smtp_connect: get_mx failed\n" );
	return( SMTP_ERR_REMOTE );
    }

    if ( result->r_answer[ 0 ].rr_ip == NULL ) {
	printf( "dnsr is broke\n" );
	return( 1 );
    }

    if ( result->r_answer[ 0 ].rr_type == DNSR_TYPE_MX ) {
	memcpy( &(sin.sin_addr.s_addr), &(result->r_answer[ 0 ].rr_ip->ip_ip ),
	    sizeof( struct in_addr ));
    } else {
	memcpy( &(sin.sin_addr.s_addr), &(result->r_answer[ 0 ].rr_a ),
	    sizeof( struct in_addr ));
    }

    printf( "%s\n", inet_ntoa( sin.sin_addr ));

    return( 0 );
}<commit_msg>Using only valid MX or A results.<commit_after>/*
 * Copyright (c) 2003 Regents of The University of Michigan.
 * All Rights Reserved.  See COPYRIGHT.
 */

/*****     dip.c     *****/
#include "config.h"

#include <sys/param.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/param.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#ifdef HAVE_LIBSSL
#include <openssl/ssl.h>
#include <openssl/rand.h>
#include <openssl/err.h>
#endif /* HAVE_LIBSSL */

#include <inttypes.h>
#include <sysexits.h>
#include <netdb.h>
#include <unistd.h>
#include <strings.h>
#include <string.h>
#include <syslog.h>

#include <snet.h>

#include "queue.h"
#include "line_file.h"
#include "envelope.h"
#include "smtp.h"
#include "denser.h"
#include "bprint.h"
#include "argcargv.h"
#include "timeval.h"
#include "simta.h"
#include "mx.h"

int simta_debug = 1;
struct stab_entry	*simta_hosts = NULL;

    int
main( int argc, char *argv[])
{
    int 			i, valid_result = 0;
    struct sockaddr_in		sin;
    DNSR			*dnsr;
    struct dnsr_result		*result;

    if ( argc != 2 ) {
	fprintf( stderr, "usage: %s hostname\n", argv[ 0 ]);
	exit( EX_USAGE );
    }

    if (( dnsr = dnsr_new( )) == NULL ) {
	syslog( LOG_ERR, "dnsr_new: %m" );
	return( SMTP_ERR_REMOTE );
    }

    if (( result = get_mx( dnsr, argv[ 1 ])) == NULL ) {
	if ( simta_debug ) fprintf( stderr, "smtp_connect: get_mx failed\n" );
	return( SMTP_ERR_REMOTE );
    }

    for ( i = 0; i < result->r_ancount; i++ ) {
	if ( simta_debug ) fprintf( stderr, "checking result %i:\n", i );
        if ( result->r_answer[ i ].rr_ip == NULL ) {
	    if ( simta_debug ) fprintf( stderr, "\tskipping null IP\n" );
#ifdef DEBUG
            printf( "dnsr is broke\n" );
#endif /* DEBUG */
            syslog( LOG_ERR,
                "smtp_connect: get_mx: dnsr returned illegal value" );
            return( SMTP_ERR_SYSCALL );
        }

        switch( result->r_answer[ i ].rr_type ) {
        case DNSR_TYPE_MX:
	    if ( simta_debug ) fprintf( stderr, "\tMX\n" );
	    memcpy( &(sin.sin_addr.s_addr),
		&(result->r_answer[ i ].rr_ip->ip_ip ),
		sizeof( struct in_addr ));
	    valid_result++;
            break;

        case DNSR_TYPE_A:
	    if ( simta_debug ) fprintf( stderr, "\tA\n" );
            memcpy( &(sin.sin_addr.s_addr), &(result->r_answer[ i ].rr_a ),
                sizeof( struct in_addr ));
	    valid_result++;
            break;

        default:
	    if ( simta_debug ) fprintf( stderr, "\tskipping non MX/A\n" );
            continue;
        }
	if ( valid_result ) {
	    break;
	}
    }

    printf( "%s\n", inet_ntoa( sin.sin_addr ));

    return( 0 );
}
{'fraction_non_alphanumeric': 0.17132790134331646, 'fraction_numerical': 0.005505395287381634, 'mean_word_length': 2.918895599654875, 'pattern_counts': {'":': 0, '<': 42, '<?xml version=': 0, '>': 52, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6654197', 'n_tokens_mistral': 1901, 'n_tokens_neox': 1823, 'n_words': 427}