Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
762 views
in Technique[技术] by (71.8m points)

sockets - How to List TCP/UDP Connections in iOS 4

I am interested in deriving a list of active TCP/UDP network connections on an iOS 4.3 device. Basically, I'm looking for the same type of information one gets from issuing a "netstat -anp tcp" (or the same, but with udp) command under OS X Darwin.

I've searched Apple's iOS Developer Library (especially NSNetServices, CFNetServices, and the iOS Manual Pages) and the Internet, but with no good results. Yet, there is an iOS Netstat app (see http://itunes.apple.com/us/app/netstat/id400071873?mt=8&ign-mpt=uo%3D2) out there, so it appears possible.

Thanks in advance for any useful pointers/suggestions/thoughts.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I believe I have now answered my own question. Thought I had taken a close enough look at the sysctl() library function, but I hadn't! For example, the following will yield information about the current TCP connections:

sysctlbyname("net.inet.tcp.pcblist", ...)

To get information about UDP connection, simply use a different Management Information Base (MIB) name: net.inet.udp.pcblist.

For convenience, here's a link to the appropriate iOS man page:

http://developer.apple.com/library/ios/#documentation/System/Conceptual/ManPages_iPhoneOS/man3/sysctlbyname.3.html

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...