> Generally speaking. I know it for sure for most Unix type OSes,
> i.e. Linux, Solaris, Irix, *BSD. I know that it also works for
> Windows since I've used it there, too. But I'm no Windows
> programmer, that's why I'm asking.
I dunno, I've just always specified the protocol in the socket() function.
FYI, here's the #defines from the Windows winsock.h file...
/*
* Protocols
*/
#define IPPROTO_IP 0 /* dummy for IP */
#define IPPROTO_ICMP 1 /* control message protocol
*/
#define IPPROTO_IGMP 2 /* group management protocol
*/
#define IPPROTO_GGP 3 /* gateway^2 (deprecated) */
#define IPPROTO_TCP 6 /* tcp */
#define IPPROTO_PUP 12 /* pup */
#define IPPROTO_UDP 17 /* user datagram protocol */
#define IPPROTO_IDP 22 /* xns idp */
#define IPPROTO_ND 77 /* UNOFFICIAL net disk proto
*/
#define IPPROTO_RAW 255 /* raw IP packet */
#define IPPROTO_MAX 256
I tried making a little .c program that opens the socket specifying TCP, UDP
and 0 in the socket protocol parameter...
//
// socket_test.c - To compile using Microsoft Visual C++ use:
// cl socket_test.c wsock32.lib
// (or) cl -D TCP socket_test.c wsock32.lib
// (or) cl -D UDP socket_test.c wsock32.lib
//
#include <stdio.h>
#include <winsock.h>
void main(int argc, char *argv[])
{
WSADATA WSAData;
SOCKET listen_desc;
SOCKET socket_desc;
SOCKADDR_IN local_sin;
SOCKADDR acc_sin;
int sin_length;
char buffer[1];
printf("<CTRL-C> to exit\n");
// start up the Windows Sockets Interface...
if (WSAStartup(0x0101, &WSAData))
{
printf("Can't start Sockets Interface!\n");
return;
}
#if TCP
listen_desc = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
#elif UDP
listen_desc = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
#else
listen_desc = socket(AF_INET, SOCK_DGRAM, 0);
#endif
if (listen_desc == INVALID_SOCKET)
{
printf("Can't create Server socket!: error=%d\n", WSAGetLastError());
return;
}
local_sin.sin_family = AF_INET;
local_sin.sin_addr.s_addr = INADDR_ANY;
local_sin.sin_port = htons(1234);
if (bind(listen_desc, (struct sockaddr *)&local_sin, sizeof(local_sin))
== SOCKET_ERROR)
{
printf("error from bind(): error=%d\n", WSAGetLastError());
return;
}
#if TCP
if (listen(listen_desc, 1) < 0)
{
printf("error from listen(): error=%d\n", WSAGetLastError());
return;
}
sin_length = sizeof(acc_sin);
if ((socket_desc = accept(listen_desc, &acc_sin, &sin_length)) ==
INVALID_SOCKET)
{
printf("error from accept(): error=%d\n", WSAGetLastError());
return;
}
closesocket(socket_desc);
#elif UDP
// can't listen() on UDP sockets...
if (recvfrom(listen_desc, buffer, 1, 0, NULL, NULL) == SOCKET_ERROR)
{
printf("error from recvfrom(): error=%d\n", WSAGetLastError());
return;
}
#else
if (recv(listen_desc, buffer, 1, 0) == SOCKET_ERROR)
{
printf("error from recv(): error=%d\n", WSAGetLastError());
return;
}
#endif
closesocket(listen_desc);
}
...The output of "netstat -a | grep 1234" gives this on Windows XP...
C:\TEMP>cl socket_test.c wsock32.lib
C:\TEMP>socket_test
<CTRL-C> to exit
(in another window...)
C:\WINDOWS\system32>netstat -an | grep 1234
File STDIN:
UDP 0.0.0.0:1234 *:*
C:\TEMP>cl -D TCP socket_test.c wsock32.lib
C:\TEMP>socket_test
<CTRL-C> to exit
(in another window...)
C:\WINDOWS\system32>netstat -an | grep 1234
File STDIN:
TCP jeffb:1234 jeffb.gearboxsoftware.com:0 LISTENING
C:\TEMP>cl -D UCP socket_test.c wsock32.lib
C:\TEMP>socket_test
<CTRL-C> to exit
(in another window...)
C:\WINDOWS\system32>netstat -an | grep 1234
File STDIN:
UDP jeffb:1234 *:*
...so both 0 and IPPROTO_UDP only shows IP listening on UDP ports (not on
UDP and TCP ports).
I wonder if the port that was picked already had something listening on the
TCP interface while the application was listening on the UDP interface.
You might try changing your listen port number to something more unique
(like 29999 or something fairly high up).
Jeffrey "botman" Broome
_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders