more changes, fixed some bugs in the code, -gateway will work now, added
authorPoul-Henning Kamp <phk@FreeBSD.org>
Thu, 2 Jun 1994 19:25:36 +0000 (19:25 +0000)
committerPoul-Henning Kamp <phk@FreeBSD.org>
Thu, 2 Jun 1994 19:25:36 +0000 (19:25 +0000)
-server (probably of limited use, but if your server is multihomed, you
need this).

usr.sbin/diskless_cfg/diskless.h
usr.sbin/diskless_cfg/diskless_cfg.c

index 96d2a2d..ef03727 100644 (file)
@@ -136,7 +136,7 @@ struct ifaliasreq {
  */
 
 #define NFS_FHSIZE     32
  */
 
 #define NFS_FHSIZE     32
-typedef struct { u_char f[NFS_FHSIZE] } nfsv2fh_t;
+typedef struct { u_char f[NFS_FHSIZE]; } nfsv2fh_t;
 /*
  * Arguments to mount NFS
  */
 /*
  * Arguments to mount NFS
  */
index 6156685..7678ff5 100644 (file)
@@ -4,8 +4,6 @@ Diskless Configuration Program
 
 Based loosely on the 4.4BSD diskless setup code
 
 
 Based loosely on the 4.4BSD diskless setup code
 
-Solaris 2.3: compile with -lbsm -lnsl -lsocket.
-
 *************************************************************************/
 #include <stdio.h>
 #include <fcntl.h>
 *************************************************************************/
 #include <stdio.h>
 #include <fcntl.h>
@@ -21,6 +19,7 @@ Solaris 2.3: compile with -lbsm -lnsl -lsocket.
 #include <sys/errno.h>
 #include <nfs/nfs.h>
 #ifdef __SVR4
 #include <sys/errno.h>
 #include <nfs/nfs.h>
 #ifdef __SVR4
+/* Solaris: compile with -lbsm -lnsl -lsocket */
 #define getfh nfs_getfh
 #define bcopy(a,b,c) memcpy(b,a,c)
 #endif
 #define getfh nfs_getfh
 #define bcopy(a,b,c) memcpy(b,a,c)
 #endif
@@ -56,6 +55,7 @@ struct nfs_diskless nfs_diskless;
 #define KW_HOSTNAME    7
 #define KW_KERNEL      8
 #define KW_GATEWAY     9
 #define KW_HOSTNAME    7
 #define KW_KERNEL      8
 #define KW_GATEWAY     9
+#define KW_SERVER      10
 
 struct {
        char *name;
 
 struct {
        char *name;
@@ -69,11 +69,12 @@ struct {
        { "-wsize",     KW_WSIZE },
        { "-hostname",  KW_HOSTNAME },
        { "-gateway",   KW_GATEWAY },
        { "-wsize",     KW_WSIZE },
        { "-hostname",  KW_HOSTNAME },
        { "-gateway",   KW_GATEWAY },
+       { "-server",    KW_SERVER },
        { NULL,         KW_HELP }
 };
 
 char *hostname = "386bsd";
        { NULL,         KW_HELP }
 };
 
 char *hostname = "386bsd";
-char *gateway = NULL;
+char gateway[256];
 char cfg[64];
 char *rootpath = "/var/386bsd";
 char *swappath = "/var/swap/386bsd";
 char cfg[64];
 char *rootpath = "/var/386bsd";
 char *swappath = "/var/swap/386bsd";
@@ -113,24 +114,6 @@ main(argc, argv)
        nfs_diskless.root_saddr.sa_len = sizeof(struct sockaddr);
        nfs_diskless.root_saddr.sa_family = AF_INET;
 
        nfs_diskless.root_saddr.sa_len = sizeof(struct sockaddr);
        nfs_diskless.root_saddr.sa_family = AF_INET;
 
-       if (gethostname(servername, 256) < 0) {
-               fprintf(stderr,"%s: unable to get host server name\n",argv[0]);
-               exit(2);
-       }
-       if ((hp = gethostbyname(servername)) == NULL) {
-               fprintf(stderr,"%s: unable to get host address\n",argv[0]);
-               exit(2);
-       }
-       p = servername;
-       while (*p && (*p != '.')) p++;
-       *p = 0;
-       nfs_diskless.swap_saddr.sa_data[0] = nfs_diskless.root_saddr.sa_data[0]
-               = NFS_SOCKET >> 8;
-       nfs_diskless.swap_saddr.sa_data[1] = nfs_diskless.root_saddr.sa_data[1]
-               = NFS_SOCKET & 0x00FF;
-       bcopy(*hp->h_addr_list, &nfs_diskless.swap_saddr.sa_data[2], 4);
-       bcopy(*hp->h_addr_list, &nfs_diskless.root_saddr.sa_data[2], 4);
-       
        i = 1;
        while (i < argc) {
                cmd = KW_HELP;
        i = 1;
        while (i < argc) {
                cmd = KW_HELP;
@@ -180,28 +163,49 @@ main(argc, argv)
                                hostname = argv[i+1];
                                i += 2;
                                break;
                                hostname = argv[i+1];
                                i += 2;
                                break;
+                       case KW_SERVER:
+                               strcpy(servername,argv[i+1]);
+                               i += 2;
+                               break;
                        case KW_GATEWAY:
                        case KW_GATEWAY:
-                               gateway = argv[i+1];
+                               strcpy(gateway,argv[i+1]);
                                i += 2;
                                break;
                }
        }
                                i += 2;
                                break;
                }
        }
-       if(gateway)
-       {
-               if (gethostname(gateway, 256) < 0) {
-                       fprintf(stderr,"%s: unable to get gateway host name\n",argv[0]);
-                       exit(2);
-               }
-               if ((hp = gethostbyname(gateway)) == NULL) {
-                       fprintf(stderr,"%s: unable to get gateway host address\n",argv[0]);
-                       exit(2);
-               }
-               nfs_diskless.mygateway.sa_len = sizeof(struct sockaddr);
-               nfs_diskless.mygateway.sa_family = AF_INET;
-               nfs_diskless.mygateway.sa_data[0] = NFS_SOCKET >> 8;
-               nfs_diskless.mygateway.sa_data[1] = NFS_SOCKET & 0x00FF;
-               bcopy(*hp->h_addr_list, &nfs_diskless.mygateway.sa_data[2], 4);
+
+       if (!*servername && gethostname(servername, sizeof servername) < 0) {
+               fprintf(stderr,"%s: unable to get host server name\n",argv[0]);
+               exit(2);
+       }
+       if ((hp = gethostbyname(servername)) == NULL) {
+               fprintf(stderr,"%s: unable to get host address\n",argv[0]);
+               exit(2);
+       }
+       p = servername;
+       while (*p && (*p != '.')) p++;
+       *p = 0;
+       nfs_diskless.swap_saddr.sa_data[0] = nfs_diskless.root_saddr.sa_data[0]
+               = NFS_SOCKET >> 8;
+       nfs_diskless.swap_saddr.sa_data[1] = nfs_diskless.root_saddr.sa_data[1]
+               = NFS_SOCKET & 0x00FF;
+       bcopy(*hp->h_addr_list, &nfs_diskless.swap_saddr.sa_data[2], 4);
+       bcopy(*hp->h_addr_list, &nfs_diskless.root_saddr.sa_data[2], 4);
+       
+       if (!*gateway && gethostname(gateway, sizeof gateway) < 0) {
+               fprintf(stderr,"%s: unable to get gateway host name\n",argv[0]);
+               exit(2);
        }
        }
+       if ((hp = gethostbyname(gateway)) == NULL) {
+               fprintf(stderr,"%s: unable to get gateway host address\n",argv[0]);
+               exit(2);
+       }
+       nfs_diskless.mygateway.sa_len = sizeof(struct sockaddr);
+       nfs_diskless.mygateway.sa_family = AF_INET;
+       nfs_diskless.mygateway.sa_data[0] = NFS_SOCKET >> 8;
+       nfs_diskless.mygateway.sa_data[1] = NFS_SOCKET & 0x00FF;
+       bcopy(*hp->h_addr_list, &nfs_diskless.mygateway.sa_data[2], 4);
+
        nfs_diskless.swap_args.rsize = i386order(rsize);
        nfs_diskless.swap_args.wsize = i386order(wsize);
        nfs_diskless.root_args.rsize = i386order(rsize);
        nfs_diskless.swap_args.rsize = i386order(rsize);
        nfs_diskless.swap_args.wsize = i386order(wsize);
        nfs_diskless.root_args.rsize = i386order(rsize);
@@ -225,7 +229,7 @@ main(argc, argv)
        bcopy(&broadcast, &nfs_diskless.myif.ifra_broadaddr.sa_data[2], 4);
        bcopy(&netmask, &nfs_diskless.myif.ifra_mask.sa_data[2], 4);
        if (stat(rootpath, &statbuf) < 0) {
        bcopy(&broadcast, &nfs_diskless.myif.ifra_broadaddr.sa_data[2], 4);
        bcopy(&netmask, &nfs_diskless.myif.ifra_mask.sa_data[2], 4);
        if (stat(rootpath, &statbuf) < 0) {
-               fprintf(stderr,"%s: unable to stat '%s'\n",
+               fprintf(stderr,"%s: unable to stat root '%s'\n",
                        argv[0],rootpath);
                exit(2);
        }
                        argv[0],rootpath);
                exit(2);
        }
@@ -244,7 +248,7 @@ main(argc, argv)
        strcpy(nfs_diskless.root_hostnam,buf);
        printf("root is on %s\n",nfs_diskless.root_hostnam);
        if (stat(swappath, &statbuf) < 0) {
        strcpy(nfs_diskless.root_hostnam,buf);
        printf("root is on %s\n",nfs_diskless.root_hostnam);
        if (stat(swappath, &statbuf) < 0) {
-               fprintf(stderr,"%s: unable to stat '%s'\n",
+               fprintf(stderr,"%s: unable to stat swap '%s'\n",
                        argv[0],swappath);
                exit(2);
        }
                        argv[0],swappath);
                exit(2);
        }