I have a problem with a server on MacOS using POSIX socket functions. The problem is that when my client try con connect to the server with the connect()
function the server (macOS) send a tcp RST packet and close connection. I tried to disable the FW but the problem is still there.
I put only what I think is useful for you to understand my problem. The same identical code works on Linux (Ubuntu) very well. I think this is a problem about security policy on MacOS.
Server code:
int main (int argc, char *argv[]){
int s;
struct sockaddr_in saddr, caddr;
socklen_t addrlen = sizeof(struct sockaddr_in);
inet_aton(argv[1], &saddr.sin_addr);
uint16_t port = htons(atoi(argv[2]));
int result;
int bklog = 10;
int i,n;
int *sockVett;
sockVett = new int[nESP];
while(1) {
s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (s == -1 ){
cout << "socket() failed\n";
return -1;
}
for(i=0; i < nESP; i++){
sockVett[i] = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
}
saddr.sin_family = AF_INET;
saddr.sin_port = port;
saddr.sin_addr.s_addr = INADDR_ANY;
bind(s, (struct sockaddr *) &saddr, sizeof(saddr));
listen (s, bklog);
for(i=0; i < nESP; i++){
if(debug) printf("SockVett[%d] is waiting for connection..\n", i+1);
sockVett[i] = accept(s, (struct sockaddr *) &caddr, &addrlen);
if(debug) printf("SockVett[%d] connected\n", i+1);
}
if(debug) printf("All ESP connected\n\n ---Start program---\n");
}
}
My server app blocks at the first accept() call in for(...) loop and with Wireshark I observed that my server send a TCP RST packet and so close the connection.
Thanks everybody!