Thread: Simple Winsock Code using DevCPP

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903

    Question Simple Winsock Code using DevCPP

    I just need a little help before getting deep into network programming.. I am attempting to make what is nothing more than a "hello world" of winsock api by playing with a couple of functions.

    The first problem is that I cannot get my code to compile using either the <winsock.h> or <winsock2.h> header. I have attached a pic of all compiler errors. I have browsed the, "include" folder located in DevCPP and have located both the winsock.h and winsock2.h header files. Compiler options are at default settings and provide paths to the devcpp 'include' folder.

    There may be additional errors.. I am kinda new at winsock api and may have made a few syntactical mistakes.

    Please help if ye' can.

    Code:
    #include<iostream>
    #include<winsock2.h>
    
    using namespace std;
    
    int main()
    {
        WSADATA wsd;
        WSAPROTOCOL_INFO *proto;
        LPDWORD bufferlength = NULL;
        
        WSAStartup(MAKEWORD(2,2), &wsd);
        
        cout << "\n\nUsing winsock version " << wsd.wVersion;
        
        //This call will fail, but will return the correct buffer size
        WSAEnumProtocols(NULL, NULL, bufferlength);
        
        //Allocate the correct buffer size of WSAPROTOCOL_INFO structures
        proto = new WSAPROTOCOL_INFO[*bufferlength];
        
        //Populate an array of system protocols
        WSAEnumProtocols(NULL, proto, bufferlength);
        
        //Step through the array and view some system supported protocol information
        for(int i=0; i<*bufferlength; i++)
        {
           cout << "\n\n\nVersion:    " << proto[i].iVersion;
           cout << "\nAddress Family: " << proto[i].iAddressFamily;
           cout << "\nMax Sockets:    " << proto[i].iMaxSockAddr;
           cout << "\nMin Sockets:    " << proto[i].iMinSockAddr;
           cout << "\nProtocol:       " << proto[i].szProtocol;
        }   
        
        WSACleanup();
        
        return 0;
    }
    Last edited by The Brain; 11-12-2006 at 09:10 AM.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with simple piece of code
    By Furious5k in forum C++ Programming
    Replies: 10
    Last Post: 12-12-2008, 05:25 PM
  2. Weird error in this simple code! C2248!
    By gross100 in forum C++ Programming
    Replies: 2
    Last Post: 12-10-2005, 01:31 AM
  3. << !! Posting Code? Read this First !! >>
    By kermi3 in forum Game Programming
    Replies: 0
    Last Post: 10-14-2002, 01:27 PM
  4. << !! Posting Code? Read this First !! >>
    By kermi3 in forum C# Programming
    Replies: 0
    Last Post: 10-14-2002, 01:26 PM
  5. Simple Code, looking for input.
    By Alien_Freak in forum C Programming
    Replies: 3
    Last Post: 03-03-2002, 11:34 AM