Re: addding new fd in select() for recieving request

Steve Friedl <[email protected]>
Newsgroups gmane.network.net-snmp.devel,gmane.network.net-snmp.user
Message-ID <[email protected]>
On Mon, Jun 09, 2008 at 11:53:23AM +0530, [email protected] wrote:
> I am thinking of doing it in following manner.
> Please comment on the following if it is wrong

It's been a while since I have done this, but I think that the count of FDs
is not being set properly. ** NOTE INLINE

> main()
> {
>         fd_set master;
>         fd_set read_fds;
>         int listener;
>         int fdmax;			** UNUSED
>         int newfd;
> 
> 	FD_ZERO(&master); 
> 	FD_ZERO(&read_fds);
> 
>         listener = socket(AF_INET, SOCK_STREAM, 0);
>         bind(listener, (struct sockaddr *)&myaddr, sizeof(myaddr));
>         listen(listener, 10)
> 
> 	// add the listener to the master set
> 	FD_SET(listener, &master);
>         fdmax = listener;		** UNUSED
> 
>          while()
>          {

		int numfds = listener+1;	** ADD THIS

>              read_fds = master;
>              snmp_select_info(&numfds, &read_fds, NULL, 0);
>              
>              select(numfds,&read_fds,0,0,NULL)
>              if (FD_ISSET(listener , &read_fds)) 
>              {
>                  newfd = accept(listener, (struct sockaddr *)&remoteaddr,&addrlen)
>                  //function1 --->reads the data add it to queue and forward to manager as a TRAP
>              }
> 
>          }
> }

-- 
Stephen J Friedl | Security Consultant |  UNIX Wizard  |   +1 714 544-6561
www.unixwiz.net  | Tustin, Calif. USA  | Microsoft MVP | [email protected]

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.