Unix Technical Forum

strange tcp connection

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 ...


Go Back   Unix Technical Forum > Unix Operating Systems > OpenBSD > comp.unix.bsd.openbsd.misc

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-16-2008, 05:30 AM
sam
 
Posts: n/a
Default strange tcp connection

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-16-2008, 05:30 AM
sam
 
Posts: n/a
Default Re: strange tcp connection

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:13 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com