• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1031
  • Last Modified:

C++ Winsock Code

[C++] I'm trying to create a program that lets me block off every connection request from other computers. I have this code so far, but it's not working. Can you fix it?


#include <winsock.h>


SOCKET SD_BOTH;
SOCKET server;


void main()
{
sockaddr_in Addr;
int Size = sizeof(Addr);
SOCKET NewSocket = accept(server, &Addr, &Size);
if (Size==Size) {
 shutdown(NewSocket, SD_BOTH);
 closesocket(NewSocket);
                    };
}



Here is the error it gave me:


--------------------Configuration: ZONEBLOCK - Win32 Debug--------------------
Compiling...
ZONEBLOCK.cpp
C:\Documents and Settings\Administrator\¹ÙÅÁ È­¸é\security\ZONEBLOCK.cpp(18) : warning C4551: function call missing argument list
C:\Documents and Settings\Administrator\¹ÙÅÁ È­¸é\security\ZONEBLOCK.cpp(24) : error C2664: 'accept' : cannot convert parameter 2 from 'struct sockaddr_in *' to 'struct sockaddr *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.

ZONEBLOCK.obj - 1 error(s), 1 warning(s)



I hope there is a way 2 fix it. Please notify me if you can.

0
NeoHacker
Asked:
NeoHacker
  • 3
  • 2
1 Solution
 
jkrCommented:
The following will work:

#include <winsock.h>


SOCKET SD_BOTH;
SOCKET server;


void main()
{
struct sockaddr_in Addr;
int Size = sizeof(Addr);
SOCKET NewSocket = accept(server, ( struct sockaddr*) &Addr, &Size);
if (Size==Size) {
shutdown(NewSocket, SD_BOTH);
closesocket(NewSocket);
                   };
}

0
 
NeoHackerAuthor Commented:
Thanks, jkr, i would have accepted this as an answer, if, when i tried to execute it, it says:

unresolved external symbol _closesocket@4
unresolved external symbol _shutdown@8
unresolved external symbol _accept@12
[i think the last error doesn't really matter]

4 errors, 0 warnings
0
 
jkrCommented:
>>if, when i tried to execute it, it says:

You need to add ws2_32.lib - just add

#pragma comment ( lib, "ws2_32.lib")

right after '#include <winsock.h>'
0
 
NeoHackerAuthor Commented:
Thanks, jkr, i would have accepted this as an answer, if, when i tried to execute it, it says:

unresolved external symbol _closesocket@4
unresolved external symbol _shutdown@8
unresolved external symbol _accept@12
[i think the last error doesn't really matter]

4 errors, 0 warnings
0
 
NeoHackerAuthor Commented:
MAn, u r a life saver! Thanks!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now