Unix C sockets: accept is listening but connection refused -


i trying develop simple unix server, not limited ipv4. however, sample code "hangs" on accept() call , when try telnet, "connection refused" on both 127.0.0.1 , ::1.

my code (i marked considered relevant /**/)

#include <string> #include <sys/types.h> #include <sys/socket.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <netdb.h> #include <unistd.h> #include <assert.h>  main(int argc, char **argv) {   struct addrinfo hi;   memset(&hi, 0, sizeof(hi));   hi.ai_family = af_unspec;   hi.ai_socktype = sock_stream;   hi.ai_flags = ai_passive;    struct addrinfo *r, *rorig;    char * port = "88";   /**/   if (0 != getaddrinfo(null, port, &hi, &r))/**/ {     perror("error getaddrinfo");     exit(exit_failure);   }    int socket_fd;   (rorig = r; r != null; r = r->ai_next) {     /**/socket_fd = socket(r->ai_family, r->ai_socktype, r->ai_protocol);/**/     if (0 != bind(socket_fd, r->ai_addr, r->ai_addrlen)) break;   }   freeaddrinfo(rorig);   if (r == nullptr) {     perror("error binding");     exit(exit_failure);   }    fprintf(stdout, "listen, fd: %d\n",socket_fd);   if (listen(socket_fd, 10) == -1) {     perror("listen error");     exit(exit_failure);   }   (;;) {     fprintf(stdout, "accept\n");     /**/int new_fd = accept(socket_fd, null, null);/**/     if (new_fd == -1) {       perror("accept error");       exit(exit_failure);     }     fprintf(stdout, "opened file descriptior %d", new_fd);   } } 

i reviewed related questions here, example unix c socket server not accepting connections none used getaddrinfo aproach , knowledge, limited ipv4.

any appreciated.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -