Thread: Help- basic WinSock application

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    7

    Wink Help- basic WinSock application

    Hi
    I want to write a basic server in C.

    I compiled this code-
    http://msdn.microsoft.com/en-us/libr...93(VS.85).aspx
    and i got these problems:

    Code:
    d:\program files\microsoft visual studio\myprojects\server\server.c(18) : error C2079: 'hints' uses undefined struct 'addrinfo'
    d:\program files\microsoft visual studio\myprojects\server\server.c(33) : error C2224: left of '.ai_family' must have struct/union type
    d:\program files\microsoft visual studio\myprojects\server\server.c(34) : error C2224: left of '.ai_socktype' must have struct/union type
    d:\program files\microsoft visual studio\myprojects\server\server.c(35) : error C2224: left of '.ai_protocol' must have struct/union type
    d:\program files\microsoft visual studio\myprojects\server\server.c(36) : error C2224: left of '.ai_flags' must have struct/union type
    d:\program files\microsoft visual studio\myprojects\server\server.c(36) : error C2065: 'AI_PASSIVE' : undeclared identifier
    d:\program files\microsoft visual studio\myprojects\server\server.c(39) : warning C4013: 'getaddrinfo' undefined; assuming extern returning int
    d:\program files\microsoft visual studio\myprojects\server\server.c(47) : error C2037: left of 'ai_family' specifies undefined struct/union 'addrinfo'
    d:\program files\microsoft visual studio\myprojects\server\server.c(47) : error C2037: left of 'ai_socktype' specifies undefined struct/union 'addrinfo'
    d:\program files\microsoft visual studio\myprojects\server\server.c(47) : error C2037: left of 'ai_protocol' specifies undefined struct/union 'addrinfo'
    d:\program files\microsoft visual studio\myprojects\server\server.c(47) : error C2198: 'socket' : too few actual parameters
    d:\program files\microsoft visual studio\myprojects\server\server.c(50) : warning C4013: 'freeaddrinfo' undefined; assuming extern returning int
    d:\program files\microsoft visual studio\myprojects\server\server.c(56) : error C2037: left of 'ai_addr' specifies undefined struct/union 'addrinfo'
    d:\program files\microsoft visual studio\myprojects\server\server.c(56) : error C2037: left of 'ai_addrlen' specifies undefined struct/union 'addrinfo'
    d:\program files\microsoft visual studio\myprojects\server\server.c(56) : error C2198: 'bind' : too few actual parameters
    Error executing cl.exe.
    in summary, the struct "addrinfo" is undefined.

    I included :
    Code:
    #include <stdio.h>
    #include <winsock2.h>
    #include <ws2tcpip.h>
    #include <stdlib.h
    I'm doing link to Ws2_32.lib(by writing it in project-settings-libar)

    I'm working in Visual Studio 6.

    Please help me

    Thanks and sorry about my english
    Tom.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Moved to Networking/Device Communication.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    26
    try including ws2_32.lib

  4. #4
    Registered User
    Join Date
    Dec 2008
    Posts
    183
    #pragma comment(lib,"ws2_32.lib") i think should work then

  5. #5
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by baccardi View Post
    try including ws2_32.lib
    this is not a linker problem - it is compiler problem

    I would try to move winsock2 include to be the first one in the list
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  6. #6
    Registered User
    Join Date
    Mar 2009
    Posts
    7
    i tried your 2 solutions, but it doesnt work ..


  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Have you at all modified the code, compared to the web-site?

    What version of Visual Studio are you using?

    I just copied and pasted it into a new, empty projects in VS C++ 2008 Express Ed., and it compiled, linked and ran without problems. I don't have any client to talk to it, so I don't know what it actually does.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #8
    Registered User
    Join Date
    Dec 2008
    Posts
    183
    msv6 got problems with it i tried it didnt compile with msv6 but it did with msv8

  9. #9
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    Code:
    #include <winsock.h>
    not winsock2.h

  10. #10
    In my head happyclown's Avatar
    Join Date
    Dec 2008
    Location
    In my head
    Posts
    391
    I noticed the program has
    Code:
    int __cdecl main(void)
    Never seen anything like that before.

    I thought the syntax was
    Code:
    int main(void)
    OS: Linux Mint 13(Maya) LTS 64 bit.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [ANN] New script engine (Basic sintax)
    By MKTMK in forum C++ Programming
    Replies: 1
    Last Post: 11-01-2005, 10:28 AM
  2. what are your thoughts on visual basic?
    By orion- in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 09-22-2005, 04:28 AM
  3. MFC run application by clicking on file...
    By dug in forum Windows Programming
    Replies: 4
    Last Post: 12-02-2004, 04:33 AM
  4. Winsock client code help.... very basic.
    By Jay_Tech in forum Windows Programming
    Replies: 7
    Last Post: 10-18-2002, 06:27 AM
  5. Moving from Visual Basic to Visual C++
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 04-10-2002, 09:57 PM