?
Solved

C++ Winsock Code

Posted on 2003-02-25
5
Medium Priority
?
1,013 Views
Last Modified: 2012-05-04
[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
Comment
Question by:NeoHacker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 8019002
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
 

Author Comment

by:NeoHacker
ID: 8019250
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
 
LVL 86

Accepted Solution

by:
jkr earned 800 total points
ID: 8019276
>>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
 

Author Comment

by:NeoHacker
ID: 8019299
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
 

Author Comment

by:NeoHacker
ID: 8019314
MAn, u r a life saver! Thanks!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question