dimanche 8 mars 2020

function bind(int sockfd, struct sockaddr *my_addr, int addrlen) Not found

I am working on Macos using X code to create tutorial for server/client program

bind(int sockfd, struct sockaddr *my_addr, int addrlen)

Not found althoug including theses header

 #include <sys/types.h>
 #include <sys/socket.h>

my fullcode:

#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <iostream>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <string.h>

int main(int argc, const char * argv[]) {

int status,sd,bind;
addrinfo svinfo , *psvinfo;
memset(&svinfo,0,sizeof(svinfo));
svinfo.ai_flags=AI_PASSIVE;
svinfo.ai_family=AF_UNSPEC;
svinfo.ai_socktype=SOCK_STREAM;

//memset(&svinfo,0,sizeof(svinfo));


if((status=getaddrinfo(NULL, "3005", &svinfo, &psvinfo) !=0)){
    //std::cout <<stderr<<" getaddrinfo error: "<<gai_strerror(status)<<std::endl;
    fprintf(stderr, "getaddrinfo error: %s\n", gai_strerror(status));
    exit(1);
}


if((sd=socket(svinfo.ai_family, svinfo.ai_socktype, svinfo.ai_protocol)) == -1){
    fprintf(stderr, "Socket error: %s\n", gai_strerror(status));
   // exit(1);
}
std::cout <<sd<<std::endl;
bind(sd, psvinfo->ai_addr, psvinfo->ai_addrlen);

if (bind(sd, (struct sockaddr *)&svinfo, sizeof(svinfo)) < 0) {
       // Handle the error.
   }

return 0;
}

I get this error Called object type 'int' is not a function or function pointer

Aucun commentaire:

Enregistrer un commentaire