mirror of
https://github.com/Interlisp/maiko.git
synced 2026-01-25 19:46:21 +00:00
Reformat all C source files with Clang-format in Google style w/ 100 col width.
This commit is contained in:
329
src/ldeether.c
Executable file → Normal file
329
src/ldeether.c
Executable file → Normal file
@@ -1,11 +1,7 @@
|
||||
/* $Id: ldeether.c,v 1.3 2001/12/24 01:09:04 sybalsky Exp $ (C) Copyright Venue, All Rights Reserved */
|
||||
/* $Id: ldeether.c,v 1.3 2001/12/24 01:09:04 sybalsky Exp $ (C) Copyright Venue, All Rights Reserved
|
||||
*/
|
||||
static char *id = "$Id: ldeether.c,v 1.3 2001/12/24 01:09:04 sybalsky Exp $ Copyright (C) Venue";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/************************************************************************/
|
||||
/* */
|
||||
/* (C) Copyright 1989-96 Venue. All Rights Reserved. */
|
||||
@@ -20,17 +16,11 @@ static char *id = "$Id: ldeether.c,v 1.3 2001/12/24 01:09:04 sybalsky Exp $ Copy
|
||||
|
||||
#include "version.h"
|
||||
|
||||
|
||||
#ifdef NOETHER
|
||||
/* No ethernet, so have a dummy here. */
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
/* No ethernet, so have a dummy here. */
|
||||
int main(int argc, char *argv[]) { return (0); }
|
||||
#else
|
||||
/* THERE -IS- AN ETHERNET */
|
||||
|
||||
|
||||
/* THERE -IS- AN ETHERNET */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -40,23 +30,15 @@ int main (int argc, char *argv[])
|
||||
#include <sys/pfmod.h>
|
||||
|
||||
#if defined(SVR4) && !defined(SUNOS5)
|
||||
char *devices[] = {
|
||||
"emd0", "emd1", "emd2", "emd3", "emd4",
|
||||
0
|
||||
};
|
||||
char *devices[] = {"emd0", "emd1", "emd2", "emd3", "emd4", 0};
|
||||
#endif
|
||||
|
||||
#ifdef SUNOS5
|
||||
#include <sys/bufmod.h>
|
||||
|
||||
char *devices[] = {
|
||||
"le0", "le1", "le2", "le3", "le4",
|
||||
"ie0", "ie1", "ie2", "ie3", "ie4",
|
||||
"qe0", "qe1", "qe2", "qe3", "qe4", "qe5", "qe6", "qe7",
|
||||
"fddi0", "fddi1", "fddi2", "fddi3", "fddi4",
|
||||
"bf0", "bf1",
|
||||
0
|
||||
};
|
||||
char *devices[] = {"le0", "le1", "le2", "le3", "le4", "ie0", "ie1", "ie2", "ie3",
|
||||
"ie4", "qe0", "qe1", "qe2", "qe3", "qe4", "qe5", "qe6", "qe7",
|
||||
"fddi0", "fddi1", "fddi2", "fddi3", "fddi4", "bf0", "bf1", 0};
|
||||
#endif
|
||||
#endif /* USE_DLPI */
|
||||
|
||||
@@ -89,203 +71,192 @@ char *devices[] = {
|
||||
|
||||
#endif /* NOETHER */
|
||||
|
||||
|
||||
|
||||
int ether_fd = -1; /* file descriptor for ether socket */
|
||||
int ether_intf_type = 0; /* IF type? from DLPI */
|
||||
unsigned char ether_host[6] = {0,0,0,0,0,0}; /* 48 bit address */
|
||||
int ether_fd = -1; /* file descriptor for ether socket */
|
||||
int ether_intf_type = 0; /* IF type? from DLPI */
|
||||
unsigned char ether_host[6] = {0, 0, 0, 0, 0, 0}; /* 48 bit address */
|
||||
char filetorun[30] = "lde";
|
||||
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char Earg[30], Ename[30], **newargv;
|
||||
int i;
|
||||
int flags;
|
||||
int main(int argc, char *argv[]) {
|
||||
char Earg[30], Ename[30], **newargv;
|
||||
int i;
|
||||
int flags;
|
||||
#ifdef USE_DLPI
|
||||
static struct packetfilt pf = {0, 1, {ENF_PUSHZERO}};
|
||||
struct strioctl si;
|
||||
static struct packetfilt pf = {0, 1, {ENF_PUSHZERO}};
|
||||
struct strioctl si;
|
||||
#endif /* USE_DLPI */
|
||||
|
||||
|
||||
#ifndef NOETHER
|
||||
|
||||
/* Only do the ether kick=-start if we've got to. */
|
||||
/* Only do the ether kick=-start if we've got to. */
|
||||
|
||||
/* Kickstart program for the Lisp Development Environment (LDE).
|
||||
Run this as setuid root to open the LDE ether socket.
|
||||
Passes all arguments through to LDE plus -E <ether-info>
|
||||
to communicate open ether socket.
|
||||
/* Kickstart program for the Lisp Development Environment (LDE).
|
||||
Run this as setuid root to open the LDE ether socket.
|
||||
Passes all arguments through to LDE plus -E <ether-info>
|
||||
to communicate open ether socket.
|
||||
|
||||
<ether-info> looks like this:
|
||||
<descriptor-number>:<b1>:<b2>:<b3>:<b4>:<b5>:<b6>:<name>
|
||||
<ether-info> looks like this:
|
||||
<descriptor-number>:<b1>:<b2>:<b3>:<b4>:<b5>:<b6>:<name>
|
||||
|
||||
where <descriptor-number> is the number of the open
|
||||
socket (decimal), and <b1>-<b6> are hex of the socket's
|
||||
48-bit Ethernet address, and <name> is the name of the
|
||||
Ethernet device as found by SIOCGIFCONF.
|
||||
*/
|
||||
|
||||
if (!geteuid()){
|
||||
#ifdef USE_DLPI
|
||||
/* Use DLPI to connect to the ethernet. This code is stolen
|
||||
from NFSWATCH4.3
|
||||
where <descriptor-number> is the number of the open
|
||||
socket (decimal), and <b1>-<b6> are hex of the socket's
|
||||
48-bit Ethernet address, and <name> is the name of the
|
||||
Ethernet device as found by SIOCGIFCONF.
|
||||
*/
|
||||
|
||||
if ( ether_fd = setup_dlpi_dev(NULL)) { /* Open an ether interface */
|
||||
ether_intf_type = dlpi_devtype(ether_fd);
|
||||
printf("opened ldeether fd %d.\n", ether_fd);
|
||||
/* first and foremost, get the packet filter module attached
|
||||
(used for ether_suspend and ether_resume) */
|
||||
if (!geteuid()) {
|
||||
#ifdef USE_DLPI
|
||||
/* Use DLPI to connect to the ethernet. This code is stolen
|
||||
from NFSWATCH4.3
|
||||
*/
|
||||
|
||||
if(ioctl(ether_fd, I_PUSH, "pfmod") < 0) {
|
||||
perror("IOCTL push of pf lost");
|
||||
close(ether_fd);
|
||||
goto I_Give_Up;
|
||||
}
|
||||
|
||||
si.ic_cmd = PFIOCSETF;
|
||||
si.ic_timout = -1;
|
||||
si.ic_len = sizeof(pf);
|
||||
si.ic_dp = (char *)&pf;
|
||||
if (ether_fd = setup_dlpi_dev(NULL)) { /* Open an ether interface */
|
||||
ether_intf_type = dlpi_devtype(ether_fd);
|
||||
printf("opened ldeether fd %d.\n", ether_fd);
|
||||
/* first and foremost, get the packet filter module attached
|
||||
(used for ether_suspend and ether_resume) */
|
||||
|
||||
if (ioctl(ether_fd, I_STR, &si) < 0) {
|
||||
perror("ioctl: I_STR PFIOCSETF");
|
||||
return(-1);
|
||||
}
|
||||
if (ioctl(ether_fd, I_PUSH, "pfmod") < 0) {
|
||||
perror("IOCTL push of pf lost");
|
||||
close(ether_fd);
|
||||
goto I_Give_Up;
|
||||
}
|
||||
|
||||
flags = fcntl(ether_fd, F_GETFL, 0);
|
||||
flags = fcntl(ether_fd, F_SETFL, flags | O_NDELAY );
|
||||
si.ic_cmd = PFIOCSETF;
|
||||
si.ic_timout = -1;
|
||||
si.ic_len = sizeof(pf);
|
||||
si.ic_dp = (char *)&pf;
|
||||
|
||||
if (ioctl(ether_fd, I_STR, &si) < 0) {
|
||||
perror("ioctl: I_STR PFIOCSETF");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
flags = fcntl(ether_fd, F_GETFL, 0);
|
||||
flags = fcntl(ether_fd, F_SETFL, flags | O_NDELAY);
|
||||
|
||||
#else
|
||||
/* N O T D L P I C O D E */
|
||||
|
||||
/* N O T D L P I C O D E */
|
||||
|
||||
#ifndef OS4
|
||||
if ((ether_fd = socket(AF_NIT, SOCK_RAW, NITPROTO_RAW)) >= 0) {
|
||||
#else /* OS4 */
|
||||
if ((ether_fd = socket(AF_NIT, SOCK_RAW, NITPROTO_RAW)) >= 0) {
|
||||
#else /* OS4 */
|
||||
|
||||
if ((ether_fd = open("/dev/nit", O_RDWR)) >= 0) {
|
||||
if ((ether_fd = open("/dev/nit", O_RDWR)) >= 0) {
|
||||
#endif /* OS4 */
|
||||
|
||||
/* it's open, now query it and find out its name and address */
|
||||
/* JRB - must document that LDE uses the first net board as found
|
||||
by SIOCGIFCONF (see if(4)). Maybe we need an option to specify
|
||||
which net board (suspect more than one net board on an LDE machine
|
||||
will be rare, but...).
|
||||
*/
|
||||
struct ifconf if_data;
|
||||
struct ifreq ifbuf[20];
|
||||
/* it's open, now query it and find out its name and address */
|
||||
/* JRB - must document that LDE uses the first net board as found
|
||||
by SIOCGIFCONF (see if(4)). Maybe we need an option to specify
|
||||
which net board (suspect more than one net board on an LDE machine
|
||||
will be rare, but...).
|
||||
*/
|
||||
struct ifconf if_data;
|
||||
struct ifreq ifbuf[20];
|
||||
|
||||
#ifdef OS4
|
||||
/* first and foremost, get the packet filter module attached
|
||||
(used for ether_suspend and ether_resume) */
|
||||
/* first and foremost, get the packet filter module attached
|
||||
(used for ether_suspend and ether_resume) */
|
||||
|
||||
if(ioctl(ether_fd, I_PUSH, "pf") < 0) {
|
||||
perror("IOCTL push of pf lost");
|
||||
close(ether_fd);
|
||||
goto I_Give_Up;
|
||||
}
|
||||
if (ioctl(ether_fd, I_PUSH, "pf") < 0) {
|
||||
perror("IOCTL push of pf lost");
|
||||
close(ether_fd);
|
||||
goto I_Give_Up;
|
||||
}
|
||||
#endif /* OS4 */
|
||||
|
||||
if_data.ifc_len = sizeof(ifbuf);
|
||||
if_data.ifc_req = ifbuf;
|
||||
if_data.ifc_len = sizeof(ifbuf);
|
||||
if_data.ifc_req = ifbuf;
|
||||
#ifndef OS4
|
||||
if(ioctl(ether_fd, SIOCGIFCONF, &if_data) < 0) {
|
||||
perror("Couldn't GIFCONF socket; Net is off");
|
||||
#else /* OS4 */
|
||||
if (ioctl(ether_fd, SIOCGIFCONF, &if_data) < 0) {
|
||||
perror("Couldn't GIFCONF socket; Net is off");
|
||||
#else /* OS4 */
|
||||
|
||||
bzero(ifbuf, sizeof(ifbuf));
|
||||
{
|
||||
/* we have to get the interface name from another socket, since
|
||||
/dev/nit doesn't know anything until it gets bound, and we
|
||||
can't bind it without knowing the interface name... */
|
||||
int s;
|
||||
bzero(ifbuf, sizeof(ifbuf));
|
||||
{
|
||||
/* we have to get the interface name from another socket, since
|
||||
/dev/nit doesn't know anything until it gets bound, and we
|
||||
can't bind it without knowing the interface name... */
|
||||
int s;
|
||||
|
||||
if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
|
||||
perror("No socket for interface name");
|
||||
close(s);
|
||||
close(ether_fd);
|
||||
ether_fd = -1;
|
||||
goto I_Give_Up;
|
||||
}
|
||||
if (ioctl(s, SIOCGIFCONF, (char *)&if_data) < 0) {
|
||||
perror("Couldn't get interface name from socket");
|
||||
close(s);
|
||||
close(ether_fd);
|
||||
ether_fd = -1;
|
||||
goto I_Give_Up;
|
||||
}
|
||||
(void) close(s);
|
||||
}
|
||||
if(ioctl(ether_fd, NIOCBIND, &if_data.ifc_req[0]) < 0) {
|
||||
perror("Couldn't NIOCBIND socket: Net is off");
|
||||
if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
|
||||
perror("No socket for interface name");
|
||||
close(s);
|
||||
close(ether_fd);
|
||||
ether_fd = -1;
|
||||
goto I_Give_Up;
|
||||
}
|
||||
if (ioctl(s, SIOCGIFCONF, (char *)&if_data) < 0) {
|
||||
perror("Couldn't get interface name from socket");
|
||||
close(s);
|
||||
close(ether_fd);
|
||||
ether_fd = -1;
|
||||
goto I_Give_Up;
|
||||
}
|
||||
(void)close(s);
|
||||
}
|
||||
if (ioctl(ether_fd, NIOCBIND, &if_data.ifc_req[0]) < 0) {
|
||||
perror("Couldn't NIOCBIND socket: Net is off");
|
||||
#endif /* OS4 */
|
||||
|
||||
close(ether_fd);
|
||||
ether_fd = -1;
|
||||
goto I_Give_Up;
|
||||
}
|
||||
/* now for the address */
|
||||
if(ioctl(ether_fd, SIOCGIFADDR, &if_data.ifc_req[0]) < 0) {
|
||||
perror("Couldn't GIFADDR socket: Net is off");
|
||||
close(ether_fd);
|
||||
ether_fd = -1;
|
||||
goto I_Give_Up;
|
||||
}
|
||||
bcopy(if_data.ifc_req[0].ifr_addr.sa_data, ether_host, 6);
|
||||
strcpy(Ename, if_data.ifc_req[0].ifr_name);
|
||||
|
||||
flags = fcntl(ether_fd, F_GETFL, 0);
|
||||
flags = fcntl(ether_fd, F_SETFL, flags | FASYNC | FNDELAY);
|
||||
close(ether_fd);
|
||||
ether_fd = -1;
|
||||
goto I_Give_Up;
|
||||
}
|
||||
/* now for the address */
|
||||
if (ioctl(ether_fd, SIOCGIFADDR, &if_data.ifc_req[0]) < 0) {
|
||||
perror("Couldn't GIFADDR socket: Net is off");
|
||||
close(ether_fd);
|
||||
ether_fd = -1;
|
||||
goto I_Give_Up;
|
||||
}
|
||||
bcopy(if_data.ifc_req[0].ifr_addr.sa_data, ether_host, 6);
|
||||
strcpy(Ename, if_data.ifc_req[0].ifr_name);
|
||||
|
||||
flags = fcntl(ether_fd, F_GETFL, 0);
|
||||
flags = fcntl(ether_fd, F_SETFL, flags | FASYNC | FNDELAY);
|
||||
|
||||
#endif /* USE_DLPI */
|
||||
#ifdef DEBUG
|
||||
printf("init_ether: **** Ethernet starts ****\n");
|
||||
#ifdef DEBUG
|
||||
printf("init_ether: **** Ethernet starts ****\n");
|
||||
#endif
|
||||
} else {
|
||||
I_Give_Up:
|
||||
perror("init_ether: can't open NIT socket\n");
|
||||
ether_fd = -1;
|
||||
/* exit(); */
|
||||
}
|
||||
seteuid(getuid());
|
||||
}
|
||||
} else {
|
||||
I_Give_Up:
|
||||
perror("init_ether: can't open NIT socket\n");
|
||||
ether_fd = -1;
|
||||
/* exit(); */
|
||||
}
|
||||
seteuid(getuid());
|
||||
}
|
||||
|
||||
#endif /* NOETHER */
|
||||
|
||||
/* OK, right here do other stuff like scan args */
|
||||
/* finally crank up LDE; first copy the original args */
|
||||
/* OK, right here do other stuff like scan args */
|
||||
/* finally crank up LDE; first copy the original args */
|
||||
|
||||
newargv = (char **) malloc((argc + 1 + (ether_fd > 0)*2) * sizeof (char **));
|
||||
newargv[0] = filetorun; /* or whatever... */
|
||||
for(i=1; i<argc; i++) newargv[i] = argv[i];
|
||||
newargv = (char **)malloc((argc + 1 + (ether_fd > 0) * 2) * sizeof(char **));
|
||||
newargv[0] = filetorun; /* or whatever... */
|
||||
for (i = 1; i < argc; i++) newargv[i] = argv[i];
|
||||
|
||||
/* then if the net is active, spit out the ether info */
|
||||
if(ether_fd > 0) {
|
||||
newargv[i++] = "-E";
|
||||
/* then if the net is active, spit out the ether info */
|
||||
if (ether_fd > 0) {
|
||||
newargv[i++] = "-E";
|
||||
#ifdef USE_DLPI
|
||||
sprintf(Earg, "%d:%x:%x:%x:%x:%x:%x", ether_fd,
|
||||
ether_host[0], ether_host[1], ether_host[2],
|
||||
ether_host[3], ether_host[4], ether_host[5]);
|
||||
sprintf(Earg, "%d:%x:%x:%x:%x:%x:%x", ether_fd, ether_host[0], ether_host[1], ether_host[2],
|
||||
ether_host[3], ether_host[4], ether_host[5]);
|
||||
#else
|
||||
sprintf(Earg, "%d:%x:%x:%x:%x:%x:%x:%s", ether_fd,
|
||||
ether_host[0], ether_host[1], ether_host[2],
|
||||
ether_host[3], ether_host[4], ether_host[5], Ename);
|
||||
sprintf(Earg, "%d:%x:%x:%x:%x:%x:%x:%s", ether_fd, ether_host[0], ether_host[1], ether_host[2],
|
||||
ether_host[3], ether_host[4], ether_host[5], Ename);
|
||||
#endif /* USE_DLPI */
|
||||
newargv[i++] = Earg;
|
||||
printf("ether = %d:%x:%x:%x:%x:%x:%x:%s", ether_fd,
|
||||
ether_host[0], ether_host[1], ether_host[2],
|
||||
ether_host[3], ether_host[4], ether_host[5], Ename);
|
||||
}
|
||||
newargv[i] = 0;
|
||||
newargv[i++] = Earg;
|
||||
printf("ether = %d:%x:%x:%x:%x:%x:%x:%s", ether_fd, ether_host[0], ether_host[1], ether_host[2],
|
||||
ether_host[3], ether_host[4], ether_host[5], Ename);
|
||||
}
|
||||
newargv[i] = 0;
|
||||
|
||||
/* then execve the LDE executable */
|
||||
execvp(filetorun, newargv);
|
||||
perror(filetorun);
|
||||
return(1);
|
||||
/* then execve the LDE executable */
|
||||
execvp(filetorun, newargv);
|
||||
perror(filetorun);
|
||||
return (1);
|
||||
}
|
||||
|
||||
#endif /* NOETHER */
|
||||
|
||||
Reference in New Issue
Block a user