Help- basic WinSock application

This is a discussion on Help- basic WinSock application within the Networking/Device Communication forums, part of the General Programming Boards category; 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: ...

  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
    22,271
    Moved to Networking/Device Communication.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    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
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  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,189
    Code:
    #include <winsock.h>
    not winsock2.h
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  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, 05: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, 07:27 AM
  5. Moving from Visual Basic to Visual C++
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 04-10-2002, 10:57 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21