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: $Id: af.c,v 1.11 1999/04/18 20:28:42 philip Exp $
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"
47 "ax25", "ax25", &flag_ax25
50 "ip", "inet", &flag_inet
53 "ip6", "inet6", &flag_inet6
56 "ipx", "ipx", &flag_ipx
59 "appletalk", "ddp", &flag_ddp
62 "netrom", "netrom", &flag_netrom
65 "inet", "inet", &flag_inet
68 "inet6", "inet6", &flag_inet6
71 "ddp", "ddp", &flag_ddp
74 "unix", "unix", &flag_unx
77 "tcpip", "inet", &flag_inet
80 "econet", "ec", &flag_econet
87 char afname[256] = "";
89 extern struct aftype unspec_aftype;
90 extern struct aftype unix_aftype;
91 extern struct aftype inet_aftype;
92 extern struct aftype inet6_aftype;
93 extern struct aftype ax25_aftype;
94 extern struct aftype netrom_aftype;
95 extern struct aftype ipx_aftype;
96 extern struct aftype ddp_aftype;
97 extern struct aftype ec_aftype;
98 extern struct aftype rose_aftype;
100 static short sVafinit = 0;
102 struct aftype *aftypes[] =
137 unspec_aftype.title = _("UNSPEC");
139 unix_aftype.title = _("UNIX Domain");
142 inet_aftype.title = _("DARPA Internet");
145 inet6_aftype.title = _("IPv6");
148 ax25_aftype.title = _("AMPR AX.25");
151 netrom_aftype.title = _("AMPR NET/ROM");
154 ipx_aftype.title = _("Novell IPX");
157 ddp_aftype.title = _("Appletalk DDP");
160 ec_aftype.title = _("Econet");
163 rose_aftype.title = _("AMPR ROSE");
168 /* set the default AF list from the program name or a constant value */
169 void aftrans_def(char *tool, char *argv0, char *dflt)
174 strcpy(afname, dflt);
176 if (!(tmp = strrchr(argv0, '/')))
177 tmp = argv0; /* no slash?! */
181 if (!(buf = strdup(tmp)))
184 if (strlen(tool) >= strlen(tmp)) {
188 tmp = buf + (strlen(tmp) - strlen(tool));
190 if (strcmp(tmp, tool) != 0) {
195 if ((tmp = strchr(buf, '_')))
199 if (aftrans_opt(buf))
206 /* Check our protocol family table for this family. */
207 struct aftype *get_aftype(const char *name)
215 while (*afp != NULL) {
216 if (!strcmp((*afp)->name, name))
220 if (index(name, ','))
221 fprintf(stderr, _("Please don't supply more than one address family.\n"));
226 /* Check our protocol family table for this family. */
227 struct aftype *get_afntype(int af)
235 while (*afp != NULL) {
236 if ((*afp)->af == af)
243 /* Check our protocol family table for this family and return its socket */
244 int get_socket_for_af(int af)
252 while (*afp != NULL) {
253 if ((*afp)->af == af)
260 int aftrans_opt(const char *arg)
262 struct aftrans_t *paft;
266 safe_strncpy(buf, arg, sizeof(buf));
272 tmp2 = index(tmp1, ',');
278 for (paft = aftrans; paft->alias; paft++) {
279 if (strcmp(tmp1, paft->alias))
281 if (strlen(paft->name) + strlen(afname) + 1 >= sizeof(afname)) {
282 fprintf(stderr, _("Too much address family arguments.\n"));
289 strcat(afname, paft->name);
293 fprintf(stderr, _("Unknown address family `%s'.\n"), tmp1);
302 /* type: 0=all, 1=getroute */
303 void print_aflist(int type) {
312 while (*afp != NULL) {
313 if ((type == 1 && ((*afp)->rprint == NULL)) || ((*afp)->af == 0)) {
316 if ((count % 3) == 0) fprintf(stderr,count?"\n ":" ");
317 txt = (*afp)->name; if (!txt) txt = "..";
318 fprintf(stderr,"%s (%s) ",txt,(*afp)->title);
322 fprintf(stderr,"\n");