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.14 2007/12/01 17:49:35 ecki 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"
51 "ax25", "ax25", &flag_ax25
54 "ip", "inet", &flag_inet
57 "ip6", "inet6", &flag_inet6
60 "ipx", "ipx", &flag_ipx
63 "rose", "rose", &flag_rose
66 "appletalk", "ddp", &flag_ddp
69 "netrom", "netrom", &flag_netrom
72 "inet", "inet", &flag_inet
75 "inet6", "inet6", &flag_inet6
78 "ddp", "ddp", &flag_ddp
81 "unix", "unix", &flag_unx
84 "tcpip", "inet", &flag_inet
87 "econet", "ec", &flag_econet
90 "x25", "x25", &flag_x25
93 "ash", "ash", &flag_ash
96 "bluetooth", "bluetooth", &flag_bluetooth
103 char afname[256] = "";
105 extern struct aftype unspec_aftype;
106 extern struct aftype unix_aftype;
107 extern struct aftype inet_aftype;
108 extern struct aftype inet6_aftype;
109 extern struct aftype ax25_aftype;
110 extern struct aftype netrom_aftype;
111 extern struct aftype ipx_aftype;
112 extern struct aftype ddp_aftype;
113 extern struct aftype ec_aftype;
114 extern struct aftype x25_aftype;
115 extern struct aftype rose_aftype;
116 extern struct aftype ash_aftype;
118 static short sVafinit = 0;
120 struct aftype *aftypes[] =
161 unspec_aftype.title = _("UNSPEC");
163 unix_aftype.title = _("UNIX Domain");
166 inet_aftype.title = _("DARPA Internet");
169 inet6_aftype.title = _("IPv6");
172 ax25_aftype.title = _("AMPR AX.25");
175 netrom_aftype.title = _("AMPR NET/ROM");
178 ipx_aftype.title = _("Novell IPX");
181 ddp_aftype.title = _("Appletalk DDP");
184 ec_aftype.title = _("Econet");
187 x25_aftype.title = _("CCITT X.25");
190 rose_aftype.title = _("AMPR ROSE");
193 ash_aftype.title = _("Ash");
198 /* set the default AF list from the program name or a constant value */
199 void aftrans_def(char *tool, char *argv0, char *dflt)
204 strcpy(afname, dflt);
206 if (!(tmp = strrchr(argv0, '/')))
207 tmp = argv0; /* no slash?! */
211 if (!(buf = strdup(tmp)))
214 if (strlen(tool) >= strlen(tmp)) {
218 tmp = buf + (strlen(tmp) - strlen(tool));
220 if (strcmp(tmp, tool) != 0) {
225 if ((tmp = strchr(buf, '_')))
229 if (aftrans_opt(buf))
236 /* Check our protocol family table for this family. */
237 struct aftype *get_aftype(const char *name)
245 while (*afp != NULL) {
246 if (!strcmp((*afp)->name, name))
250 if (index(name, ','))
251 fprintf(stderr, _("Please don't supply more than one address family.\n"));
256 /* Check our protocol family table for this family. */
257 struct aftype *get_afntype(int af)
265 while (*afp != NULL) {
266 if ((*afp)->af == af)
273 /* Check our protocol family table for this family and return its socket */
274 int get_socket_for_af(int af)
282 while (*afp != NULL) {
283 if ((*afp)->af == af)
290 int aftrans_opt(const char *arg)
292 struct aftrans_t *paft;
296 safe_strncpy(buf, arg, sizeof(buf));
302 tmp2 = index(tmp1, ',');
308 for (paft = aftrans; paft->alias; paft++) {
309 if (strcmp(tmp1, paft->alias))
311 if (strlen(paft->name) + strlen(afname) + 1 >= sizeof(afname)) {
312 fprintf(stderr, _("Too much address family arguments.\n"));
319 strcat(afname, paft->name);
323 fprintf(stderr, _("Unknown address family `%s'.\n"), tmp1);
332 /* type: 0=all, 1=getroute */
333 void print_aflist(int type) {
342 while (*afp != NULL) {
343 if ((type == 1 && ((*afp)->rprint == NULL)) || ((*afp)->af == 0)) {
346 if ((count % 3) == 0) fprintf(stderr,count?"\n ":" ");
347 txt = (*afp)->name; if (!txt) txt = "..";
348 fprintf(stderr,"%s (%s) ",txt,(*afp)->title);
352 fprintf(stderr,"\n");