TaiwanTimmy
TaiwanTimmy

Reputation: 187

winsock bind cannot be converted to int

I am having a strange error that I can't find anywhere online. I am attempting to open a socket and bind it so I can send a UDP packet. However, the when I try to check if the bind succeeds, it won't compile. From what I have read, bind() is supposed to return an int, but for some reason it is not doing it in my program.

SOCKET sock = socket(AF_INET, SOCK_DGRAM, 0);
// handle errors
struct sockaddr_in local;
memset(&local, 0, sizeof(local));
local.sin_family = AF_INET;
local.sin_addr.s_addr = INADDR_ANY;
local.sin_port = htons(0);
if (bind(sock, (struct sockaddr*)&local, sizeof(local)) == SOCKET_ERROR) {
    cout << "Binding error\n";
    return false;
}
return true;

My only guess is that bind() is getting overloaded somehow (Maybe another library that I have included)

Upvotes: 1

Views: 497

Answers (2)

SergeyA
SergeyA

Reputation: 62553

The better solution is stop using namespace std; once and for all. It does you much more harm than good (taking into account, it does you no good whatsoever).

Upvotes: 1

Zbynek Vyskovsky - kvr000
Zbynek Vyskovsky - kvr000

Reputation: 18825

Could be conflict with std::bind in C++. Try prepending global namespace:

 ::bind(sock, (struct sockaddr*)&local, sizeof(local))

Upvotes: 3

Related Questions