TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: All
from: Rob Basler
date: 1999-11-16 18:34:16
subject: sendto() doesn`t work on WSeB

I'm trying to make a UDP app that will broadcast on the local LAN to find any
available servers.  I have tested this code on Warp 4 and it works fine.  It
also works fine if the server is on WSeB, but if the client is on WSeB I get a 
TCP/IP error 10065 (No Route to Host) which is pretty strange.  
 
Suggestions?  I can ping any and all computers on my lan from any and all.  If 
I connect to the internet via dialup the client program runs, but of course is 
looking at the internet rather than my local lan to find the servers so it
doesn't find anything.
 
The code (prettified a bit.)
 
int s, tries, found;
char buf[256], buf2[256];
int nonblocking, errorcode, broadcast;
struct sockaddr_in server, client;
 
tries=5;
found=0;
while ((tries>0) && (found==0)) {
     /* Create a datagram socket in the internet domain and use the default
protocol (UDP). */
     if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
          return(-1);
     }
 
     /* Bind the UDP socket to the server address. */
     client.sin_family      = AF_INET;    /* Server is in Internet Domain */
     client.sin_port        = 0;          /* Any port in a storm */
     client.sin_addr.s_addr = INADDR_ANY; /* Server's Internet Address    */
     if (bind(s, (struct sockaddr *)&client, sizeof(client)) < 0) {
         return(-1);
     }
 
     /* Set up the server name */
     server.sin_family      = AF_INET;                   /* Internet Domain    
*/
     server.sin_port        = htons(SERVERBROADCAST_UDP); /* Server Port       
 */
     server.sin_addr.s_addr = INADDR_BROADCAST;          /* broadcast to all
servers */
 
     // Make up our message, the client name and version
     strcpy(buf,"CLIENTBXMSG10");
 
     // Set socket to allow broadcasts
     broadcast=1;
     if
(setsockopt(s,SOL_SOCKET,SO_BROADCAST,(char*)&broadcast,sizeof(broadcast))!=0) 
{
           return(-3);
     }
 
     /* Broadcast the message in buf to the server */
     if (sendto(s, buf, (strlen(buf)+1), 0, (struct sockaddr *)&server,
sizeof(server)) < 0) {
          return(-2);
     }
 
     // Set socket to non-blocking mode
     nonblocking=1;
     if (ioctl(s,FIONBIO,(caddr_t)&nonblocking,sizeof(nonblocking))!=0) {
           return(-3);
     }
 
     // Wait for response for 2 seconds.
     int32 timeout=TimeGet();
     while ((TimeElapsed(timeout)<2000) && (found * Origin: Frog Hollow Port Moody BC 604-469-0264/0284 (1:153/290)

SOURCE: echoes via The OS/2 BBS

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.