Re: [hlcoders] winsock question
What Windows version are you using? Maybe 9x has a bug that causes this, but I'm pretty sure Windows XP doesn't do this. Also, are you sure you don't open a socket elsewhere in the program? Also, it might be a netstat problem, not a sockets problem. Now, about the flaws in the code: - I spotted a typo (SockAdr *). That should be (sockaddr *), but I think you are doing a typedef somewhere? Else this wouldn't compile... - You forget to zero the sin_zero part of address. Failure to do so _may_ cause unwanted sideeffects. - htonl(INADDR_ANY); -- you should NOT use htonl on that constant! Jeroen ShadowLord Bogers - Original Message - From: matthew lewis [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, August 04, 2003 02:23 Subject: [hlcoders] winsock question | | I have never seen this happen. Are you sure you aren't looking at netstat | the wrong way, or that you aren't opening a TCP socket by accident? | | Jeroen ShadowLord Bogers | Here's the actual code: //- int CIrisSockets::OpenSocket ( const char *sz_ipaddr, int iPort ) { char func_name[] = CIrisSockets::OpenSocket ; // create a UDP socket. sockfd = socket(AF_INET, SOCK_DGRAM, 0); if (sockfd == SOCKET_ERROR) { PRINTF( %s: Could not get socket descripter. '%d'\n, func_name, WSAGetLastError()); return -1; } // assign an ip address and port number to the socket. address.sin_family = AF_INET; if (sz_ipaddr) address.sin_addr.s_addr = inet_addr(sz_ipaddr); else address.sin_addr.s_addr = htonl(INADDR_ANY); address.sin_port = htons(iPort); // open the new socket for business if (bind(sockfd, (SockAdr *) address, sizeof(address)) == SOCKET_ERROR) { PRINTF(%s: Couldn't bind socket. '%d'\n, func_name, WSAGetLastError()); CloseSocket(); return -1; } return 0; } // - end code --- The netstat command used was netstat -an. I searched the news groups (deja news) and found that, others have experienced the same problem, but no cause or solution was offered. This code works fine under linux. ___ To unsubscribe, edit your list preferences, or view the list archives, please visit: http://list.valvesoftware.com/mailman/listinfo/hlcoders ___ To unsubscribe, edit your list preferences, or view the list archives, please visit: http://list.valvesoftware.com/mailman/listinfo/hlcoders
Re: [hlcoders] winsock question
Here's the actual code: //- int CIrisSockets::OpenSocket ( const char *sz_ipaddr, int iPort ) { char func_name[] = CIrisSockets::OpenSocket ; // create a UDP socket. sockfd = socket(AF_INET, SOCK_DGRAM, 0); You should have... sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); ...instead. Jeffrey botman Broome ___ To unsubscribe, edit your list preferences, or view the list archives, please visit: http://list.valvesoftware.com/mailman/listinfo/hlcoders
Re: [hlcoders] winsock question
botman wrote: You should have... sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); ...instead. Why is that? Normally the protocol argument to the socket() function is set to 0 (except for raw sockets). Florian. ___ To unsubscribe, edit your list preferences, or view the list archives, please visit: http://list.valvesoftware.com/mailman/listinfo/hlcoders
Re: [hlcoders] winsock question
Why is that? Normally the protocol argument to the socket() function is set to 0 (except for raw sockets). Are you talking about Windows sockets exclusively, or all socket libraries (i.e. Linux, Unix, Solaris, OS/2, etc.)? Jeffrey botman Broome ___ To unsubscribe, edit your list preferences, or view the list archives, please visit: http://list.valvesoftware.com/mailman/listinfo/hlcoders
Re: [hlcoders] winsock question
botman wrote: Are you talking about Windows sockets exclusively, or all socket libraries (i.e. Linux, Unix, Solaris, OS/2, etc.)? 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. Florian. ___ To unsubscribe, edit your list preferences, or view the list archives, please visit: http://list.valvesoftware.com/mailman/listinfo/hlcoders
Re: [hlcoders] winsock question
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_ICMP1 /* control message protocol */ #define IPPROTO_IGMP2 /* 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; SOCKETlisten_desc; SOCKETsocket_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:\TEMPcl socket_test.c wsock32.lib C:\TEMPsocket_test CTRL-C to exit (in another window...) C:\WINDOWS\system32netstat -an | grep 1234 File STDIN: UDP0.0.0.0:1234 *:* C:\TEMPcl -D TCP socket_test.c wsock32.lib C:\TEMPsocket_test CTRL-C to exit (in another window...) C:\WINDOWS\system32netstat -an | grep 1234 File STDIN: TCPjeffb:1234 jeffb.gearboxsoftware.com:0 LISTENING C:\TEMPcl -D UCP socket_test.c wsock32.lib C:\TEMPsocket_test CTRL-C to exit (in another window...) C:\WINDOWS\system32netstat -an | grep 1234 File STDIN: UDPjeffb: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 2 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
[hlcoders] winsock question
Does anyone know why winsock2 also opens a TCP socket when you create a UDP socket? It's not hurting anything, but its very strange. (The TCP socket shows up when doing a netstat.) ___ To unsubscribe, edit your list preferences, or view the list archives, please visit: http://list.valvesoftware.com/mailman/listinfo/hlcoders
Re: [hlcoders] winsock question
I have never seen this happen. Are you sure you aren't looking at netstat the wrong way, or that you aren't opening a TCP socket by accident? Jeroen ShadowLord Bogers - Original Message - From: matthew lewis [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Sunday, August 03, 2003 17:38 Subject: [hlcoders] winsock question Does anyone know why winsock2 also opens a TCP socket when you create a UDP socket? It's not hurting anything, but its very strange. (The TCP socket shows up when doing a netstat.) ___ To unsubscribe, edit your list preferences, or view the list archives, please visit: http://list.valvesoftware.com/mailman/listinfo/hlcoders ___ To unsubscribe, edit your list preferences, or view the list archives, please visit: http://list.valvesoftware.com/mailman/listinfo/hlcoders
[hlcoders] winsock question
| | I have never seen this happen. Are you sure you aren't looking at netstat | the wrong way, or that you aren't opening a TCP socket by accident? | | Jeroen ShadowLord Bogers | Here's the actual code: //- int CIrisSockets::OpenSocket ( const char *sz_ipaddr, int iPort ) { char func_name[] = CIrisSockets::OpenSocket ; // create a UDP socket. sockfd = socket(AF_INET, SOCK_DGRAM, 0); if (sockfd == SOCKET_ERROR) { PRINTF( %s: Could not get socket descripter. '%d'\n, func_name, WSAGetLastError()); return -1; } // assign an ip address and port number to the socket. address.sin_family = AF_INET; if (sz_ipaddr) address.sin_addr.s_addr = inet_addr(sz_ipaddr); else address.sin_addr.s_addr = htonl(INADDR_ANY); address.sin_port = htons(iPort); // open the new socket for business if (bind(sockfd, (SockAdr *) address, sizeof(address)) == SOCKET_ERROR) { PRINTF(%s: Couldn't bind socket. '%d'\n, func_name, WSAGetLastError()); CloseSocket(); return -1; } return 0; } // - end code --- The netstat command used was netstat -an. I searched the news groups (deja news) and found that, others have experienced the same problem, but no cause or solution was offered. This code works fine under linux. ___ To unsubscribe, edit your list preferences, or view the list archives, please visit: http://list.valvesoftware.com/mailman/listinfo/hlcoders