]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sbin/atm/atm/atm_inet.c
This commit was generated by cvs2svn to compensate for changes in r163820,
[FreeBSD/FreeBSD.git] / sbin / atm / atm / atm_inet.c
1 /*
2  *
3  * ===================================
4  * HARP  |  Host ATM Research Platform
5  * ===================================
6  *
7  *
8  * This Host ATM Research Platform ("HARP") file (the "Software") is
9  * made available by Network Computing Services, Inc. ("NetworkCS")
10  * "AS IS".  NetworkCS does not provide maintenance, improvements or
11  * support of any kind.
12  *
13  * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
14  * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
15  * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
16  * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
17  * In no event shall NetworkCS be responsible for any damages, including
18  * but not limited to consequential damages, arising from or relating to
19  * any use of the Software or related support.
20  *
21  * Copyright 1994-1998 Network Computing Services, Inc.
22  *
23  * Copies of this Software may be made, however, the above copyright
24  * notice must be reproduced on all copies.
25  */
26
27 /*
28  * User configuration and display program
29  * --------------------------------------
30  *
31  * IP support
32  *
33  */
34
35 #include <sys/param.h>  
36 #include <sys/socket.h> 
37 #include <net/if.h>
38 #include <netinet/in.h>
39 #include <netatm/port.h>
40 #include <netatm/atm.h>
41 #include <netatm/atm_if.h> 
42 #include <netatm/atm_sap.h>
43 #include <netatm/atm_sys.h>
44 #include <netatm/atm_ioctl.h>
45
46 #include <errno.h>
47 #include <libatm.h>
48 #include <stdio.h>
49 #include <stdlib.h>
50 #include <string.h>
51 #include <err.h>
52
53 #include "atm.h"
54
55 #ifndef lint
56 __RCSID("@(#) $FreeBSD$");
57 #endif
58
59
60 /*
61  * Process add command for a TCP/IP PVC
62  * 
63  * Command format: 
64  *      atm add pvc <intf> <vpi> <vci> <aal> <encaps> IP <netif>
65  *              <IP addr> | dynamic
66  *
67  * Arguments:
68  *      argc    number of remaining arguments to command
69  *      argv    pointer to remaining argument strings
70  *      cmdp    pointer to command description 
71  *      app     pointer to AIOCAPVC structure
72  *      intp    pointer to air_int_rsp structure with information
73  *              about the physical interface that is the PVC is for.
74  *
75  * Returns:
76  *      none
77  *
78  */
79 void
80 ip_pvcadd(int argc, char **argv, const struct cmd *cmdp,
81     struct atmaddreq *app, struct air_int_rsp *intp)
82 {
83         char    *cp;
84         char    nhelp[128];
85         u_int   netif_no;
86         u_int   i, netif_pref_len;
87
88         /*
89          * Yet more validation
90          */
91         if (argc < 2) {
92                 strcpy(nhelp, cmdp->help);
93                 cp = strstr(nhelp, "<netif>");
94                 if (cp)
95                         strcpy(cp, "ip {dyn|<dst>}");
96                 fprintf(stderr, "%s: Invalid number of arguments:\n",
97                                 prog);
98                 fprintf(stderr, "\tformat is: %s%s %s\n",
99                                 prefix, cmdp->name, nhelp);
100                 exit(1);
101         }
102
103         /*
104          * Validate and set network interface
105          */
106         bzero(app->aar_pvc_intf, sizeof(app->aar_pvc_intf));
107         netif_pref_len = strlen(intp->anp_nif_pref);
108         cp = &argv[0][netif_pref_len];
109         netif_no = (u_int)strtoul(cp, NULL, 10);
110         for (i = 0; i < strlen(cp); i++) {
111                 if (cp[i] < '0' || cp[i] > '9') {
112                         netif_no = -1;
113                         break;
114                 }
115         }
116         if (strlen(argv[0]) > sizeof(app->aar_pvc_intf) - 1)
117                 errx(1, "Illegal network interface name '%s'", argv[0]);
118
119         if (strncasecmp(intp->anp_nif_pref, argv[0], netif_pref_len) ||
120             strlen(argv[0]) <= netif_pref_len || netif_no >= intp->anp_nif_cnt)
121                 errx(1, "network interface %s is not associated with "
122                     "interface %s", argv[0], intp->anp_intf);
123
124         strcpy(app->aar_pvc_intf, argv[0]);
125         argc--;
126         argv++;
127
128         /*
129          * Set PVC destination address
130          */
131         bzero(&app->aar_pvc_dst, sizeof(struct sockaddr));
132         if (strcasecmp(argv[0], "dynamic") == 0 ||
133                         strcasecmp(argv[0], "dyn") == 0) {
134
135                 /*
136                  * Destination is dynamically determined
137                  */
138                 app->aar_pvc_flags |= PVC_DYN;
139         } else {
140
141                 /*
142                  * Get destination IP address
143                  */
144                 struct sockaddr_in *sain, *ret;
145
146                 sain = (struct sockaddr_in *)(void *)&app->aar_pvc_dst;
147                 ret = get_ip_addr(argv[0]);
148                 if (ret == NULL)
149                         errx(1, "%s: bad ip address '%s'", argv[-1], argv[0]);
150                 sain->sin_addr.s_addr = ret->sin_addr.s_addr;
151         }
152         argc--; argv++;
153 }
154