short SCTP_setPrimary(unsigned int associationID, short path_id) { int result; if ((result = sctp_setPrimary(associationID, path_id)) != 0) { if (result == SCTP_LIBRARY_NOT_INITIALIZED) { fprintf(stderr, "sctp_setPrimary: library not initialized.\n"); } else if (result == SCTP_ASSOC_NOT_FOUND) { fprintf(stderr, "sctp_setPrimary: association not found.\n"); } else if (result == SCTP_MODULE_NOT_FOUND) { fprintf(stderr, "sctp_setPrimary: internal error.\n"); } else if (result == SCTP_UNSPECIFIED_ERROR) { fprintf(stderr, "sctp_setPrimary: internal error (data structure not yet allocated).\n"); } else if (result == SCTP_PARAMETER_PROBLEM) { fprintf(stderr, "sctp_setPrimary: Path Id invalid.\n"); } else if (result == SCTP_SPECIFIC_FUNCTION_ERROR) { fprintf(stderr, "sctp_setPrimary: association is not in state established, or primary path inactive\n"); } fflush(stderr); } return result; }
void networkStatusChangeNotif(unsigned int assocID, short destAddrIndex, unsigned short newState, void* ulpDataPtr) { SCTP_AssociationStatus assocStatus; SCTP_PathStatus pathStatus; unsigned short pathID; if (verbose) { sprintf(tstr, "%-8x: Network status change: path %u is now %s\n", assocID, destAddrIndex, ((newState == SCTP_PATH_OK) ? "ACTIVE" : "INACTIVE")); waddstr(statusWin,tstr); wrefresh(statusWin); } /* if the primary path has become inactive */ if ((newState == SCTP_PATH_UNREACHABLE) && (destAddrIndex == sctp_getPrimary(assocID))) { /* select a new one */ sctp_getAssocStatus(assocID, &assocStatus); for (pathID=0; pathID < assocStatus.numberOfAddresses; pathID++){ sctp_getPathStatus(assocID, pathID, &pathStatus); if (pathStatus.state == SCTP_PATH_OK) break; } /* and use it */ if (pathID < assocStatus.numberOfAddresses) { sctp_setPrimary(assocID, pathID); getDestinationIPaddr((char *)peeraddr); } } }
void networkStatusChangeNotif(unsigned int assocID, short destAddrIndex, unsigned short newState, void* ulpDataPtr) { SCTP_AssociationStatus assocStatus; SCTP_PathStatus pathStatus; unsigned short pathID; sctp_getPathStatus(assocID, destAddrIndex , &pathStatus); sprintf(statusInfo, " Association ID =%-8x: Network status change: path %u (towards %s) is now %s\n", assocID, destAddrIndex, pathStatus.destinationAddress, pathStateName(newState)); waddstr(statusWin,statusInfo); wrefresh(statusWin); /* if the primary path has become inactive */ if ((newState == SCTP_PATH_UNREACHABLE) && (destAddrIndex == sctp_getPrimary(assocID))) { sctp_getAssocStatus(assocID, &assocStatus); for (pathID=0; pathID < assocStatus.numberOfAddresses; pathID++) { sctp_getPathStatus(assocID, pathID, &pathStatus); if (pathStatus.state == SCTP_PATH_OK) { break; } } /* and use it */ if (pathID < assocStatus.numberOfAddresses) { sctp_setPrimary(assocID, pathID); } } /* Display functions */ ncurses_display_AssocStatus(assocID); displayPathDetails = 0; ncurses_display_PathStatus(assocID); }