- // If there are no MX records for the domain, resolv will give us a single one with zero length.
- // Make sure we only record actual MX records and not the blank.
- if (strlen(expanded_buf) > 0) {
- ++num_mxrecs;
- if (mxrecs == NULL) {
- mxrecs = malloc(sizeof(struct mx));
- }
- else {
- mxrecs = realloc(mxrecs, (sizeof(struct mx) * num_mxrecs) );
- }
-
- mxrecs[num_mxrecs - 1].pref = pref;
- strcpy(mxrecs[num_mxrecs - 1].host, expanded_buf);
- }
+ mx.pref = pref;
+ strcpy(mx.host, expanded_buf);
+ array_append(mxrecords, &mx);