Hi, Dear All!

I get stuck by a problem with our Linux-Pentinum
cluster system. Essentially,  what is botherring us
is that the UDP socket program we wrote always
fails to connect, with the error response "Connect
Refused". But all the IP uitlities provided works fine,
including ping, traceroute, netperf, etc.

Our configure is 9 Linux(Redhat 6.0) nodes connected
with Ethernet switch. One node is special, with connection
to the outside Internet and internal node as well.
All the remaining node use reserved IP address(192.168.1.x).
On the gateway node, we test UDP connection by a small
socket porgram shown below.

This code runs and gets the date and time when I
connects to outside server, but fails to get response from
the internal nodes. It prints out "Connect Refused",
which stuck us since there is no reason for this kind of
failure. I suspect the problem is in the confiugration.
Currently we disable the NIS daemon.

Any advice is highly appreciated. Thanks ahead.

Shu Xiao






==================================================
/* inetDaytime - Connecting to "daytime" datagram daemon in other host*/

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>

#define BUFSZ 256
#define SERVICE "daytime"

main(int argc, char **argv)
{

 int s,n,len;
 char buf[BUFSZ];

 struct hostent *hp;
 struct servent *sp;
 struct sockaddr sin;

 if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
 /* acquire a socket */
  perror("socket");
  exit(1);
 }

 /* check the port number of the serverwork byte order */
 if ((sp = getserverbyname(SERVICE, "udp")) == NULL) {
  fprintf(stderr, "%s/udp: unknown service. \n", SERVICE);
  exit(1);
 }

 while (--argc){

  if ((hp = gethostbyname(*++argv)) == NULL) {
   /* look for host network address */
   fprintf(stderr,"%s: host unknown.\n", *argv);
   continue;
  }

  /* set server address on the remote host */
  sin.sinfamily = AF_INET;
  sin_sin_port = sp->s_port;
  bcopy(hp->h_addr, &sin.sin_addr, hp->h_length);

  printf("%s:\t", *argv);
  fflush(stdout);

  /* send a datagram to server*/
  if (sendto(s,buf,BUFSZ,0,&sin,sizeof(sin)) <0){
   perror("sendto");
   continue;
  }

  /* receive a datagram */
  len = sizeof(sin);
  n = recvfrom(s, buf, sizeof(buf), 0, &sin, &len);

  if (n<0) {
   perror("recvfrom");
   continue;
  }

  buf[n] = '\0';
  printf("%s\n", buf);
 }


 close(s);
 exit(0);

}





-
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to [EMAIL PROTECTED]

Reply via email to