if returning a pointer to something on the stack, make it a static.

This commit is contained in:
explorer 1999-06-28 07:37:13 +00:00
parent 74d3c214ec
commit 4ca6c63ecd
1 changed files with 89 additions and 67 deletions

View File

@ -37,20 +37,25 @@
/*
* greconfig - frontend to set/query tunnel endpoints
*
* $NetBSD: greconfig.c,v 1.4 1999/01/26 21:32:40 hwr Exp $
* $NetBSD: greconfig.c,v 1.5 1999/06/28 07:37:13 explorer Exp $
*/
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <err.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/sockio.h>
#include <netdb.h>
#include <net/if.h>
#include <netinet/in.h>
#include <arpa/inet.h>
/* from sys/sockio.h */
@ -83,12 +88,25 @@ main(int argc, char **argv)
while ((i = getopt(argc, argv, "d:i:p:s:v")) != -1)
switch(i) {
case 'd': dst=optarg; break;
case 'i': inf=optarg; break;
case 'p': proto=atoi(optarg); pflag++; break;
case 's': src=optarg; break;
case 'v': verbose++; break;
default: usage(); exit(1);
case 'd':
dst = optarg;
break;
case 'i':
inf = optarg;
break;
case 'p':
proto = atoi(optarg);
pflag++;
break;
case 's':
src = optarg;
break;
case 'v':
verbose++;
break;
default:
usage();
exit(1);
}
if (inf == NULL) {
@ -125,7 +143,8 @@ main(int argc, char **argv)
name2sa(src, &sa);
ifr.ifr_addr = *sa;
if (verbose)
printf("Setting source address ...\n");
printf("Setting source address to %s...\n",
sa2name(sa));
err = ioctl(s, GRESADDRS, (caddr_t)&ifr);
if (err < 0)
perror("GRESADDRS");
@ -135,7 +154,8 @@ main(int argc, char **argv)
name2sa(dst, &sa);
ifr.ifr_addr = *sa;
if (verbose)
printf("Setting destination address ...\n");
printf("Setting destination address to %s...\n",
sa2name(sa));
err = ioctl(s, GRESADDRD, (caddr_t)&ifr);
if (err < 0)
perror("GRESADDRD");
@ -167,34 +187,36 @@ main(int argc, char **argv)
void
usage(void)
{
printf("greconfig -i unit [-d dst] [-s src] [-p proto] [-v]\n");
printf("unit is gre<n>, proto either 47 or 55\n");
fprintf(stderr,
"greconfig -i unit [-d dst] [-s src] [-p proto] [-v]\n");
fprintf(stderr, "unit is gre<n>, proto either 47 or 55\n");
}
void name2sa(char *name,struct sockaddr **sa)
void
name2sa(char *name, struct sockaddr **sa)
{
struct hostent *hp;
struct sockaddr_in *si;
struct sockaddr_in s;
static struct sockaddr_in s;
hp = gethostbyname(name);
bzero(&s, sizeof(struct sockaddr_in));
s.sin_family = hp->h_addrtype;
if(hp->h_addrtype != AF_INET) {
printf("Only internet addresses allowed, not %s\n",name);
exit(5);
}
if (hp->h_addrtype != AF_INET)
errx(5, "Only internet addresses allowed, not %s\n", name);
bcopy(hp->h_addr, &s.sin_addr, hp->h_length);
si = &s;
*sa = (struct sockaddr *)si;
}
char* sa2name(struct sockaddr *sa)
char *
sa2name(struct sockaddr *sa)
{
struct sockaddr_in *si;
si = ((struct sockaddr_in *)(sa));
return (inet_ntoa(si->sin_addr));
}