allow coexistance of N build and AC build.
[tomato.git] / release / src / router / rc / snmp.c
blobf5d9ef4a7af5b01b681dfd614ee4793538895461
1 /*
2 * snmp.c
4 * Copyright (C) 2011 shibby
6 */
7 #include <rc.h>
8 #include <sys/stat.h>
10 void start_snmp(void)
12 FILE *fp;
14 // only if enable...
15 if( nvram_match( "snmp_enable", "1" ) )
18 // writing data to file
19 if( !( fp = fopen( "/etc/snmpd.conf", "w" ) ) )
21 perror( "/etc/snmpd.conf" );
22 return;
24 fprintf(fp, "agentaddress udp:%d\n", nvram_get_int( "snmp_port" ) );
25 fprintf(fp, "syslocation %s\n", nvram_safe_get( "snmp_location" ) );
26 fprintf(fp, "syscontact %s <%s>\n", nvram_safe_get( "snmp_contact" ),nvram_safe_get( "snmp_contact" ) );
27 fprintf(fp, "rocommunity %s\n", nvram_safe_get( "snmp_ro" ) );
29 fclose( fp );
30 chmod( "/etc/snmpd.conf", 0644 );
32 xstart( "snmpd", "-c", "/etc/snmpd.conf" );
35 return;
38 void stop_snmp(void)
40 killall("snmpd", SIGTERM);
41 return;