Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. VC++ console application - client / Server

VC++ console application - client / Server

Scheduled Pinned Locked Moved C / C++ / MFC
sysadminquestionc++
21 Posts 5 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Pouria Polouk

    Thank you for your advice, But it didn’t work. I decided to run server program on one of computers in my office. For this purpose I got that computer’s IP address from http://myip.dnsomatic.com and used it in server program. But error code 10049 was returned. (Cannot assign requested address) : WSAData ws; struct sockaddr_in sock; int resSock, cl,bnd; WSAStartup(MAKEWORD(2, 2), &ws); resSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (resSock != INVALID_SOCKET){ sock.sin_family = AF_INET; sock.sin_port = htons(3377); sock.sin_addr.S_un.S_addr = inet_addr("86.57.x.y"); } bnd = bind(resSock, (struct sockaddr *)&sock, sizeof(sock)); if (bnd != SOCKET_ERROR) cout << "Successfull..." << endl; else cout << GetLastError() << endl;

    D Offline
    D Offline
    David Crow
    wrote on last edited by
    #6

    zartosht_ppp wrote:

    I decided to run server program on one of computers in my office. For this purpose I got that computer’s IP address from http://myip.dnsomatic.com and...

    But is that computer visible to the outside world? In most offices, it would not be.

    "One man's wage rise is another man's price increase." - Harold Wilson

    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

    "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

    P 1 Reply Last reply
    0
    • D David Crow

      zartosht_ppp wrote:

      I decided to run server program on one of computers in my office. For this purpose I got that computer’s IP address from http://myip.dnsomatic.com and...

      But is that computer visible to the outside world? In most offices, it would not be.

      "One man's wage rise is another man's price increase." - Harold Wilson

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

      P Offline
      P Offline
      Pouria Polouk
      wrote on last edited by
      #7

      In my office, it's possible. I just want a solution. Let me know if you have one.

      A 1 Reply Last reply
      0
      • P Pouria Polouk

        In my office, it's possible. I just want a solution. Let me know if you have one.

        A Offline
        A Offline
        Albert Holguin
        wrote on last edited by
        #8

        There are a lot of things that could be in the way... can you ping between the two machines? Just having internet access isn't really enough, a lot of times certain ports are blocked off to prevent external intrusions. There could be firewalls blocking access both within the machine and externally as part of the network.

        P 1 Reply Last reply
        0
        • A Albert Holguin

          There are a lot of things that could be in the way... can you ping between the two machines? Just having internet access isn't really enough, a lot of times certain ports are blocked off to prevent external intrusions. There could be firewalls blocking access both within the machine and externally as part of the network.

          P Offline
          P Offline
          Pouria Polouk
          wrote on last edited by
          #9

          Look, my problem is that server program doesn’t bind to the valid IP such as 86.57.91.230. But it binds to the invalid IP such as 192.168.0.1.

          L J 2 Replies Last reply
          0
          • P Pouria Polouk

            Look, my problem is that server program doesn’t bind to the valid IP such as 86.57.91.230. But it binds to the invalid IP such as 192.168.0.1.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #10

            You should let the system choose which address to bind to, rather than trying to force it. The chances are that the address you have is not the address of a network adapter on that system.

            1 Reply Last reply
            0
            • P Pouria Polouk

              Look, my problem is that server program doesn’t bind to the valid IP such as 86.57.91.230. But it binds to the invalid IP such as 192.168.0.1.

              J Offline
              J Offline
              jeron1
              wrote on last edited by
              #11

              Is that IP address 86.57.... the IP address on your router that the outside world sees?

              "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst

              P 1 Reply Last reply
              0
              • J jeron1

                Is that IP address 86.57.... the IP address on your router that the outside world sees?

                "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst

                P Offline
                P Offline
                Pouria Polouk
                wrote on last edited by
                #12

                Yes, it is.

                J 1 Reply Last reply
                0
                • P Pouria Polouk

                  Yes, it is.

                  J Offline
                  J Offline
                  jeron1
                  wrote on last edited by
                  #13

                  Have you set your router up to port forward requests from the outside world to your machine? Have you open up that port on your firewall? You need to bind to your local IP address (192.168....) and have the router forward those external requests to your machine.

                  "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst

                  P 1 Reply Last reply
                  0
                  • J jeron1

                    Have you set your router up to port forward requests from the outside world to your machine? Have you open up that port on your firewall? You need to bind to your local IP address (192.168....) and have the router forward those external requests to your machine.

                    "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst

                    P Offline
                    P Offline
                    Pouria Polouk
                    wrote on last edited by
                    #14

                    Thank you so much, it worked. Now I want to develop the program and write a program such as NETCAT. I want the victim stays at listening state after running the program. The question is how the victim get its public IP to stays at listening state with that IP?

                    J 1 Reply Last reply
                    0
                    • P Pouria Polouk

                      Thank you so much, it worked. Now I want to develop the program and write a program such as NETCAT. I want the victim stays at listening state after running the program. The question is how the victim get its public IP to stays at listening state with that IP?

                      J Offline
                      J Offline
                      jeron1
                      wrote on last edited by
                      #15

                      Not sure what you mean by victim, nor am I familiar with netcat. Try clarifying your question and perhaps create a new thread on this forum.

                      "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst

                      P 1 Reply Last reply
                      0
                      • J jeron1

                        Not sure what you mean by victim, nor am I familiar with netcat. Try clarifying your question and perhaps create a new thread on this forum.

                        "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst

                        P Offline
                        P Offline
                        Pouria Polouk
                        wrote on last edited by
                        #16

                        ok. Here is about NETCAT (http://en.wikipedia.org/wiki/Netcat) I have written a program in two client and server versions. The server program must be run on the victim computer. I’m controlling the whole of the victim computer by client program. I’ve written this program for LAN. Now I want this program works on the internet while controlling that victim computer with the server program on. The victim computer is connected to the internet by and ADSL broadband. My problem is when the server program is being run on the victim computer, how it can get the Public IP and then stays at listening state on that IP address?

                        J 1 Reply Last reply
                        0
                        • P Pouria Polouk

                          ok. Here is about NETCAT (http://en.wikipedia.org/wiki/Netcat) I have written a program in two client and server versions. The server program must be run on the victim computer. I’m controlling the whole of the victim computer by client program. I’ve written this program for LAN. Now I want this program works on the internet while controlling that victim computer with the server program on. The victim computer is connected to the internet by and ADSL broadband. My problem is when the server program is being run on the victim computer, how it can get the Public IP and then stays at listening state on that IP address?

                          J Offline
                          J Offline
                          jeron1
                          wrote on last edited by
                          #17

                          Sounds difficult, as the ADSL router probably doesn't have a static IP address, but if it did, the server software would listen to the local machines' (private) IP address (this probably isn't static either), and the ADSL router would need to have port forwarding setup to send your server machine incoming packets. Lots of this (I'm guessing) is not done programatically. here[^] is an example of the type of setup needed.

                          "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst

                          P 1 Reply Last reply
                          0
                          • J jeron1

                            Sounds difficult, as the ADSL router probably doesn't have a static IP address, but if it did, the server software would listen to the local machines' (private) IP address (this probably isn't static either), and the ADSL router would need to have port forwarding setup to send your server machine incoming packets. Lots of this (I'm guessing) is not done programatically. here[^] is an example of the type of setup needed.

                            "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst

                            P Offline
                            P Offline
                            Pouria Polouk
                            wrote on last edited by
                            #18

                            Dear friend, It’s not important if that public IP (ADSL IP) be static or dynamic. The code below gets public IP of that computer and it must be able bind that IP to the created socket and then stays at the listening state: ... HINTERNET hI, hF; DWORD piSize; char public_ip[15]; hI= InternetOpen(NULL, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); hF = InternetOpenUrlA(hI, "http://myip.dnsomatic.com", NULL, 0, INTERNET_FLAG_RELOAD, 0); InternetReadFile(hF, &public_ip, sizeof(public_ip), &piSize); public_ip[piSize] = '\0'; InternetCloseHandle(hF); InternetCloseHandle(hI); cout << public_ip; ... The main problem is that my server program can’t bind to received public IP.

                            J 1 Reply Last reply
                            0
                            • P Pouria Polouk

                              Dear friend, It’s not important if that public IP (ADSL IP) be static or dynamic. The code below gets public IP of that computer and it must be able bind that IP to the created socket and then stays at the listening state: ... HINTERNET hI, hF; DWORD piSize; char public_ip[15]; hI= InternetOpen(NULL, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); hF = InternetOpenUrlA(hI, "http://myip.dnsomatic.com", NULL, 0, INTERNET_FLAG_RELOAD, 0); InternetReadFile(hF, &public_ip, sizeof(public_ip), &piSize); public_ip[piSize] = '\0'; InternetCloseHandle(hF); InternetCloseHandle(hI); cout << public_ip; ... The main problem is that my server program can’t bind to received public IP.

                              J Offline
                              J Offline
                              jeron1
                              wrote on last edited by
                              #19

                              You want to bind to an IP address associated with a NIC on a seperate device (ADSL router)? If so, I don't think you can, and you don't need to (think port forwarding). If not, I'm still not sure what your question is.

                              "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst

                              P 1 Reply Last reply
                              0
                              • J jeron1

                                You want to bind to an IP address associated with a NIC on a seperate device (ADSL router)? If so, I don't think you can, and you don't need to (think port forwarding). If not, I'm still not sure what your question is.

                                "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst

                                P Offline
                                P Offline
                                Pouria Polouk
                                wrote on last edited by
                                #20

                                It's confusing! Let’s imagine my public IP address is 86.57.91.237. Now I want to use that IP in the code below: ... WSAData ws; struct sockaddr_in sock; int resSock, bnd; WSAStartup(MAKEWORD(2, 2), &ws); resSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (resSock != INVALID_SOCKET){ sock.sin_family = AF_INET; sock.sin_port = htons(3377); sock.sin_addr.S_un.S_addr = inet_addr("86.57.91.237"); } bnd=bind(resSock, (struct sockaddr *)&sock, sizeof(sock)); if (bnd != SOCKET_ERROR) cout << "Bind Successful" << endl; else cout << GetLastError() << endl; ... why does this program show error code 10049? Error code 10049 means: “The requested address is not valid in its context. This normally results from an attempt to bind to an address that is not valid for the local computer”. I want to see “Bind Successful” message.

                                J 1 Reply Last reply
                                0
                                • P Pouria Polouk

                                  It's confusing! Let’s imagine my public IP address is 86.57.91.237. Now I want to use that IP in the code below: ... WSAData ws; struct sockaddr_in sock; int resSock, bnd; WSAStartup(MAKEWORD(2, 2), &ws); resSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (resSock != INVALID_SOCKET){ sock.sin_family = AF_INET; sock.sin_port = htons(3377); sock.sin_addr.S_un.S_addr = inet_addr("86.57.91.237"); } bnd=bind(resSock, (struct sockaddr *)&sock, sizeof(sock)); if (bnd != SOCKET_ERROR) cout << "Bind Successful" << endl; else cout << GetLastError() << endl; ... why does this program show error code 10049? Error code 10049 means: “The requested address is not valid in its context. This normally results from an attempt to bind to an address that is not valid for the local computer”. I want to see “Bind Successful” message.

                                  J Offline
                                  J Offline
                                  jeron1
                                  wrote on last edited by
                                  #21

                                  Run "ipconfig /all" at the command prompt. Look at the results, there should be data given about each NIC card on YOUR machine. Look at the line that says "IP Address.......xxx.xxx.xxx.xxx" (there may be several). Make a list of these IP addresses. If "86.57.91.237" is not in that list, then you can not bind to it. Meaning it is not an IP address associated with a NIC on your computer.

                                  "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst

                                  1 Reply Last reply
                                  0
                                  Reply
                                  • Reply as topic
                                  Log in to reply
                                  • Oldest to Newest
                                  • Newest to Oldest
                                  • Most Votes


                                  • Login

                                  • Don't have an account? Register

                                  • Login or register to search.
                                  • First post
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • World
                                  • Users
                                  • Groups