Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8201111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:41:46+00:00 2026-06-07T06:41:46+00:00

im getting issues with the folowing code: #include <netdb.h> #include socket.h #define INVALID_SOCKET -1

  • 0

im getting issues with the folowing code:

#include <netdb.h>
#include "socket.h"

#define INVALID_SOCKET -1
#define SOCKET_ERROR   -1

int SenderAddrSize = sizeof(sockaddr);
sockaddr CSocket::SenderAddr;
bool CSocket::tcpconnect(char *address, int port, int mode)
{
    sockaddr_in addr;
    hostent hostEntry;
    if((sockid = socket(AF_INET,SOCK_STREAM, 0)) == SOCKET_ERROR)
        return false;
    if((hostEntry = gethostbyname(address)) == NULL)
    {
        closesocket(sockid);
        return false;
    }
    addr.sin_family = AF_INET;
    addr.sin_addr = *((LPIN_ADDR)*hostEntry->h_addr_list);
    addr.sin_port = htons((u_short)port);
    if(mode ==2)setsync(1);
    if(connect(sockid, (LPSOCKADDR)&addr, sizeof(sockaddr)) == SOCKET_ERROR)
    {
        if(WSAGetLastError() != WSAEWOULDBLOCK)
        {
            closesocket(sockid);
            return false;
        }
    }
    if(mode ==1)setsync(1);
    return true;
}

I get the following output:

/home/nick/.projects/39dll-4-linux/socket.cpp||In member function ‘bool CSocket::tcpconnect(char*, int, int)’:|
/home/nick/.projects/39dll-4-linux/socket.cpp|15|error: no match for ‘operator=’ in ‘hostEntry = gethostbyname(((const char*)address))’|
/home/nick/.projects/39dll-4-linux/socket.cpp|15|note: candidate is:|
/usr/include/netdb.h|101|note: hostent& hostent::operator=(const hostent&)|
/usr/include/netdb.h|101|note:   no known conversion for argument 1 from ‘hostent*’ to ‘const hostent&’|
/home/nick/.projects/39dll-4-linux/socket.cpp|17|error: ‘closesocket’ was not declared in this scope|
/home/nick/.projects/39dll-4-linux/socket.cpp|21|error: ‘LPIN_ADDR’ was not declared in this scope|
/home/nick/.projects/39dll-4-linux/socket.cpp|21|error: base operand of ‘->’ has non-pointer type ‘hostent’|
/home/nick/.projects/39dll-4-linux/socket.cpp|24|error: ‘LPSOCKADDR’ was not declared in this scope|
/home/nick/.projects/39dll-4-linux/socket.cpp|26|error: ‘WSAGetLastError’ was not declared in this scope|
/home/nick/.projects/39dll-4-linux/socket.cpp|26|error: ‘WSAEWOULDBLOCK’ was not declared in this scope|
/home/nick/.projects/39dll-4-linux/socket.cpp|28|error: ‘closesocket’ was not declared in this scope|
/home/nick/.projects/39dll-4-linux/socket.cpp||In member function ‘bool CSocket::tcplisten(int, int, int)’:|
/home/nick/.projects/39dll-4-linux/socket.cpp|40|error: ‘struct sockaddr’ has no member named ‘sin_family’|
/home/nick/.projects/39dll-4-linux/socket.cpp|41|error: ‘struct sockaddr’ has no member named ‘sin_addr’|
/home/nick/.projects/39dll-4-linux/socket.cpp|42|error: ‘struct sockaddr’ has no member named ‘sin_port’|
/home/nick/.projects/39dll-4-linux/socket.cpp|44|error: ‘LPSOCKADDR’ was not declared in this scope|
/home/nick/.projects/39dll-4-linux/socket.cpp|46|error: ‘closesocket’ was not declared in this scope|
/home/nick/.projects/39dll-4-linux/socket.cpp|51|error: ‘closesocket’ was not declared in this scope|
/home/nick/.projects/39dll-4-linux/socket.cpp|57|error: expected constructor, destructor, or type conversion before ‘(’ token|
/home/nick/.projects/39dll-4-linux/socket.cpp||In destructor ‘CSocket::~CSocket()’:|
/home/nick/.projects/39dll-4-linux/socket.cpp|75|error: ‘closesocket’ was not declared in this scope|
/home/nick/.projects/39dll-4-linux/socket.cpp||In member function ‘CSocket* CSocket::tcpaccept(int)’:|
/home/nick/.projects/39dll-4-linux/socket.cpp|80|error: ‘SOCKET’ was not declared in this scope|
/home/nick/.projects/39dll-4-linux/socket.cpp|80|error: expected ‘;’ before ‘sock2’|
/home/nick/.projects/39dll-4-linux/socket.cpp|81|error: ‘sock2’ was not declared in this scope|
/home/nick/.projects/39dll-4-linux/socket.cpp|81|error: ‘SOCKADDR’ was not declared in this scope|
/home/nick/.projects/39dll-4-linux/socket.cpp|81|error: expected primary-expression before ‘)’ token|
/home/nick/.projects/39dll-4-linux/socket.cpp||In member function ‘char* CSocket::tcpip()’:|
/home/nick/.projects/39dll-4-linux/socket.cpp|93|error: ‘SOCKADDR’ was not declared in this scope|
/home/nick/.projects/39dll-4-linux/socket.cpp|93|error: expected primary-expression before ‘)’ token|
/home/nick/.projects/39dll-4-linux/socket.cpp|94|error: ‘struct sockaddr’ has no member named ‘sin_addr’|
/home/nick/.projects/39dll-4-linux/socket.cpp|94|error: ‘inet_ntoa’ was not declared in this scope|
/home/nick/.projects/39dll-4-linux/socket.cpp||In member function ‘void CSocket::setnagle(bool)’:|
/home/nick/.projects/39dll-4-linux/socket.cpp|100|error: ‘TCP_NODELAY’ was not declared in this scope|
/home/nick/.projects/39dll-4-linux/socket.cpp||In member function ‘bool CSocket::tcpconnected()’:|
/home/nick/.projects/39dll-4-linux/socket.cpp|108|error: ‘WSAGetLastError’ was not declared in this scope|
/home/nick/.projects/39dll-4-linux/socket.cpp|108|error: ‘WSAEWOULDBLOCK’ was not declared in this scope|
/home/nick/.projects/39dll-4-linux/socket.cpp||In member function ‘int CSocket::setsync(int)’:|
/home/nick/.projects/39dll-4-linux/socket.cpp|116|error: ‘FIONBIO’ was not declared in this scope|
/home/nick/.projects/39dll-4-linux/socket.cpp|116|error: ‘ioctlsocket’ was not declared in this scope|
/home/nick/.projects/39dll-4-linux/socket.cpp||In member function ‘bool CSocket::udpconnect(int, int)’:|
/home/nick/.projects/39dll-4-linux/socket.cpp|121|error: ‘SOCKADDR_IN’ was not declared in this scope|
/home/nick/.projects/39dll-4-linux/socket.cpp|121|error: expected ‘;’ before ‘addr’|
/home/nick/.projects/39dll-4-linux/socket.cpp|124|error: ‘addr’ was not declared in this scope|
/home/nick/.projects/39dll-4-linux/socket.cpp|128|error: ‘SOCKADDR’ was not declared in this scope|
/home/nick/.projects/39dll-4-linux/socket.cpp|128|error: expected primary-expression before ‘)’ token|
/home/nick/.projects/39dll-4-linux/socket.cpp|130|error: ‘closesocket’ was not declared in this scope|
/home/nick/.projects/39dll-4-linux/socket.cpp||In member function ‘int CSocket::sendmessage(char*, int, CBuffer*)’:|
/home/nick/.projects/39dll-4-linux/socket.cpp|142|error: ‘SOCKADDR_IN’ was not declared in this scope|
/home/nick/.projects/39dll-4-linux/socket.cpp|142|error: expected ‘;’ before ‘addr’|
/home/nick/.projects/39dll-4-linux/socket.cpp|145|error: ‘min’ was not declared in this scope|
/home/nick/.projects/39dll-4-linux/socket.cpp|145|note: suggested alternative:|
/usr/include/c++/4.6/bits/stl_algobase.h|233|note:   ‘std::min’|
/home/nick/.projects/39dll-4-linux/socket.cpp|146|error: ‘addr’ was not declared in this scope|
/home/nick/.projects/39dll-4-linux/socket.cpp|148|error: ‘inet_addr’ was not declared in this scope|
/home/nick/.projects/39dll-4-linux/socket.cpp|149|error: ‘SOCKADDR’ was not declared in this scope|
/home/nick/.projects/39dll-4-linux/socket.cpp|149|error: expected primary-expression before ‘)’ token|
/home/nick/.projects/39dll-4-linux/socket.cpp|168|error: ‘WSAGetLastError’ was not declared in this scope|
/home/nick/.projects/39dll-4-linux/socket.cpp||In member function ‘int CSocket::receivemessage(int, CBuffer*)’:|
/home/nick/.projects/39dll-4-linux/socket.cpp|198|error: ‘SOCKADDR’ was not declared in this scope|
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options...|
||=== Build finished: 50 errors, 0 warnings ===|

I’m totally lost at this point. Ive used Google extensively and solved several other problems myself, but I’m stuck at this. can anyone help me with this issue?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T06:41:47+00:00Added an answer on June 7, 2026 at 6:41 am

    Your variable hostEntry is of type hostent but the function gethostbyname only returns a pointer to a structure. Your variable should have a pointer type, hostent*.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some issues getting file uploads to work correctly and the following code
I am mainly from a Sql Server background, and following some issues with getting
After resolving issues with RIA installation here , I'm still getting this following error.
Lately we've started getting issues with outdated countries / regions list being presented to
Having some issues getting my head around the differences between UTF-8, UTF-16, ASCII and
Im having issues getting this to work, maybe its not even possible? I have
I'm having issues getting the CSS3 box-shadow to look correct. I currently have a
I am having issues getting setCenter to work. My JS console tells me: myMap
I am having issues getting the -e and -d file test operators to work
i am trying to intergrate the jquery progress bar but i am getting issues.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.