home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tolkit45.zip / os2tk45 / samples / tcpiptk / sysctl / sysctl.c < prev    next >
C/C++ Source or Header  |  1999-05-11  |  5KB  |  132 lines

  1. /*******************************copyrite.xic*********************************/
  2. /*                                                                          */
  3. /*   Licensed Materials - Property of IBM                                   */
  4. /*   IBM TCP/IP for OS/2                                                    */
  5. /*   (C) Copyright IBM Corporation. 1990,1996.                              */
  6. /*                                                                          */
  7. /*   All rights reserved.                                                   */
  8. /*                                                                          */
  9. /*   US Government Users Restricted Rights -                                */
  10. /*   Use, duplication or disclosure restricted by GSA ADP Schedule          */
  11. /*   Contract with IBM Corp.                                                */
  12. /*                                                                          */
  13. /*--------------------------------------------------------------------------*/
  14. /*  DISCLAIMER OF WARRANTIES.  The following [enclosed] code is             */
  15. /*  sample code created by IBM Corporation. This sample code is not         */
  16. /*  part of any standard or IBM product and is provided to you solely       */
  17. /*  for  the purpose of assisting you in the development of your            */
  18. /*  applications.  The code is provided "AS IS", without                    */
  19. /*  warranty of any kind.  IBM shall not be liable for any damages          */
  20. /*  arising out of your use of the sample code, even if they have been      */
  21. /*  advised of the possibility of such damages.                             */
  22. /*--------------------------------------------------------------------------*/
  23. /***************************** SYSCTL.C *************************************/
  24.  
  25. typedef unsigned long tcp_seq;
  26.  
  27. #include <stdio.h>
  28. #include <types.h>
  29. #include <netinet\in.h>
  30. #include <sys\socket.h>
  31. #include <netinet\ip_var.h>
  32. #include <netinet\tcp_var.h>
  33. #include <netinet\udp.h>
  34. #include <netinet\udp_var.h>
  35. #include <netinet\in_systm.h>
  36. #include <netinet\ip.h>
  37. #include <netinet\ip_icmp.h>
  38. #include <netinet\icmp_var.h>
  39. #include <driver.h>
  40. #include <os2.h>
  41. #include <genio.h>
  42. #include <sys\sysctl.h>
  43. #include <sys\lipcpar.h>
  44.  
  45. /* Globals */
  46. int
  47.    mib[7], i, failures=0, Success=0;
  48. unsigned int
  49.    oldenp=0, newlen=0;
  50.  
  51. int main(void)
  52. {
  53.    struct a {
  54.           int flag;
  55.           } uap_old, uap_new;
  56.  
  57.    int org;
  58.  
  59.    /* Place a sysctl call filling the mib struct */
  60.     mib[0]= CTL_NET;              //cmd
  61.     mib[1]= PF_INET;              //Protocol Family
  62.     mib[2]= IPPROTO_IP;           //Protocol
  63.     mib[3]= IPCTL_FORWARDING;     //Control command for switch(name[0]) in tcp_sysctl
  64.  
  65.     /* Check the set value */
  66.     uap_old.flag = 0;
  67.     newlen = oldenp  = sizeof(struct a);
  68.  
  69.     if (sysctl(mib,4,(void *)&uap_old,&oldenp,(void *)NULL,newlen) < 0) {
  70.          failures++;
  71.          printf ("*** ERR ::: sysctl ipforwarding. \n");
  72.     }
  73.     else {
  74.          Success++;
  75.          org = uap_old.flag;
  76.          printf ("sysctl ipforwarding value : %d\n",uap_old.flag);
  77.     }
  78.  
  79.     /* set a new to 1 */
  80.     uap_new.flag = 1;
  81.     newlen = oldenp  = sizeof(struct a);
  82.  
  83.     if (sysctl(mib,4,(void *)NULL,&oldenp,(void *)&uap_new,newlen) < 0) {
  84.          failures++;
  85.          printf ("*** ERR ::: sysctl ipforwarding. \n");
  86.     }
  87.     else {
  88.          Success++;
  89.          printf ("sysctl ipforwarding now set to : %d\n",uap_new.flag);
  90.     }
  91.  
  92.     /* Check the set value */
  93.     uap_old.flag = 0;
  94.     newlen = oldenp  = sizeof(struct a);
  95.  
  96.     if (sysctl(mib,4,(void *)&uap_old,&oldenp,(void *)NULL,newlen) < 0) {
  97.          failures++;
  98.          printf ("*** ERR ::: sysctl ipforwarding. \n");
  99.     }
  100.     else {
  101.          Success++;
  102.          printf ("sysctl ipforwarding value : %d\n",uap_old.flag);
  103.     }
  104.  
  105.     /* Set a new to org */
  106.     uap_new.flag = org;
  107.     newlen = oldenp  = sizeof(struct a);
  108.  
  109.     if (sysctl(mib,4,(void *)NULL,&oldenp,(void *)&uap_new,newlen) < 0) {
  110.          failures++;
  111.          printf ("*** ERR ::: sysctl ipforwarding. \n");
  112.     }
  113.     else {
  114.          Success++;
  115.          printf ("sysctl ipforwarding now set to : %d\n",uap_new.flag);
  116.     }
  117.  
  118.     /* Check the set value */
  119.     uap_old.flag = 0;
  120.     newlen = oldenp  = sizeof(struct a);
  121.  
  122.     if (sysctl(mib,4,(void *)&uap_old,&oldenp,(void *)NULL,newlen) < 0) {
  123.          failures++;
  124.          printf ("*** ERR ::: sysctl ipforwarding. \n");
  125.     }
  126.     else {
  127.         Success++;
  128.         printf ("sysctl ipforwarding value : %d\n",uap_old.flag);
  129.    }
  130.  
  131. }
  132.