home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / MSDOS / WATTCP / WNWATTCP.ZIP / SRC / SOCK_INI.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-09-19  |  1.3 KB  |  60 lines

  1. /*
  2.  * sock_init - easy way to guarentee:
  3.  *  - card is ready
  4.  *  - shutdown is handled
  5.  *  - cbreaks are handled
  6.  *      - config file is read
  7.  *  - bootp is run
  8.  *
  9.  * 0.1 : May 2, 1991  Erick - reorganized operations
  10.  */
  11.  
  12. #include "copyright.h"
  13. #include "wattcp.h"
  14. #include "errors.h"
  15. #include <stdlib.h>
  16.  
  17. word _survivebootp = 0;
  18.  
  19. void sock_exit()
  20. {
  21.     tcp_shutdown();
  22. #ifdef WINDOWS
  23.     WinExit();
  24. #endif
  25. }
  26.  
  27. int sock_init(void)
  28. {
  29.     int err;
  30.  
  31. #ifdef WINDOWS
  32.     if (err = WinInit()) return err;    /* Initialize Windows environment */
  33. #endif
  34.     if (err = tcp_init()) return err;   /* must precede tcp_config because we need eth addr */
  35.     atexit(sock_exit);  /* must not precede tcp_init() incase no PD */
  36.     tcp_cbrk( 0x10 );   /* allow control breaks, give message */
  37.  
  38.     if (tcp_config( NULL )) { /* if no config file use BOOTP w/broadcast */
  39.        _bootpon = 1;
  40. #ifdef WINDOWS
  41.        /* nothing */
  42. #else
  43.        outs("Configuring through BOOTP");
  44. #endif
  45.     }
  46.  
  47.     if (_bootpon) /* non-zero if we use bootp */
  48.       if (_dobootp()) {
  49. #ifdef WINDOWS
  50.      /* nothing */
  51. #else
  52.          outs("BOOTP failed\n\r");
  53. #endif
  54.          if ( !_survivebootp )
  55.            sock_exit();
  56.            return(ER_CONF);
  57.       }
  58.     return(SUCCESS);
  59. }
  60.