sloved
used:
int sock;
struct addrinfo hints, *res;
int reuseaddr = 1; /* True */
/* Get the address info */
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
if (getaddrinfo(NULL, PORT, &hints, &res) != 0) {
perror("getaddrinfo");
return 1;
}
/* Create the socket */
sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
if (sock == -1) {
perror("socket");
return 1;
}
/* Enable the socket to reuse the address */
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &reuseaddr, sizeof(int)) == -1) {
perror("setsockopt");
return 1;
}
/* Bind to the address */
if (bind(sock, res->ai_addr, res->ai_addrlen) == -1) {
perror("bind!!!!");
return 0;
}
freeaddrinfo(res);
which is only for same machine connection, changed it to:
struct sockaddr_in ip4addr;
ip4addr.sin_family= AF_INET;
ip4addr.sin_port = htons(p2);
inet_pton(PF_INET,"10.0.0.2",&ip4addr.sin_addr);
/* Create the socket */
sock=socket(PF_INET,SOCK_STREAM,0);
if (sock == -1) {
perror("socket");
return 1;
}
/* Bind to the address */
bind(sock,(struct sockaddr*)&ip4addr,sizeof ip4addr);
---------- Post added 07-20-14 at 02:45 PM ----------
and changed ip as well ofcourse
|