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.7 1998/11/17 15:16:26 freitag 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;
99 static short sVafinit = 0;
101 struct aftype *aftypes[] =
133 unspec_aftype.title = _("UNSPEC");
135 unix_aftype.title = _("UNIX Domain");
138 inet_aftype.title = _("DARPA Internet");
141 inet6_aftype.title = _("IPv6");
144 ax25_aftype.title = _("AMPR AX.25");
147 netrom_aftype.title = _("AMPR NET/ROM");
150 ipx_aftype.title = _("IPX");
153 ddp_aftype.title = _("Appletalk DDP");
156 ec_aftype.title = _("Econet");
161 /* set the default AF list from the program name or a constant value */
162 void aftrans_def(char *tool, char *argv0, char *dflt)
167 strcpy(afname, dflt);
169 if (!(tmp = strrchr(argv0, '/')))
170 tmp = argv0; /* no slash?! */
174 if (!(buf = strdup(tmp)))
177 if (strlen(tool) >= strlen(tmp)) {
181 tmp = buf + (strlen(tmp) - strlen(tool));
183 if (strcmp(tmp, tool) != 0) {
188 if ((tmp = strchr(buf, '_')))
192 if (aftrans_opt(buf))
199 /* Check our protocol family table for this family. */
200 struct aftype *get_aftype(const char *name)
208 while (*afp != NULL) {
209 if (!strcmp((*afp)->name, name))
213 if (index(name, ','))
214 fprintf(stderr, _("Please don't supply more than one address family.\n"));
219 /* Check our protocol family table for this family. */
220 struct aftype *get_afntype(int af)
228 while (*afp != NULL) {
229 if ((*afp)->af == af)
236 /* Check our protocol family table for this family and return its socket */
237 int get_socket_for_af(int af)
245 while (*afp != NULL) {
246 if ((*afp)->af == af)
253 int aftrans_opt(const char *arg)
255 struct aftrans_t *paft;
259 safe_strncpy(buf, arg, sizeof(buf));
265 tmp2 = index(tmp1, ',');
271 for (paft = aftrans; paft->alias; paft++) {
272 if (strcmp(tmp1, paft->alias))
274 if (strlen(paft->name) + strlen(afname) + 1 >= sizeof(afname)) {
275 fprintf(stderr, _("Too much address family arguments.\n"));
282 strcat(afname, paft->name);
286 fprintf(stderr, _("Unknown address family `%s'.\n"), tmp1);