title: I would like to convert this Borland C++ code into workable Visual Studio C++ Code, Some Issues
body: <p>I have some old Borland C++ source code that needs to be converted into Visual Studio C++ code. I got some of it working, however have hit a roadblock with some "const chars" and "unsigned chars". Notably the IP addressing and Port addressing (lines 15 - 28 and the error points to line 44)</p>
  
  <pre><code>    // test1.cpp 5/23/97
  
      // example Win32 C++ program to read registers from PLC via gateway
  
      // compile with BC45 or BC50
      // default settings for Win32 console app
      // empty DEF file
  
      #include &lt;winsock2.h&gt;
      #include &lt;stdio.h&gt;
      #include &lt;conio.h&gt;
  
  
  
      int main(int argc, char** argv)
      {
          if (argc &lt; 5)
          {
              printf("usage: test1 ip_adrs unit reg_no num_regs\n"
                  "eg test1 198.202.138.72 5 0 10\n");
              return 1;
          }
          char* ip_adrs = argv[1];
          unsigned short unit = atoi(argv[2]);
          unsigned short reg_no = atoi(argv[3]);
          unsigned short num_regs = atoi(argv[4]);
          printf("ip_adrs = %s unit = %d reg_no = %d num_regs = %d\n",
              ip_adrs, unit, reg_no, num_regs);
  
          // initialize WinSock
          static WSADATA wd;
          if (WSAStartup(0x0101, &amp;wd))
          {
              printf("cannot initialize WinSock\n");
              return 1;
          }
  
          // set up socket
          SOCKET s;
          s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
          struct sockaddr_in server;
          server.sin_family = AF_INET;
          server.sin_port = htons(502); // ASA standard port
          server.sin_addr.s_addr = inet_addr(ip_adrs);
          int i;
          i = connect(s, (sockaddr*)&amp; server, sizeof(sockaddr_in));
          if (i &lt; 0)
          {
              printf("connect - error %d\n", WSAGetLastError());
              closesocket(s);
              WSACleanup();
              return 1;
          }
          fd_set fds;
          FD_ZERO(&amp;fds);
          timeval tv;
          tv.tv_sec = 5;
          tv.tv_usec = 0;
  
          // wait for permission to send
          FD_SET(s, &amp;fds);
          i = select(32, NULL, &amp;fds, NULL, &amp;tv); // write
          if (i &lt;= 0)
          {
              printf("select - error %d\n", WSAGetLastError());
              closesocket(s);
              WSACleanup();
              return 1;
          }
  
          // build request of form 0 0 0 0 0 6 ui 3 rr rr nn nn
          unsigned char obuf[261];
          unsigned char ibuf[261];
          for (i = 0; i &lt; 5; i++) obuf[i] = 0;
          obuf[5] = 6;
          obuf[6] = unit;
          obuf[7] = 3;
          obuf[8] = reg_no &gt;&gt; 8;
          obuf[9] = reg_no &amp; 0xff;
          obuf[10] = num_regs &gt;&gt; 8;
          obuf[11] = num_regs &amp; 0xff;
  
          // send request
          i = send(s, reinterpret_cast&lt;char*&gt;(obuf), 12, 0);
          if (i &lt; 12)
          {
              printf("failed to send all 12 chars\n");
          }
  
          // wait for response
          FD_SET(s, &amp;fds);
          i = select(32, &amp;fds, NULL, NULL, &amp;tv); //read
          if (i &lt;= 0)
          {
              printf("no TCP response received\n");
              closesocket(s);
              WSACleanup();
              return 1;
          }
  
          // read response
          i = recv(s, reinterpret_cast&lt;char*&gt;(ibuf), 261, 0);
          if (i &lt; 9)
          {
              if (i == 0)
              {
                  printf("unexpected close of connection at remote end\n");
              }
              else
              {
                  printf("response was too short - %d chars\n", i);
              }
          }
          else if (ibuf[7] &amp; 0x80)
          {
              printf("MODBUS exception response - type %d\n", ibuf[8]);
          }
          else if (i != (9 + 2 * num_regs))
          {
              printf("incorrect response size is %d expected %d\n", i, (9 + 2 * num_regs));
          }
          else
          {
              for (i = 0; i &lt; num_regs; i++)
              {
                  unsigned short w = (ibuf[9 + i + i] &lt;&lt; 8) + ibuf[10 + i + i];
                  printf("word %d = %d\n", i, w);
              }
          }
  
          // close down
          closesocket(s);
          WSACleanup();
          return 0;
      }
  </code></pre>
  
  <p>This is code to connect to a simulator, and the IP and socket values in here are incorrect. However that should not be the issue, it is the conversion of the "chars" that is the real roadblock. Any feedback is appreciated.</p>
  
  <p>The correct destination for the IP is DESKTOP-E503UCE or 192.168.0.11 and the port listed under server settings is 502. Please note that the IP above is a local IP (my computer)</p>
  
  <p>Additionally, the only error currently occurring is Code C4996 - 'inet_addr': Use inet_pton() or Inet_Pton() instead or define _WINSTOCK_DEPREACTED_NO_WARNINGS to disable deprecated API warnings on line 44.</p>