public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Mumit Khan <khan@xraylith.wisc.EDU>
To: "Robert A. Mackie" <robert_mackie@mail.com>
Cc: cygwin@sourceware.cygnus.com
Subject: Re: posix style DGRAM sockets with cygwin.dll
Date: Tue, 24 Aug 1999 18:27:00 -0000	[thread overview]
Message-ID: <199908250127.UAA28632@mercury.xraylith.wisc.edu> (raw)
In-Reply-To: <37C23EE9.92525BD@mail.com>

"Robert A. Mackie" <robert_mackie@mail.com> writes:
> 
> I'm trying to get a very simple UDP example ported to cygwin as a
> starting point for some real code I expect to develop.  Everything
> compiles and links, but the sockets don't communicate.  When built for
> unix the same code works fine.  (unless I've introduced some small bug
> trying to get it to work under cygwin.)  I notice I'm not the first to
> say something like this.  The last person was using the -no-cygwin
> option and was told to call WSAStartup.  I read as much documentation as
> I could find.  It looked to me like that was not necessary when using
> the posix calls, rather than the winsock calls.  (Maybe I'm wrong ?)

If you're using -mno-cygwin, you're using Windows sockets (and you need
WSAStartup); if you're *not* using -mno-cygwin, you're using POSIX sockets
and obviously don't need the windows hacks, er features.

> If I do need to initialize winsock explicitly, could you help me with a
> couple of details? The only place that I see WSAStartup and WSACleanup
> defined is in <Windows32/Sockets.h>.  This file seems to be set up for
> an MSC compiler, and includes a bunch of other similar headers.  When I
> include any of them and the standard headers I'm used to, I get all
> sorts of re-definition collisions between the headers.  When I include
> them without the standard headers, things like strerror aren't defined.

You include winsock.h, not the internal headers, but *only* if you're using
Windows sockets. If you're using Cygwin runtime, use the POSIX specs and
forget about the windows headers (Cygwin runtime will do the right thing).

It's quite unclear from your message what runtime you're trying to use
and so on. If you could elaborate, we could try to help. 

As far as your code is concerned, there is at least one blatant bug I
see right away -- 

  server_address.sin_port        = htonl(SERVER_UDP_PORT);
                                   ^^^^^ (should be htons)

likewise in the other case. Just remember that sin_addr is htonl and
sin_port is htons and life would be a lot easier.

Perhaps you ought to check over your code a bit more and try again.

Regards,
Mumit


--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com

WARNING: multiple messages have this Message-ID
From: Mumit Khan <khan@xraylith.wisc.EDU>
To: "Robert A. Mackie" <robert_mackie@mail.com>
Cc: cygwin@sourceware.cygnus.com
Subject: Re: posix style DGRAM sockets with cygwin.dll
Date: Tue, 31 Aug 1999 23:49:00 -0000	[thread overview]
Message-ID: <199908250127.UAA28632@mercury.xraylith.wisc.edu> (raw)
Message-ID: <19990831234900.mJC3kG5C_jWvUPVSVKlxcfsVyHB4v42aOaWYw_H70nI@z> (raw)
In-Reply-To: <37C23EE9.92525BD@mail.com>

"Robert A. Mackie" <robert_mackie@mail.com> writes:
> 
> I'm trying to get a very simple UDP example ported to cygwin as a
> starting point for some real code I expect to develop.  Everything
> compiles and links, but the sockets don't communicate.  When built for
> unix the same code works fine.  (unless I've introduced some small bug
> trying to get it to work under cygwin.)  I notice I'm not the first to
> say something like this.  The last person was using the -no-cygwin
> option and was told to call WSAStartup.  I read as much documentation as
> I could find.  It looked to me like that was not necessary when using
> the posix calls, rather than the winsock calls.  (Maybe I'm wrong ?)

If you're using -mno-cygwin, you're using Windows sockets (and you need
WSAStartup); if you're *not* using -mno-cygwin, you're using POSIX sockets
and obviously don't need the windows hacks, er features.

> If I do need to initialize winsock explicitly, could you help me with a
> couple of details? The only place that I see WSAStartup and WSACleanup
> defined is in <Windows32/Sockets.h>.  This file seems to be set up for
> an MSC compiler, and includes a bunch of other similar headers.  When I
> include any of them and the standard headers I'm used to, I get all
> sorts of re-definition collisions between the headers.  When I include
> them without the standard headers, things like strerror aren't defined.

You include winsock.h, not the internal headers, but *only* if you're using
Windows sockets. If you're using Cygwin runtime, use the POSIX specs and
forget about the windows headers (Cygwin runtime will do the right thing).

It's quite unclear from your message what runtime you're trying to use
and so on. If you could elaborate, we could try to help. 

As far as your code is concerned, there is at least one blatant bug I
see right away -- 

  server_address.sin_port        = htonl(SERVER_UDP_PORT);
                                   ^^^^^ (should be htons)

likewise in the other case. Just remember that sin_addr is htonl and
sin_port is htons and life would be a lot easier.

Perhaps you ought to check over your code a bit more and try again.

Regards,
Mumit


--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com

  reply	other threads:[~1999-08-24 18:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-08-23 23:39 Robert A. Mackie
1999-08-24 18:27 ` Mumit Khan [this message]
1999-08-25 14:39   ` Robert A. Mackie
1999-08-31 23:49     ` Robert A. Mackie
1999-08-31 23:49   ` Mumit Khan
1999-08-31 23:49 ` Robert A. Mackie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=199908250127.UAA28632@mercury.xraylith.wisc.edu \
    --to=khan@xraylith.wisc.edu \
    --cc=cygwin@sourceware.cygnus.com \
    --cc=robert_mackie@mail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).