home *** CD-ROM | disk | FTP | other *** search
-
- /*
- * @(#)etherCode.c 1.3 2/23/90
- */
-
- /* File: /u1/Eden/Kernel/MsgOps/EtherCode.c */
-
- /*
- * $Header: /u1/Eden/Kernel/MsgOps/RCS/EtherCode.v Revision 3.4 85/03/14 21:03:23 eric Exp$
- * INTERFACE: None.
- *
- * FUNCTION: Provides the Ethernet address primitives.
- *
- * IMPORTS: /u1/Eden/Source/MsgOps/EtherTypes.h.
- *
- * EXPORTS: mEtherNull, mEtherCopy, mEtherIsEqual, mEqualNetwork,
- * mMakeEtherNetAddr, mGetHostName.
- *
- * DESIGN: Ethernet addresses are Unix 4.2 sockaddr_in structures
- * (see socket(2) ).
- *
- * $Log: /u1/Eden/Source/MsgOps/RCS/EtherCode.v $
- * Revision 3.6 86/12/05 22:45:17 eric
- * Put default port number into mMakeEtherNetAddress.
- * Revision 3.5 86/04/02 15:19:17 oystr
- * Got rid of mMakeNextEtherNetAddress which is not used
- * by any body. God only knows how much more of the stuff we
- * are hauling is obsolete.
- *
- * Revision 3.4 85/03/14 21:03:23 eric
- * Fixed MXTrace levels.
- *
- * Revision 3.3 84/11/29 21:03:23 schwartz
- * Changed routine mGetHostName to use table of Eden machine string names /
- * ethernet addresses instead of Unix system call gethostbyaddr (which does
- * file I/O)
- *
- * Revision 3.2 84/11/15 03:00:04 schwartz
- * Added the routine mGetHostName.
- *
- * Revision 3.1 84/08/19 19:40:02 schwartz
- * Added the routines mEqualNetwork, mMakeEtherNetAddr and
- * mMakeNextEtherNetAddr.
- *
- * Revision 3.0 84/07/07 23:21:31 schwartz
- * Changed code to accomodate usage of Unix 4.2 sockets for network
- * interprocess communication
- *
- * Revision 1.7 83/10/14 16:37:12 mager
- * Made mEtherNull and mEtherCopy block moves.
- *
- * Revision 1.5 83/02/25 12:15:26 cady
- * Added new trace levels.
- *
- * Revision 1.4 83/02/24 16:39:32 cady
- * Replaced conditional debug trace with dynamic trace.
- * Added conditional Kernel compilation.
- *
- * Revision 1.3 83/02/22 12:05:38 cady
- * Replaced #if Debug with #ifdef Debug.
- *
- * Revision 1.2 83/01/06 17:36:08 cady
- * Fixed mEtherPrint fFile type definition.
- *
- * Revision 1.1 83/01/06 14:10:22 cady
- * Initial revision
- *
- * 5-Jan-1983 Initial implementation. S. Cady.
- */
-
- #include <stdio.h>
- #include <netdb.h>
-
- #include "Kernel/h/mmTypes.h"
- #include "Kernel/h/mmEthrTypes.h"
- #include "Kernel/h/mmCodes.h"
- extern char *inet_ntoa();
-
-
- /****************************************************************/
- /* */
- /* mEtherNull */
- /* */
- /* mEtherNull sets the specified variable to the null Ethernet */
- /* address. */
- /* */
- /****************************************************************/
-
- void mEtherNull( fEther
- )
- EtherNetAddress *fEther;
- {
- static EtherNetAddress NULLETHER = {0}; /* All zeros, believe it or not */
-
- MXTraceMsg(6, "mEtherNull( %d )\n", fEther);
-
- *fEther = NULLETHER;
- }
-
- /****************************************************************/
- /* */
- /* mEtherCopy */
- /* */
- /* mEtherCopy copies the Ethernet address fSource into fDest. */
- /* */
- /****************************************************************/
-
- void mEtherCopy( fSource,
- fDest
- )
- EtherNetAddress *fSource;
- EtherNetAddress *fDest;
- {
- MXTraceMsg(5, "mEtherCopy( %d, %d )\n", fSource, fDest);
-
- *fDest = *fSource;
-
- }
-
- /****************************************************************/
- /* */
- /* mEtherIsEqual */
- /* */
- /* mEtherIsEqual compares two Ethernet addresses and returns */
- /* True if they are equal and False if they are not equal. */
- /* */
- /****************************************************************/
-
- Boolean mEtherIsEqual( fEther1,
- fEther2
- )
- EtherNetAddress *fEther1;
- EtherNetAddress *fEther2;
- {
- MXTraceMsg(6, "mEtherIsEqual( %d, %d )\n", fEther1, fEther2);
-
- return ( (Boolean)
- (fEther1->sin_addr.s_addr == fEther2->sin_addr.s_addr)
- );
- }
-
- /* mEqualNetwork Returns true is fAddr1 and fAddr2 are in the same
- local network */
- Boolean mEqualNetwork(fAddr1, fAddr2)
- EtherNetAddress *fAddr1, *fAddr2;
- {
- return( inet_netof(fAddr1->sin_addr) ==
- inet_netof(fAddr2->sin_addr) );
- }
-
- /* Initialize fields of EtherNetAddress given name of host and service name.
- A null service name means take any port. */
-
- KKStatus mMakeEtherNetAddr(fHostName, /* "in" parameter */
- fServiceName, /* "in" parameter */
- fDefaultPort, /* "in" parameter */
- fAddr) /* "out" parameter */
- char *fHostName;
- char *fServiceName;
- int fDefaultPort;
- EtherNetAddress *fAddr;
- {
- struct hostent *hp;
- struct servent *sp;
- unsigned short portNumber;
-
- hp = gethostbyname (fHostName);
- if (hp == NULL)
- return (MMSF_NoPhysHost);
-
- if (fServiceName == NULL)
- portNumber = 0; /* This requests Unix to take any available port */
- else {
- sp = NULL; /* getservbyname(fServiceName, "udp"); */
- if (sp == NULL)
- portNumber = htons((u_short) fDefaultPort);
- else
- portNumber = sp->s_port;
- }
-
- COPYADDR(hp->h_addr,&(fAddr->sin_addr.s_addr), hp->h_length);
- fAddr->sin_port = portNumber;
- fAddr->sin_family = AF_INET;
-
- return(MMSS_Success);
- }
-
- /* mGetHostName returns a pointer to a character string containing the
- name of the physical host at Ethernet address fEtherAddr */
- char *mGetHostName(fEtherAddr)
- EtherNetAddress *fEtherAddr;
- {
- extern int NumEmMachines;
- extern char *EmMachineNames[];
- extern EtherNetAddress EmMachineAddrs[];
- char buf[200];
- int i;
- struct hostent *host;
- struct in_addr theEtherAddr;
-
- for (i = 0; i < NumEmMachines; i++)
- if (mEtherIsEqual(&(EmMachineAddrs[i]), fEtherAddr))
- return(EmMachineNames[i]);
-
- /* Hmm, no local name */
-
- theEtherAddr = fEtherAddr->sin_addr;
- host = gethostbyaddr((char *)&theEtherAddr, sizeof(theEtherAddr), AF_INET);
- if (host != NULL) {
- sprintf(buf, "%s", host->h_name);
- } else {
- sprintf(buf, "%s", inet_ntoa(theEtherAddr));
- };
- return(buf);
- }
-
- /****************************************************************/
- /* End of Ethernet Library */
- /****************************************************************/
-