A snippet of my code looks as follows:
int descriptor = socket(AF_INET, SOCK_STREAM, 0);
if(descriptor < 0){
cerr << "Error establishing socket connection." << endl;
return -1;
}
int port = 3400;
struct sockaddr_in address;
char buffer[140];
address.sin_family = AF_INET;
address.sin_addr.s_addr = htons(INADDR_ANY);
address.sin_port = htons(port);
int size = sizeof(address);
if(bind(descriptor,(struct sockaddr*)&address,size) < 0){
cerr << "Error binding socket." << endl;
}
cout << "Waiting for connection on " << INADDR_ANY << " on port " << port << ends;
whenever I try compiling this, I get the following error:
error: invalid operands to binary expression
('__bind<int &, sockaddr *, int &>' and 'int')
if(bind(descriptor,(struct sockaddr*)&address,size) < 0){
Does anybody know what this could mean? bind()
is supposed to return an integer or so I thought. My imports look like this:
#include <iostream>
#include <string.h>
#include <string>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <unistd.h>
using namespace std;
Thanks!