mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-26 02:01:03 +00:00
probe upgrades
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@6056 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
7d5a5bcc36
commit
f79a356d74
2 changed files with 125 additions and 30 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
Tue Feb 22 07:31:00 2000 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||||
|
|
||||||
|
* Tools/gdomap.c: Reinstated '-p' flag to disable probes and added
|
||||||
|
code to do probes by broadcast to the local network rather than by
|
||||||
|
probing machines individually if possible.
|
||||||
|
|
||||||
2000-02-20 Matthias Klose <doko@cs.tu-berlin.de>
|
2000-02-20 Matthias Klose <doko@cs.tu-berlin.de>
|
||||||
|
|
||||||
* Tools/gdomap.c (main): Add -I <file> option to write the pid to.
|
* Tools/gdomap.c (main): Add -I <file> option to write the pid to.
|
||||||
|
|
101
Tools/gdomap.c
101
Tools/gdomap.c
|
@ -95,6 +95,7 @@
|
||||||
|
|
||||||
typedef unsigned char *uptr;
|
typedef unsigned char *uptr;
|
||||||
int debug = 0; /* Extra debug logging. */
|
int debug = 0; /* Extra debug logging. */
|
||||||
|
int nobcst = 0; /* turn off broadcast probing. */
|
||||||
int nofork = 0; /* turn off fork() for debugging. */
|
int nofork = 0; /* turn off fork() for debugging. */
|
||||||
int noprobe = 0; /* turn off probe for unknown servers. */
|
int noprobe = 0; /* turn off probe for unknown servers. */
|
||||||
int interval = 600; /* Minimum time (sec) between probes. */
|
int interval = 600; /* Minimum time (sec) between probes. */
|
||||||
|
@ -184,6 +185,8 @@ static plentry *plist = 0;
|
||||||
*/
|
*/
|
||||||
int interfaces = 0; /* Number of interfaces. */
|
int interfaces = 0; /* Number of interfaces. */
|
||||||
struct in_addr *addr; /* Address of each interface. */
|
struct in_addr *addr; /* Address of each interface. */
|
||||||
|
unsigned char *bcok; /* Broadcast OK for interface? */
|
||||||
|
struct in_addr *bcst; /* Broadcast for interface. */
|
||||||
struct in_addr *mask; /* Netmask of each interface. */
|
struct in_addr *mask; /* Netmask of each interface. */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -625,7 +628,7 @@ prb_tim(long when)
|
||||||
when -= 1800;
|
when -= 1800;
|
||||||
for (i = prb_used - 1; i >= 0; i--)
|
for (i = prb_used - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
if (prb[i]->when < when && prb[i]->when < last_probe)
|
if (noprobe == 0 && prb[i]->when < when && prb[i]->when < last_probe)
|
||||||
{
|
{
|
||||||
prb_del(&prb[i]->sin);
|
prb_del(&prb[i]->sin);
|
||||||
}
|
}
|
||||||
|
@ -751,7 +754,13 @@ init_iface()
|
||||||
close(desc);
|
close(desc);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
if (addr != 0) free(addr);
|
||||||
addr = (struct in_addr*)malloc(num_iface*IASIZE);
|
addr = (struct in_addr*)malloc(num_iface*IASIZE);
|
||||||
|
if (bcok != 0) free(bcok);
|
||||||
|
bcok = (char*)malloc(num_iface*sizeof(char));
|
||||||
|
if (bcst != 0) free(bcst);
|
||||||
|
bcst = (struct in_addr*)malloc(num_iface*IASIZE);
|
||||||
|
if (mask != 0) free(mask);
|
||||||
mask = (struct in_addr*)malloc(num_iface*IASIZE);
|
mask = (struct in_addr*)malloc(num_iface*IASIZE);
|
||||||
|
|
||||||
final = (struct ifreq*)&ifc.ifc_buf[ifc.ifc_len];
|
final = (struct ifreq*)&ifc.ifc_buf[ifc.ifc_len];
|
||||||
|
@ -764,6 +773,17 @@ init_iface()
|
||||||
}
|
}
|
||||||
else if (ifreq.ifr_flags & IFF_UP)
|
else if (ifreq.ifr_flags & IFF_UP)
|
||||||
{ /* interface is up */
|
{ /* interface is up */
|
||||||
|
int broadcast = 0;
|
||||||
|
int pointopoint = 0;
|
||||||
|
|
||||||
|
if (ifreq.ifr_flags & IFF_BROADCAST)
|
||||||
|
{
|
||||||
|
broadcast = 1;
|
||||||
|
}
|
||||||
|
if (ifreq.ifr_flags & IFF_POINTOPOINT)
|
||||||
|
{
|
||||||
|
pointopoint = 1;
|
||||||
|
}
|
||||||
if (ioctl(desc, SIOCGIFADDR, (char *)&ifreq) < 0)
|
if (ioctl(desc, SIOCGIFADDR, (char *)&ifreq) < 0)
|
||||||
{
|
{
|
||||||
perror("SIOCGIFADDR");
|
perror("SIOCGIFADDR");
|
||||||
|
@ -782,6 +802,33 @@ init_iface()
|
||||||
}
|
}
|
||||||
addr[interfaces] =
|
addr[interfaces] =
|
||||||
((struct sockaddr_in *)&ifreq.ifr_addr)->sin_addr;
|
((struct sockaddr_in *)&ifreq.ifr_addr)->sin_addr;
|
||||||
|
bcok[interfaces] = (broadcast | pointopoint);
|
||||||
|
if (pointopoint)
|
||||||
|
{
|
||||||
|
if (ioctl(desc, SIOCGIFDSTADDR, (char*)&ifreq) < 0)
|
||||||
|
{
|
||||||
|
perror("SIOCGIFDSTADDR");
|
||||||
|
bcok[interfaces] = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bcst[interfaces]
|
||||||
|
= ((struct sockaddr_in *)&ifreq.ifr_dstaddr)->sin_addr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (ioctl(desc, SIOCGIFBRDADDR, (char*)&ifreq) < 0)
|
||||||
|
{
|
||||||
|
perror("SIOCGIFBRDADDR");
|
||||||
|
bcok[interfaces] = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bcst[interfaces]
|
||||||
|
= ((struct sockaddr_in*)&ifreq.ifr_broadaddr)->sin_addr;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (ioctl(desc, SIOCGIFNETMASK, (char *)&ifreq) < 0)
|
if (ioctl(desc, SIOCGIFNETMASK, (char *)&ifreq) < 0)
|
||||||
{
|
{
|
||||||
perror("SIOCGIFNETMASK");
|
perror("SIOCGIFNETMASK");
|
||||||
|
@ -1035,6 +1082,15 @@ init_ports()
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Warning - unable to set 're-use' on UDP socket\n");
|
fprintf(stderr, "Warning - unable to set 're-use' on UDP socket\n");
|
||||||
}
|
}
|
||||||
|
if (nobcst == 0)
|
||||||
|
{
|
||||||
|
r = 1;
|
||||||
|
if ((setsockopt(udp_desc,SOL_SOCKET,SO_BROADCAST,(char*)&r,sizeof(r)))<0)
|
||||||
|
{
|
||||||
|
nobcst++;
|
||||||
|
fprintf(stderr, "Warning - unable to use 'broadcast' for probes\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
if ((r = fcntl(udp_desc, F_GETFL, 0)) >= 0)
|
if ((r = fcntl(udp_desc, F_GETFL, 0)) >= 0)
|
||||||
{
|
{
|
||||||
r |= NBLK_OPT;
|
r |= NBLK_OPT;
|
||||||
|
@ -1192,6 +1248,10 @@ init_probe()
|
||||||
int iface;
|
int iface;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
if (noprobe > 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (debug > 2)
|
if (debug > 2)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Initiating probe requests.\n");
|
fprintf(stderr, "Initiating probe requests.\n");
|
||||||
|
@ -1224,13 +1284,15 @@ init_probe()
|
||||||
|
|
||||||
for (i = 0; i < nlist_size; i++)
|
for (i = 0; i < nlist_size; i++)
|
||||||
{
|
{
|
||||||
|
int broadcast = 0;
|
||||||
|
int elen = 0;
|
||||||
struct in_addr *other;
|
struct in_addr *other;
|
||||||
int elen;
|
|
||||||
struct in_addr sin;
|
struct in_addr sin;
|
||||||
int high;
|
int high;
|
||||||
int low;
|
int low;
|
||||||
unsigned long net;
|
unsigned long net;
|
||||||
int j;
|
int j;
|
||||||
|
struct in_addr b;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Build up a list of addresses that we serve on this network.
|
* Build up a list of addresses that we serve on this network.
|
||||||
|
@ -1238,6 +1300,16 @@ init_probe()
|
||||||
for (iface = 0; iface < interfaces; iface++)
|
for (iface = 0; iface < interfaces; iface++)
|
||||||
{
|
{
|
||||||
if ((addr[iface].s_addr & mask[iface].s_addr) == nlist[i])
|
if ((addr[iface].s_addr & mask[iface].s_addr) == nlist[i])
|
||||||
|
{
|
||||||
|
if (bcok[iface])
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Simple broadcast for this address.
|
||||||
|
*/
|
||||||
|
b.s_addr = bcst[iface].s_addr;
|
||||||
|
broadcast = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
unsigned long ha; /* full host address. */
|
unsigned long ha; /* full host address. */
|
||||||
unsigned long hm; /* full netmask. */
|
unsigned long hm; /* full netmask. */
|
||||||
|
@ -1264,6 +1336,7 @@ init_probe()
|
||||||
low = ha & hm & 255; /* low end of subnet. */
|
low = ha & hm & 255; /* low end of subnet. */
|
||||||
high = low | (255 & ~hm); /* high end of subnet. */
|
high = low | (255 & ~hm); /* high end of subnet. */
|
||||||
elen = other_addresses_on_net(sin, &other);
|
elen = other_addresses_on_net(sin, &other);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1298,6 +1371,13 @@ init_probe()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (broadcast)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Now broadcast probe on this network.
|
||||||
|
*/
|
||||||
|
queue_probe(&b, &sin, 0, 0, 0);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
@ -1652,6 +1732,11 @@ handle_recv()
|
||||||
{
|
{
|
||||||
fprintf(stderr, "recvfrom %s\n", inet_ntoa(addr->sin_addr));
|
fprintf(stderr, "recvfrom %s\n", inet_ntoa(addr->sin_addr));
|
||||||
}
|
}
|
||||||
|
if (is_local_host(addr->sin_addr) == 1)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "recvfrom packet from self discarded\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
handle_request(udp_desc);
|
handle_request(udp_desc);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -2860,7 +2945,7 @@ int
|
||||||
main(int argc, char** argv)
|
main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
extern char *optarg;
|
extern char *optarg;
|
||||||
char *options = "CHL:M:P:R:T:U:a:c:dfi:pI:";
|
char *options = "CHI:L:M:P:R:T:U:a:bc:dfi:p";
|
||||||
int c;
|
int c;
|
||||||
int ptype = GDO_TCP_GDO;
|
int ptype = GDO_TCP_GDO;
|
||||||
int port = 0;
|
int port = 0;
|
||||||
|
@ -2886,6 +2971,7 @@ main(int argc, char** argv)
|
||||||
printf("GNU Distributed Objects name server\n");
|
printf("GNU Distributed Objects name server\n");
|
||||||
printf("-C help about configuration\n");
|
printf("-C help about configuration\n");
|
||||||
printf("-H general help\n");
|
printf("-H general help\n");
|
||||||
|
printf("-I pid file to write pid\n");
|
||||||
printf("-L name perform lookup for name then quit.\n");
|
printf("-L name perform lookup for name then quit.\n");
|
||||||
printf("-M name machine name for L (default local)\n");
|
printf("-M name machine name for L (default local)\n");
|
||||||
printf("-P number port number required for R option.\n");
|
printf("-P number port number required for R option.\n");
|
||||||
|
@ -2895,12 +2981,12 @@ main(int argc, char** argv)
|
||||||
printf(" tcp_foreign, udp_foreign.\n");
|
printf(" tcp_foreign, udp_foreign.\n");
|
||||||
printf("-U name unregister name locally then quit.\n");
|
printf("-U name unregister name locally then quit.\n");
|
||||||
printf("-a file use config file for interface list.\n");
|
printf("-a file use config file for interface list.\n");
|
||||||
|
printf("-p disable udp broadcast for probe\n");
|
||||||
printf("-c file use config file for probe.\n");
|
printf("-c file use config file for probe.\n");
|
||||||
printf("-d extra debug logging.\n");
|
printf("-d extra debug logging.\n");
|
||||||
printf("-f avoid fork() to make debugging easy\n");
|
printf("-f avoid fork() to make debugging easy\n");
|
||||||
printf("-i seconds re-probe at this interval (roughly), min 60\n");
|
printf("-i seconds re-probe at this interval (roughly), min 60\n");
|
||||||
printf("-p obsolete no-op\n");
|
printf("-p disable probing for other servers\n");
|
||||||
printf("-I pid file to write pid\n");
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|
||||||
|
@ -3006,6 +3092,10 @@ printf(
|
||||||
load_iface(optarg);
|
load_iface(optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'b':
|
||||||
|
nobcst++;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'c':
|
case 'c':
|
||||||
{
|
{
|
||||||
FILE *fptr = fopen(optarg, "r");
|
FILE *fptr = fopen(optarg, "r");
|
||||||
|
@ -3170,7 +3260,6 @@ printf(
|
||||||
if (pidfile) {
|
if (pidfile) {
|
||||||
{
|
{
|
||||||
FILE *fptr = fopen(pidfile, "a");
|
FILE *fptr = fopen(pidfile, "a");
|
||||||
int pid;
|
|
||||||
|
|
||||||
if (fptr == 0)
|
if (fptr == 0)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue