[insert project logo here (125x200px max)] Navigator Mailinglists Please report any errors or ommissions you find to our `Help' mailinglist, or post a message in the Forums. Copyright and Licensing Information Snap is (c) Jonathan T. Moore, 1999-2002 and licensed under the GNU General Public License (GPL). All other parts of Splash are (c) Willem de Bruijn, 2002-2003 and licensed under the BSD Open Source License. All sourcecode is made publicly available. Acknowledgement Splash and the Splash website are hosted by SourceForge.net |
Splash - DocumentationSNMP Plus a Lightweight API for SNAP Handlingsnap_svc/snap_svc_proc.cGo to the documentation of this file.00001 /* snap service library */ 00002 /* (c) Willem de Bruijn, 2002, 2003 */ 00003 /* Licensed under the BSD License */ 00004 /* snap_svc_proc library sourcefile */ 00005 00006 /* platform includes (linux) */ 00007 #include <sys/socket.h> 00008 #include <netinet/in.h> 00009 00010 /* low-level file access functionality */ 00011 #include <fcntl.h> 00012 #include <unistd.h> 00013 00014 /* libc includes */ 00015 #include <string.h> 00016 00017 /* local includes */ 00018 #include "d_printf.h" 00019 #include "snap_svc.h" 00020 #include "snap_svc_proc.h" 00021 00022 /* library handling functions */ 00023 void snap_external_svclib_init(){ 00024 d_printf(50,"snap_svc_proc : initialized\n"); 00025 } 00026 00027 void snap_external_svclib_done(){ 00028 d_printf(50,"snap_svc_proc : closed\n"); 00029 } 00030 00031 /* there is where functions inside the library should be listed for registration */ 00032 void snap_external_svclib_getnextfunc(char** snapsvc_name, snapsvc_func_proto* snapsvc_func, int* snapsvc_args, int* snapsvc_rets){ 00033 00034 switch (svc_fun_counter){ 00035 case 0 : (*snapsvc_name) = strdup ("proc_getipforward"); 00036 (*snapsvc_func) = (snapsvc_func_proto) &proc_sysnetip_getforwarding; 00037 (*snapsvc_args) = 0; 00038 (*snapsvc_rets) = SVC_SNMP_TYPE_INT; 00039 break; 00040 case 1 : (*snapsvc_name) = strdup ("proc_setipforward"); 00041 (*snapsvc_func) = (snapsvc_func_proto) &proc_sysnetip_setforwarding; 00042 (*snapsvc_args) = 1; 00043 (*snapsvc_rets) = SVC_SNMP_TYPE_NULL; 00044 break; 00045 /* unknown handler -> return NULL as end-of-list symbol */ 00046 default : (*snapsvc_name) = NULL; 00047 (*snapsvc_func) = NULL; 00048 (*snapsvc_args) = 0; 00049 (*snapsvc_rets) = 0; 00050 } 00051 svc_fun_counter ++; 00052 } 00053 00054 /* ADD SERVICES BELOW */ 00055 /* declarations of snap service handlers */ 00056 00057 /* TO BE FILLED IN WHEN USEFUL 00058 int proc_getvalue_int(char* strProcFile){ 00059 } 00060 00061 char* proc_getvalue_string(char* strProcFile){ 00062 } 00063 00064 int proc_setvalue_int(char* strProcFile, int dValue){ 00065 } 00066 00067 int proc_setvalue_string(char* strProcFile, char* strValue){ 00068 } 00069 */ 00070 00071 /* retrieve ip forwarding info */ 00072 int proc_sysnetip_getforwarding(void* useless){ 00073 int fd; 00074 char cValue; 00075 00076 fd = open("/proc/sys/net/ipv4/ip_forward", O_RDONLY); 00077 if (fd < 0){ 00078 d_printf(10,"error >> ip_getforwarding : unable to open ip_forward..\n is the forwarding option compiled into the kernel?\n"); 00079 return -1; 00080 } 00081 00082 read (fd,&cValue,1); 00083 00084 return (cValue == '0' ? 0 : 1); 00085 } 00086 00087 /* 00088 unconditionally set forwarding 00089 (uValue is interpreted as a boolean: true or false) 00090 00091 NB: we use the /proc interface instead of sysctl, this is 00092 the preferred option since sysctl arguments may vary between system versions. 00093 */ 00094 int proc_sysnetip_setforwarding(unsigned int uValue){ 00095 int fd; 00096 00097 fd = open("/proc/sys/net/ipv4/ip_forward", O_TRUNC | O_RDWR); 00098 if (fd < 0){ 00099 d_printf(10,"error >> ip_setforwarding : unable to open ip_forward..\n is the forwarding option compiled into the kernel?\n"); 00100 return -1; 00101 } 00102 00103 write (fd,uValue ? "1" : "0", 1); 00104 00105 return (uValue ? 1 : 0); 00106 } 00107 |