void mx_list_fill( mx_list_t* ml, const char* domain ) { stralloc mxs = { 0 }; stralloc host = { 0 }; char* current; // create the "djb-string" and look up the MX servers stralloc_copys( &host, domain ); if ( 0 != dns_mx( &mxs, &host ) ) { fprintf( stderr, "Error resolving\n" ); exit( -1 ); } // now, for each MX, we resolve the hostname current = mxs.s; while ( current < ( mxs.s + mxs.len ) ) { int weight = 255 * current[ 0 ] + current[ 1 ]; current += 2; if ( mx_debug_mode ) fprintf( stdout, "%s\t\tMX\t%-2d\t%s\n", domain, weight, current ); // we have one hostname, look that up mx_list_fill_name( ml, current ); while ( *current != 0 ) current++; current++; } }
int main () { stralloc out ={0}; stralloc sa ={0}; char ip[4]; char *dn =0; stralloc_copys(&sa, "abcdefg"); dns_ip4(&out, &sa); dns_ip4_qualify(&out, &sa, &sa); dns_name4(&out, ip); dns_mx(&out, &sa); dns_txt(&out, &sa); dns_domain_length(sa.s); dns_domain_equal(sa.s, sa.s); dns_domain_copy(&dn, sa.s); dns_domain_fromdot(&dn, sa.s, sa.len); return 0; }