This is a discussion on strange tcp connection within the comp.unix.bsd.openbsd.misc forums, part of the OpenBSD category; --> Hi, I got a problem with a tcp server I coded in openbsd. I test this code in redhat ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hi, I got a problem with a tcp server I coded in openbsd. I test this code in redhat and freebsd and it is running fine by allowing telnet and other tcp client establish connection to it. But when I running this code in openbsd, it only allow tcp connection from within localhost. here is the code: int tcp_listen(const char *host, const char *serv, socklen_t *addrlenp) { int listenfd, n; const int on = 1; struct addrinfo hints, *res, *ressave; bzero(&hints, sizeof(struct addrinfo)); hints.ai_flags = AI_PASSIVE; hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; if ( (n = getaddrinfo(host, serv, &hints, &res)) != 0) err_quit("tcp_listen error for %s, %s: %s", host, serv, gai_strerror(n)); ressave = res; do { listenfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); if (listenfd < 0) continue; /* error, try next one */ Setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); //Setsockopt(listenfd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on)); if (bind(listenfd, res->ai_addr, res->ai_addrlen) == 0) break; /* success */ Close(listenfd); /* bind error, close and try next one */ } while ( (res = res->ai_next) != NULL); if (res == NULL) /* errno from final socket() or bind() */ err_sys("tcp_listen error for %s, %s", host, serv); Listen(listenfd, LISTENQ); if (addrlenp) } Thanks sam |
| ||||
| sam wrote: > Hi, > > I got a problem with a tcp server I coded in openbsd. I test this code > in redhat and freebsd and it is running fine by allowing telnet and > other tcp client establish connection to it. But when I running this > code in openbsd, it only allow tcp connection from within localhost. > > here is the code: > > int > tcp_listen(const char *host, const char *serv, socklen_t *addrlenp) > { > int listenfd, n; > const int on = 1; > struct addrinfo hints, *res, *ressave; > > bzero(&hints, sizeof(struct addrinfo)); > hints.ai_flags = AI_PASSIVE; > hints.ai_family = AF_UNSPEC; > hints.ai_socktype = SOCK_STREAM; > > if ( (n = getaddrinfo(host, serv, &hints, &res)) != 0) > err_quit("tcp_listen error for %s, %s: %s", > host, serv, gai_strerror(n)); > ressave = res; > > do { > listenfd = socket(res->ai_family, res->ai_socktype, > res->ai_protocol); > if (listenfd < 0) > continue; /* error, try next one */ > > Setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, > sizeof(on)); > //Setsockopt(listenfd, IPPROTO_TCP, TCP_NODELAY, &on, > sizeof(on)); > if (bind(listenfd, res->ai_addr, res->ai_addrlen) == 0) > break; /* success */ > > Close(listenfd); /* bind error, close and try > next one */ > } while ( (res = res->ai_next) != NULL); > > if (res == NULL) /* errno from final socket() or bind() */ > err_sys("tcp_listen error for %s, %s", host, serv); > > Listen(listenfd, LISTENQ); > > if (addrlenp) > > > } > > > Thanks > sam And the following netstat command shown that this tcp code is listening to Tcp6, not in Tcp: Proto Recv-Q Send-Q Local Address Foreign Address (state) tcp6 0 0 *.1111 *.* LISTEN I don't find the port 1111 appear in tcp connection. why is that happened?? Sam |