There are two steps to accomplish what you want.
1. You need a program structure that can re-initialize the tcp/ip stack when necessary.
2. You need to be able to detect "when it is necessary".
For the first part - the Altera examples use the following structure:
alt_iniche_init();
netmain();
/* Wait for the network stack to be ready before proceeding.
* iniche_net_ready indicates that TCP/IP stack is ready, and IP address is obtained.
*/
while (!iniche_net_ready)
TK_SLEEP(1);
This code happens once during the initial task processing, and doesn't happen again. You can instead put this code in a separate task that can re-try the two function calls, and eliminates the sleep on iniche_net_ready.
With nichestack 3.1 found in the 9.x tools, netmain() is where all the action is, including talking to the PHY device to autonegotiate 10/100/1000 megabits and full or half duplex.
I don't know the specific way to query the PHY chip to see if a cable has been attached, for example, but you will find the existing PHY communication code by tracing netmain() into the Altera IP Device Drivers selected by SOPC builder for the PHY circuit in your system.
An alternative is to simply call netmain() from time to time and see if iniche_net_ready goes true after a suitable time delay. Again, the main part of the time delay will be autonegotiation if no cable is attached, because the current code does several retries before giving up, and if you have DHCP enabled, there might be a delay there too.
Hope this gives you some pointers.
Mike