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