• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: TCP connection count
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: TCP connection count


  • Subject: Re: TCP connection count
  • From: Eyal Redler <email@hidden>
  • Date: Sun, 14 Oct 2007 12:07:28 +0200


You can count TCP connections using Sysctl to get a list of
TCP connection control blocks using MIB name CTL_NET, AF_INET,
IPPROTO_TCP, TCPCTL_PCBLIST.  You can read more about this in
Steven's UNIX Network Programming.  I use this in the Connection
List tool in IPNetMonitorX.

Thanks for the answer, Peter, I don't have Steven's book (I guess I should order it) and I'm having a little difficulty walking the data structure I'm getting back when calling sysctl using this mib name.
Based on some source code I found over the net, I managed to figure out the following code but I'm pretty sure I need to filter some of the tcpcb's according to the xt_tp.t_state field, unfortunately, I have no idea what are the possible states. I'm also really not sure about the actual iteration, does this structure end with a dummy element?


unsigned long CountTCPConnections()
{
	unsigned long numberOfPcb=0;
	size_t paramSize;
	void* buff;
	int mib[4]={CTL_NET, PF_INET,IPPROTO_TCP, TCPCTL_PCBLIST};

	if (sysctl(mib, 4, NULL, &paramSize, NULL, 0)==-1)
		return 0;
	buff=malloc(paramSize);
	if (sysctl(mib, 4, buff, &paramSize, NULL, 0)==-1)
	{
		free(buff);
		return 0;
	}
	struct xinpgen *xig;
	xtcpcb* pcp;

	xig = ( xinpgen *) buff;
    	pcp = (xtcpcb*)(((char *) xig + xig->xig_len));
	while (pcp->xt_len > sizeof(xinpgen))
	{
	numberOfPcb++;
	pcp=(xtcpcb*)(((char*)pcp)+pcp->xt_len);
	}



	free(buff);
	return numberOfPcb;
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: TCP connection count
      • From: "Peter Sichel" <email@hidden>
References: 
 >TCP connection count (From: Eyal Redler <email@hidden>)
 >Re: TCP connection count (From: "Peter Sichel" <email@hidden>)
 >Re: TCP connection count (From: Eyal Redler <email@hidden>)
 >Re: TCP connection count (From: "Peter Sichel" <email@hidden>)

  • Prev by Date: Re: TCP connection count
  • Next by Date: Re: TCP connection count
  • Previous by thread: Re: TCP connection count
  • Next by thread: Re: TCP connection count
  • Index(es):
    • Date
    • Thread