addding new fd in select() for recieving request - SNMP

This is a discussion on addding new fd in select() for recieving request - SNMP ; Hello, I have a requirement that i also need to listen for alarms coming from another application on socket and forward them to manager apart from GET/SET request from Manager Now in order to listen on socket for alarms i ...

+ Reply to Thread
Results 1 to 3 of 3

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

  1. addding new fd in select() for recieving request

    Hello,

    I have a requirement that i also need to listen for alarms coming from another application on socket and forward them to manager apart from GET/SET request from Manager

    Now in order to listen on socket for alarms i need to accept the connection but this will make it blocking. So i have to add it in select() to hear whether it is ready to be read or not and then accept connection.

    I am thinking of doing it in following manner.
    Please comment on the following if it is wrong
    This code will be main

    main()
    {
    fd_set master;
    fd_set read_fds;
    int listener;
    int fdmax;
    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;

    while()
    {
    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
    }

    }
    }


    But this does'nt seem to work , do i need to register my function1.Please help me on this


    Thanks



    -------------------------------------------------------------------------
    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
    _______________________________________________
    Net-snmp-coders mailing list
    Net-snmp-coders@lists.sourceforge.net
    https://lists.sourceforge.net/lists/...et-snmp-coders


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

    On Mon, Jun 09, 2008 at 11:53:23AM +0530, gauravmeh2004@indiatimes.com 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 | steve@unixwiz.net

    -------------------------------------------------------------------------
    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
    _______________________________________________
    Net-snmp-coders mailing list
    Net-snmp-coders@lists.sourceforge.net
    https://lists.sourceforge.net/lists/...et-snmp-coders


  3. Re: Writing MIB objects Values in files

    [Please send your request to the mailing list
    net-snmp-users@lists.sourceforge.net
    and *not* to the request address. Thanks]

    2008/6/10 rajesh :
    > Hi Dave,
    > Thanks for ur help .
    > I am able to do GET/SET operation on the own defined mib .
    > once snmpd is down and am restarting , snmpd .
    > all the previous SET operation on mib object is lost .
    >
    > Please Suggest me how to make All the data Persistent even if the snmpd
    > is restarted .


    Use the SNMP_CALLBACK_STORE_DATA callback
    to write out the persistent values.
    These will then be read in when the agent restarts.

    Note that you will need to code "store" routine to save
    this information, and matching "parse" config handlers
    to read it in again.

    See (e.g.) mibgroup/mibII/system_mib.c for an example of
    this in action.

    Dave

    -------------------------------------------------------------------------
    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
    _______________________________________________
    Net-snmp-users mailing list
    Net-snmp-users@lists.sourceforge.net
    Please see the following page to unsubscribe or change other options:
    https://lists.sourceforge.net/lists/...net-snmp-users


+ Reply to Thread