int snmp_synch_input(int Operation, struct snmp_session *Session, int RequestID, struct snmp_pdu *pdu, void *magic) { struct variable_list *var; struct synch_state *state = (struct synch_state *)magic; struct snmp_pdu *newpdu; struct variable_list *varPtr; #ifdef DEBUG_CLIENT printf("CLIENT %x: Synchronizing input.\n", (unsigned int)pdu); #endif /* Make sure this is the proper request */ if (RequestID != state->reqid) return 0; state->waiting = 0; /* Did we receive a Get Response */ if (Operation == RECEIVED_MESSAGE && pdu->command == SNMP_PDU_RESPONSE) { /* clone the pdu */ state->pdu = newpdu = snmp_pdu_clone(pdu); newpdu->variables = 0; /* Clone all variables */ var = pdu->variables; if (var != NULL) { newpdu->variables = snmp_var_clone(var); varPtr = newpdu->variables; /* While there are more variables */ while(var->next_variable) { /* Clone the next one */ varPtr->next_variable = snmp_var_clone(var->next_variable); /* And move on */ var = var->next_variable; varPtr = varPtr->next_variable; } varPtr->next_variable = NULL; } state->status = STAT_SUCCESS; snmp_errno = 0; /* XX all OK when msg received ? */ Session->s_snmp_errno = 0; } else if (Operation == TIMED_OUT) { state->pdu = NULL; /* XX from other lib ? */ state->status = STAT_TIMEOUT; snmp_errno = SNMPERR_NO_RESPONSE; Session->s_snmp_errno = SNMPERR_NO_RESPONSE; } return 1; }
struct snmp_pdu *snmp_fix_pdu(struct snmp_pdu *pdu, int command) { struct variable_list *var, *newvar; struct snmp_pdu *newpdu; int index; int copied = 0; #ifdef DEBUG_PDU printf("PDU %x: Fixing. Err index is %d\n", (unsigned int)pdu, (unsigned int)pdu->errindex); #endif if (pdu->command != SNMP_PDU_RESPONSE || pdu->errstat == SNMP_ERR_NOERROR || pdu->errindex <= 0) { snmp_set_api_error(SNMPERR_UNABLE_TO_FIX); return(NULL); } /* clone the pdu */ newpdu = snmp_pdu_clone(pdu); if (newpdu == NULL) return(NULL); newpdu->variables = 0; newpdu->command = command; newpdu->reqid = SNMP_DEFAULT_REQID; newpdu->errstat = SNMP_ERR_NOERROR; newpdu->errindex = 0; /* XXXXX Is this right? */ /* Loop through the variables, removing whatever isn't necessary */ var = pdu->variables; index = 1; /* skip first variable if necessary*/ if (pdu->errindex == index) { var = var->next_variable; index++; } if (var != NULL) { /* VAR is the first uncopied variable */ /* Clone this variable */ newpdu->variables = snmp_var_clone(var); if (newpdu->variables == NULL) { snmp_pdu_free(newpdu); return(NULL); } copied++; newvar = newpdu->variables; /* VAR has been copied to NEWVAR. */ while(var->next_variable) { /* Skip the item that was bad */ if (++index == pdu->errindex) { var = var->next_variable; continue; } /* Copy this var */ newvar->next_variable = snmp_var_clone(var->next_variable); if (newvar->next_variable == NULL) { snmp_pdu_free(newpdu); return(NULL); } /* Move to the next one */ newvar = newvar->next_variable; var = var->next_variable; copied++; } newvar->next_variable = NULL; } /* If we didn't copy anything, free the new pdu. */ if (index < pdu->errindex || copied == 0) { snmp_free_pdu(newpdu); snmp_set_api_error(SNMPERR_UNABLE_TO_FIX); return(NULL); } #ifdef DEBUG_PDU printf("PDU %x: Fixed PDU is %x\n", (unsigned int)pdu, (unsigned int)newpdu); #endif return(newpdu); }