This, like any problem you are faced with in life, requires a clear definition of the problem. And you'll need to break it down into parts.
Firstly, do you need to "discover" the topology, or do you already have it supplied in a text file somewhere? Is your requirement merely to graph the topology (in which case a program called "graphviz" will probably already do the job you require)? If you have to discover the topology, what kind of network is it? LAN? WAN? TCP/IP? Something else?
Then you have to ask yourself why you want to use C or C++ - it would appear from your question that you have not much experience with networks - thus it is not apparent why you would want to go to the trouble of using a low-level language to undertake your chosen task. Perhaps a high level language would be appropriate in the near term.
Be aware that many have faced the same challenge you have - graphing a network topology; thus there are many applications that do just this. Perhaps you could elaborate on your reasons for wanting to attempt this task yourself?