⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mmm.c

📁 DOS下开发网络程序的SOCK库,有示例程序,包括FTP
💻 C
字号:

#include "dsock.h"
#include "grlcd.h"
#include "gpio.h"
#include "network.h"
#include "keyboard.h"
#include <conio.h>
#include <dos.h>
#include <stdio.h>
#include <time.h>

unsigned _stklen = 32767U; /* To avoid stack overflow */

/* Network information */
#define MAX_INFO_LINE 11
char _ppcInfo[MAX_INFO_LINE][DUMP_LINE_SIZE] =
{
  "<Information>",
  "MAC:",  "",
  "IP:",  "",
  "Netmask:",  "",
  "Gateway:",  "",
  "DNS:",  "",
};

void ShowLogo(); /* Display our logo */

/* Introduction for Mity-Mite */
char _ppcMityMite[][DUMP_LINE_SIZE] =
{
  #include "msg.c"
};

int main()
{
  char  szBuf[32];
  BYTE *pbyMac;
  DWORD dwIp;
  int   nKey;
  uint  nCnt = 0;
  char  sz[] = "-\\|/";
  int   i;
  SOCKET _sFtp;
  SOCKET _sSmtp;
  SOCKET _sHttp;

  /* Initialize graphic LCD library */
  GrLcd_SetFontType(FONT_5X7);

  printf("\nDM&P Mity-Mite Module Demo Example, %s %s.\n\n",__DATE__,__TIME__);

  /* Show logo */
  Beep3();
  ShowLogo();

  /* Initialize DSock library */
  if(DSock_Open()==FALSE)
  {
    printf("Unable to initialize socket library.\n");
    return 1;
  }

  /* Use BOOTP/DHCP to get setup */
  GrLcd_printf(0,0,"DHCP/BOOTP...");
  if(DSock_DoBootp()==TRUE)
  {
    printf("Load network setup from BOOTP/DHCP.\n");
  }
  else /* Load setup from config file */
  {
    GrLcd_printf(0,8*1,"Loading DSOCK.CFG");
    printf("Unable to load setup from BOOTP/DHCP server.\n");
    DSock_LoadConfigFile("dsock.cfg");
    printf("Load network setup from DSOCK.CFG\n");
  }

  /* Dump network info to network infor buffer and display them on screen */

  pbyMac = DSock_GetMacAddr();
  printf("MAC     : %02X-%02X-%02X-%02X-%02X-%02X\n",
         pbyMac[0],pbyMac[1],pbyMac[2],
         pbyMac[3],pbyMac[4],pbyMac[5]);
  sprintf(_ppcInfo[2],"%02X-%02X-%02X-%02X-%02X-%02X",
         pbyMac[1],pbyMac[1],pbyMac[2],
         pbyMac[2],pbyMac[4],pbyMac[5]);

  dwIp = DSock_GetHostIp();
  inet_ntoa(szBuf,dwIp);
  printf("IP      : %s\n",szBuf);
  sprintf(_ppcInfo[4],"%s",szBuf);

  dwIp = DSock_GetNetmask();
  inet_ntoa(szBuf,dwIp);
  printf("Netmask : %s\n",szBuf);
  sprintf(_ppcInfo[6],"%s",szBuf);

  dwIp = DSock_GetGateway();
  inet_ntoa(szBuf,dwIp);
  printf("Gateway : %s\n",szBuf);
  sprintf(_ppcInfo[8],"%s",szBuf);

  dwIp = DSock_GetDomainNameServer();
  inet_ntoa(szBuf,dwIp);
  printf("DNS     : %s\n",szBuf);
  sprintf(_ppcInfo[10],"%s",szBuf);

  /* Initialize service sockets */
  printf("HTTP service...%s.\n",InitServer(&_sHttp,HTTP_PORT) ? "OK" : "Error");
  printf("FTP  service...%s.\n",InitServer(&_sFtp,FTP_PORT)   ? "OK" : "Error");
  printf("SMTP service...%s.\n",InitServer(&_sSmtp,SMTP_PORT) ? "OK" : "Error");

  /* Get my IP */
  dwIp = DSock_GetHostIp();
  inet_ntoa(szBuf,dwIp);

  /* Show title */
  GrLcd_ClearScreen();
  GrLcd_printf(0,0,"<Mity-Mite Module>\nIP:%s",szBuf);
  SetLed(0);

  /* Main loop */
  while(TRUE)
  {
    /* Display spin bar on screen and LCD */
    GrLcd_printf(115,0,"%c",sz[nCnt++/500%4]);
    printf("%c\r",sz[nCnt++/100%4]);

    FtpServer(_sFtp);
    HttpServer(_sHttp);
    if(SmtpServer(_sSmtp)) /* Is mail available ? */
    {
      SetLed(1);
      GrLcd_printf(0,3*8,"You got mail.");
      Beep3();
    }

    /* Check keyboard for network setup */
    if(kbhit())
    {
      if(getch()==27) /* Exit main loop */
        break;
      KeyboardSetup();
      /* Show title again */
      GrLcd_ClearScreen();
      GrLcd_printf(0,0,"<Mity-Mite Module>\nIP:%s",szBuf);
    }

    nKey = GetKey();
    if(nKey==KEY_ENTER) /* Show mail */
    {
      DumpMail();
      SetLed(0);
      GrLcd_printf(0,0,"<Mity-Mite Module>\nIP:%s",szBuf);
    }
    if(nKey==KEY_RIGHT) /* Show network information */
    {
      DumpBuf(_ppcInfo,MAX_INFO_LINE);
      GrLcd_printf(0,0,"<Mity-Mite Module>\nIP:%s",szBuf);
    }
    if(nKey==KEY_LEFT) /* Show Mity-Mite introduction */
    {
      ShowLogo();
      DumpBuf(_ppcMityMite,75);
      GrLcd_printf(0,0,"<Mity-Mite Module>\nIP:%s",szBuf);
    }
  }

  /* Uninitialize serveice sockets */
  UninitServer(_sHttp);
  UninitServer(_sSmtp);
  UninitServer(_sFtp);

  /* Close DSock library */
  DSock_Close();

  return 0;
}

/* Display our logo */
void ShowLogo()
{
  clock_t clk;
  GrLcd_ClearScreen();
  GrLcd_DisplayBitmapFile(0,0,"dmp.bmp");
  GrLcd_printf(58,0*8," Mity-Mite");
  GrLcd_printf(58,1*8," Demo Box");
  GrLcd_printf(58,3*8,"   <ICOP>");
  clk = clock();
  /* It will delay 5 seconds or press key to skip */
  while(clock()<(clk+18.2*5))
  {
    if(GetKey()!=KEY_NULL)
      break;
    if(kbhit())
    {
      getch();
      break;
    }
  }
  GrLcd_ClearScreen();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -