public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Unable to Accept TCP Connection
@ 2018-04-21 21:44 R0b0t1
  2018-04-21 23:20 ` Mark Geisert
  0 siblings, 1 reply; 3+ messages in thread
From: R0b0t1 @ 2018-04-21 21:44 UTC (permalink / raw)
  To: cygwin

The following never prints "Hello, world!"


struct sboot_state {
    struct sockaddr_in haddr;
    struct sockaddr caddr;
    socklen_t clen;
    int sfd, cfd;
} state = { 0 };

state.haddr.sin_family = AF_INET;
state.haddr.sin_port = 2200;
state.haddr.sin_addr.s_addr = INADDR_ANY;

state.sfd = socket(AF_INET, SOCK_STREAM, 0);
if (state.sfd < 0) {
  perror("socket");
  exit(1);
}

if (bind(state.sfd, (struct sockaddr *)&state.haddr,
  sizeof(state.haddr)) < 0) {
  perror("bind");
  exit(1);
}

listen(state.sfd, 5);
state.clen = sizeof(state.caddr);
state.cfd = accept(state.sfd, (struct sockaddr *)&state.caddr,
  &state.clen);
if (state.cfd < 0) {
  perror("accept");
  exit(1);
}

printf("Hello, world!\n");


The program was allowed through the Windows firewall. Any hints?
Attempting to connect with netcat immediately fails.

Cheers,
     R0b0t1

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Unable to Accept TCP Connection
  2018-04-21 21:44 Unable to Accept TCP Connection R0b0t1
@ 2018-04-21 23:20 ` Mark Geisert
  2018-04-22  2:11   ` R0b0t1
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Geisert @ 2018-04-21 23:20 UTC (permalink / raw)
  To: cygwin

R0b0t1 wrote:
> The following never prints "Hello, world!"
>
>
> struct sboot_state {
>     struct sockaddr_in haddr;
>     struct sockaddr caddr;
>     socklen_t clen;
>     int sfd, cfd;
> } state = { 0 };
>
> state.haddr.sin_family = AF_INET;
> state.haddr.sin_port = 2200;

You can use the Windows 'netstat' to see listening connections.  See if your app 
shows up on port 2200.  But I suspect you need an htons(2200) on the assignment 
to sin_port.

..mark


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Unable to Accept TCP Connection
  2018-04-21 23:20 ` Mark Geisert
@ 2018-04-22  2:11   ` R0b0t1
  0 siblings, 0 replies; 3+ messages in thread
From: R0b0t1 @ 2018-04-22  2:11 UTC (permalink / raw)
  To: cygwin

On Sat, Apr 21, 2018 at 6:20 PM, Mark Geisert <mark@maxrnd.com> wrote:
> R0b0t1 wrote:
>>
>> The following never prints "Hello, world!"
>>
>>
>> struct sboot_state {
>>     struct sockaddr_in haddr;
>>     struct sockaddr caddr;
>>     socklen_t clen;
>>     int sfd, cfd;
>> } state = { 0 };
>>
>> state.haddr.sin_family = AF_INET;
>> state.haddr.sin_port = 2200;
>
>
> You can use the Windows 'netstat' to see listening connections.  See if your
> app shows up on port 2200.  But I suspect you need an htons(2200) on the
> assignment to sin_port.
>

Thanks, I thought something was missing. Wasn't sure what.

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-04-22  2:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-21 21:44 Unable to Accept TCP Connection R0b0t1
2018-04-21 23:20 ` Mark Geisert
2018-04-22  2:11   ` R0b0t1

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).