[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Linux for help (fwd)



-----BEGIN PGP SIGNED MESSAGE-----


I found this in my Red Hat Linux User's FAQ inbox today...  I just found
it rather humorus that someone thought that because I have a web site I
could help them with this particular problem.


- ---------- Forwarded message ----------
From: Shu Xiao <xiao@usc.edu>
To: rhlufaq@pobox.com
Date: Mon, 14 Jun 1999 15:46:22 -0700
Subject: Linux for help

Hi,

I get stuck by a problem with our Linux-Pentinum
cluster problem. 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);

}



-----BEGIN PGP SIGNATURE-----
Version: 2.6.2

iQCVAwUBN2WhdjM3jpXy1kJtAQHTywQAiiv2wGAJlVukFR+4yP95uEPn5PzOKsP3
/kHnBSPn9W3bA6eIW5q/1VuLFw+qJz4vJWr6X1uBAgrpe5jbtdW9hN4iEK1aSE1y
XTpZxi6B+7rsJcIBesD6psQZf1kWhkUOkklsQrSWQd9UaSNqwJyI+rxXxA0PZVie
SA7uQO24BEQ=
=lnAd
-----END PGP SIGNATURE-----