#include <netinet/in.h>

This is a discussion on #include <netinet/in.h> within the C Programming forums, part of the General Programming Boards category; how do I include this header it says error in my system thx for future help...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    15

    Question #include <netinet/in.h>

    how do I include this header it says error in my system

    thx for future help

  2. #2
    Registered User
    Join Date
    Feb 2006
    Posts
    20
    hmmz it is a bit hard to tell because you didnt state your compiler

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    15
    I use visual studio c/c++

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >I use visual studio c/c++
    It's generally difficult to include Unix headers on a Windows system. Explain what you're trying to do and the answer will be more useful than "You can't do that".
    My best code is written with the delete key.

  5. #5
    Registered User
    Join Date
    Oct 2006
    Posts
    15
    oh okay then

    I am trying to open a port , lisen ,read , write data to it any help would be great

  6. #6
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Code:
    #include <winsock2.h>
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Searching for "socket tutorial" or the like on this board or a search engine will give you a tutorial for winsock, or a tutorial for unix sockets and their differences from winsock sockets.

    [edit] I like Beej's sockets tutorial: http://www.google.ca/search?hl=en&q=beej&meta= [/edit]

    [edit=2] From http://mia.ece.uic.edu/~papers/WWW/s...tml/intro.html
    1.5. Note for Windows Programmers
    I have a particular dislike for Windows, and encourage you to try Linux, BSD, or Unix instead. That being said, you can still use this stuff under Windows.

    First, ignore pretty much all of the system header files I mention in here. All you need to include is:

    #include <winsock.h>



    Wait! You also have to make a call to WSAStartup() before doing anything else with the sockets library. The code to do that looks something like this:

    #include <winsock.h>

    {
    WSADATA wsaData; // if this doesn't work
    //WSAData wsaData; // then try this instead

    if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0) {
    fprintf(stderr, "WSAStartup failed.\n");
    exit(1);
    }



    You also have to tell your compiler to link in the Winsock library, usually called wsock32.lib or winsock32.lib or somesuch. Under VC++, this can be done through the Project menu, under Settings.... Click the Link tab, and look for the box titled "Object/library modules". Add "wsock32.lib" to that list.

    Or so I hear.

    Finally, you need to call WSACleanup() when you're all through with the sockets library. See your online help for details.

    Once you do that, the rest of the examples in this tutorial should generally apply, with a few exceptions. For one thing, you can't use close() to close a socket--you need to use closesocket(), instead. Also, select() only works with socket descriptors, not file descriptors (like 0 for stdin).

    There is also a socket class that you can use, CSocket. Check your compilers help pages for more information.

    To get more information about Winsock, read the Winsock FAQ and go from there.

    Finally, I hear that Windows has no fork() system call which is, unfortunately, used in some of my examples. Maybe you have to link in a POSIX library or something to get it to work, or you can use CreateProcess() instead. fork() takes no arguments, and CreateProcess() takes about 48 billion arguments. If you're not up to that, the CreateThread() is a little easier to digest...unfortunately a discussion about multithreading is beyond the scope of this document. I can only talk about so much, you know!
    [/edit]
    Last edited by dwks; 10-21-2006 at 02:48 PM.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  8. #8
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    There shouldn't be much differences though.
    I have compiled many unix socket tutorials with no problems.

    Although it doesn't hurt to learn the differences
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  9. #9
    Registered User
    Join Date
    Oct 2006
    Posts
    15
    cool thx people If I have any more questions I will ask

  10. #10
    Registered User
    Join Date
    Oct 2006
    Posts
    15
    this tutorial is better for me And i hope it helps otherS too

    http://www.exegesis.uklinux.net/gand...k/winsock1.htm
    Last edited by Demon.killer; 10-21-2006 at 05:26 PM.

  11. #11
    Registered User
    Join Date
    Oct 2006
    Posts
    15
    Code:
    #include <winsock.h>
    int main(void)
    {
    WSADATA wsaData; 
    
    if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0)
    {
    printf("WSAStartup failed.\n");
    exit(1);
    } 
    }
    When I use this code I get the following 2 error


    1)Error 2 error LNK2019: unresolved external symbol _WSAStartup@8 referenced in function _main ports.obj


    2)Error 3 fatal error LNK1120: 1 unresolved externals C:\Documents and Settings\Ajay\My Documents\Visual Studio 2005\Projects\ports\Debug\ports.exe

  12. #12
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >1)Error 2 error LNK2019: unresolved external symbol _WSAStartup@8 referenced in function _main ports.obj
    You need to link the winsock library too. Just including the header doesn't do diddly because it only contains declarations.
    My best code is written with the delete key.

  13. #13
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    It's mentioned here:
    You also have to tell your compiler to link in the Winsock library, usually called wsock32.lib or winsock32.lib or somesuch. Under VC++, this can be done through the Project menu, under Settings.... Click the Link tab, and look for the box titled "Object/library modules". Add "wsock32.lib" to that list.
    It's libwsock32.a for Dev-C++, I think; the command-line parameter is -lwsock32.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  14. #14
    Registered User
    Join Date
    Oct 2006
    Posts
    15

    Question

    in visual studio I don't see any thing under that any help will be better pls

    thx for future help
    Attached Images Attached Images  

  15. #15
    Registered User
    Join Date
    Oct 2006
    Posts
    15
    I got it working thxs every one
    Last edited by Demon.killer; 10-22-2006 at 03:27 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  2. MFC include BS
    By VirtualAce in forum Windows Programming
    Replies: 4
    Last Post: 10-31-2005, 11:44 AM
  3. help with finding lowest number entered
    By volk in forum C++ Programming
    Replies: 12
    Last Post: 03-22-2003, 12:21 PM
  4. #includes don't seem to be working
    By Inquirer in forum C++ Programming
    Replies: 12
    Last Post: 08-05-2002, 05:38 PM
  5. MFC Assertion Failure
    By maxthecat in forum Windows Programming
    Replies: 5
    Last Post: 08-01-2002, 09:58 AM

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