2 * lib/af.c This file contains the top-level part of the protocol
3 * support functions module for the NET-2 base distribution.
5 * Version: lib/af.c 1.13 (1996-02-21)
7 * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
8 * Copyright 1993 MicroWalt Corporation
10 * This program is free software; you can redistribute it
11 * and/or modify it under the terms of the GNU General
12 * Public License as published by the Free Software
13 * Foundation; either version 2 of the License, or (at
14 * your option) any later version.
16 #include <sys/types.h>
17 #include <sys/socket.h>
25 #include "net-support.h"
26 #include "pathnames.h"
45 {"ax25", "ax25", &flag_ax25},
46 {"ip", "inet", &flag_inet},
47 {"ip6", "inet6", &flag_inet6},
48 {"ipx", "ipx", &flag_ipx},
49 {"appletalk", "ddp", &flag_ddp},
50 {"netrom", "netrom", &flag_netrom},
51 {"inet", "inet", &flag_inet},
52 {"inet6", "inet6", &flag_inet6},
53 {"ddp", "ddp", &flag_ddp},
54 {"unix", "unix", &flag_unx},
55 {"tcpip", "inet", &flag_inet},
56 {"econet", "ec", &flag_econet},
62 extern struct aftype unspec_aftype;
63 extern struct aftype unix_aftype;
64 extern struct aftype inet_aftype;
65 extern struct aftype inet6_aftype;
66 extern struct aftype ax25_aftype;
67 extern struct aftype netrom_aftype;
68 extern struct aftype ipx_aftype;
69 extern struct aftype ddp_aftype;
70 extern struct aftype ec_aftype;
72 static short sVafinit = 0;
74 static struct aftype *aftypes[] = {
105 unspec_aftype.title = _("UNSPEC");
107 unix_aftype.title = _("UNIX Domain");
110 inet_aftype.title = _("DARPA Internet");
113 inet6_aftype.title = _("IPv6");
116 ax25_aftype.title = _("AMPR AX.25");
119 netrom_aftype.title = _("AMPR NET/ROM");
122 ipx_aftype.title = _("IPX");
125 ddp_aftype.title = _("Appletalk DDP");
128 ec_aftype.title = _("Econet");
133 /* set the default AF list from the program name or a constant value */
135 aftrans_def(char *tool, char *argv0, char *dflt)
140 strcpy(afname, dflt);
142 if (!(tmp = strrchr(argv0, '/')))
143 tmp = argv0; /* no slash?! */
147 if (!(buf = strdup(tmp)))
150 if (strlen(tool) >= strlen(tmp)) {
154 tmp = buf+(strlen(tmp)-strlen(tool));
156 if (strcmp(tmp, tool)!=0) {
162 if ((tmp = strchr(buf,'_')))
166 if (aftrans_opt(buf))
173 /* Check our protocol family table for this family. */
175 get_aftype(const char *name)
183 while (*afp != NULL) {
184 if (!strcmp((*afp)->name, name)) return(*afp);
188 fprintf(stderr,_("Please don't supply more than one address family.\n"));
193 /* Check our protocol family table for this family. */
203 while (*afp != NULL) {
204 if ((*afp)->af == af) return(*afp);
211 int aftrans_opt(const char *arg)
213 struct aftrans_t *paft;
217 strncpy(buf,arg,sizeof(buf));
218 buf[sizeof(buf)-1]='\0';
224 tmp2=index(tmp1,',');
230 for(paft=aftrans;paft->alias;paft++) {
231 if (strcmp(tmp1,paft->alias))
233 if (strlen(paft->name)+strlen(afname)+1 >= sizeof(afname)) {
234 fprintf(stderr,_("Too much address family arguments.\n"));
241 strcat(afname,paft->name);
245 fprintf(stderr,_("Unknown address family `%s'.\n"),tmp1);