If a blocking (synchronous) query is ok, just use res_query(), and link your program with -lresolv. len = res_query(host, C_IN, T_MX, &answer, sizeof(answer));