[Linux-decnet-commit] CVS: dnprogs/multinet multinet.c,1.8,1.9
Brought to you by:
chrissie_c,
ph3-der-loewe
From: Christine C. <chr...@us...> - 2008-08-20 12:07:39
|
Update of /cvsroot/linux-decnet/dnprogs/multinet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21376 Modified Files: multinet.c Log Message: make SIGHUP re-read the remote IP address Index: multinet.c =================================================================== RCS file: /cvsroot/linux-decnet/dnprogs/multinet/multinet.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -r1.8 -r1.9 *** multinet.c 7 Apr 2006 13:00:41 -0000 1.8 --- multinet.c 20 Aug 2008 12:07:35 -0000 1.9 *************** *** 1,4 **** ! /****************************************************************************** ! (c) 2006 P.J. Caulfield pa...@de... This program is free software; you can redistribute it and/or modify --- 1,4 ---- ! /********************************************************************************** ! (c) 2006,2008 Christine Caulfield chr...@go... This program is free software; you can redistribute it and/or modify *************** *** 11,15 **** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. ! ******************************************************************************* --- 11,15 ---- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. ! ******************************************************************************** *************** *** 51,54 **** --- 51,55 ---- static int got_remote_addr; static unsigned char remote_decnet_addr[2]; + static char *remote_host_name; static int got_verification; *************** *** 62,68 **** --- 63,104 ---- static time_t last_ip_packet; static sig_atomic_t running; + static sig_atomic_t reload_config; #define DUMP_MAX 1024 + /* Resolve the remote IP host name. + * Called at startup and on receipt of SIGHUP + */ + static int lookup_name(void) + { + struct addrinfo *ainfo; + struct addrinfo ahints; + int res; + + memset(&ahints, 0, sizeof(ahints)); + ahints.ai_socktype = SOCK_DGRAM; + ahints.ai_protocol = IPPROTO_UDP; + + /* Lookup the nodename address */ + if ( (res=getaddrinfo(remote_host_name, NULL, &ahints, &ainfo)) ) + { + fprintf(stderr, "Can't resolve name '%s': %s\n", remote_host_name, gai_strerror(res)); + return 2; + } + + memcpy(&remote_addr, ainfo->ai_addr, sizeof(struct sockaddr_in)); + remote_addr.sin_family = AF_INET; + remote_addr.sin_port = htons(port); + + return 0; + } + + static void do_sighup(int sig) + { + if (verbose) + fprintf(stderr, "Got sighup, re-reading config\n"); + reload_config = 1; + } + static void do_shutdown(int sig) { *************** *** 377,381 **** if (len <= 0) return; ! /* We get local HELLOs from time to time so this shoud ensure that we're not flooding the IP link with dodgy UDP continously */ --- 413,417 ---- if (len <= 0) return; ! /* We get local HELLOs from time to time so this should ensure that we're not flooding the IP link with dodgy UDP continously */ *************** *** 455,459 **** /* Configure the interface. ! * Sigh, this maybe should be sone using sysctl but that interface * is probably worse than poking values into /proc ! */ --- 491,495 ---- /* Configure the interface. ! * Sigh, this maybe should be done using sysctl but that interface * is probably worse than poking values into /proc ! */ *************** *** 534,538 **** { ! printf("Usage: %s [options] <local-decnet-addr> <remote-host>\n", cmd); printf("eg %s -D 3.2 zarqon\n\n", cmd); --- 570,574 ---- { ! printf("Usage: %s [options] <local-decnet-addr> <remote-IP-host>\n", cmd); printf("eg %s -D 3.2 zarqon\n\n", cmd); *************** *** 555,561 **** unsigned short addr; int make_default = 0; - struct addrinfo *ainfo; - struct addrinfo ahints; - int res; int opt; --- 591,594 ---- *************** *** 640,661 **** /* Check remote address is valid */ optind++; ! memset(&ahints, 0, sizeof(ahints)); ! ahints.ai_socktype = SOCK_DGRAM; ! ahints.ai_protocol = IPPROTO_UDP; ! ! /* Lookup the nodename address */ ! if ( (res=getaddrinfo(argv[optind], NULL, &ahints, &ainfo)) ) ! { ! fprintf(stderr, "Can't resolve name '%s': %s\n", argv[optind], gai_strerror(res)); return 2; - } - - memcpy(&remote_addr, ainfo->ai_addr, sizeof(struct sockaddr_in)); - remote_addr.sin_family = AF_INET; - remote_addr.sin_port = htons(port); signal(SIGINT, do_shutdown); signal(SIGTERM, do_shutdown); /* Initialise network ports */ --- 673,684 ---- /* Check remote address is valid */ optind++; + remote_host_name = argv[optind]; ! if (!lookup_name()) return 2; signal(SIGINT, do_shutdown); signal(SIGTERM, do_shutdown); + signal(SIGHUP, do_sighup); /* Initialise network ports */ *************** *** 685,691 **** if (status == -1 && errno != EINTR) { ! perror("poll"); exit(1); } if (pfds[0].revents & POLLIN) read_ip(); --- 708,721 ---- if (status == -1 && errno != EINTR) { ! perror("poll error"); exit(1); } + + if (reload_config) + { + lookup_name(); + reload_config = 0; + } + if (pfds[0].revents & POLLIN) read_ip(); |