One another thing:

456     to = &addr_pair->remote_addr.sa;
457
458     if (to != NULL && t != NULL && t->sock >= 0) {

Should be replaced with:

     if (addr_pair != NULL && t != NULL && t->sock >= 0) {
         to = &addr_pair->remote_addr.sa;