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.13 2000/05/20 13:38:10 pb 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"
49 "ax25", "ax25", &flag_ax25
52 "ip", "inet", &flag_inet
55 "ip6", "inet6", &flag_inet6
58 "ipx", "ipx", &flag_ipx
61 "appletalk", "ddp", &flag_ddp
64 "netrom", "netrom", &flag_netrom
67 "inet", "inet", &flag_inet
70 "inet6", "inet6", &flag_inet6
73 "ddp", "ddp", &flag_ddp
76 "unix", "unix", &flag_unx
79 "tcpip", "inet", &flag_inet
82 "econet", "ec", &flag_econet
85 "x25", "x25", &flag_x25
88 "ash", "ash", &flag_ash
95 char afname
[256] = "";
97 extern struct aftype unspec_aftype
;
98 extern struct aftype unix_aftype
;
99 extern struct aftype inet_aftype
;
100 extern struct aftype inet6_aftype
;
101 extern struct aftype ax25_aftype
;
102 extern struct aftype netrom_aftype
;
103 extern struct aftype ipx_aftype
;
104 extern struct aftype ddp_aftype
;
105 extern struct aftype ec_aftype
;
106 extern struct aftype x25_aftype
;
107 extern struct aftype rose_aftype
;
108 extern struct aftype ash_aftype
;
110 static short sVafinit
= 0;
112 struct aftype
*aftypes
[] =
153 unspec_aftype
.title
= _("UNSPEC");
155 unix_aftype
.title
= _("UNIX Domain");
158 inet_aftype
.title
= _("DARPA Internet");
161 inet6_aftype
.title
= _("IPv6");
164 ax25_aftype
.title
= _("AMPR AX.25");
167 netrom_aftype
.title
= _("AMPR NET/ROM");
170 ipx_aftype
.title
= _("Novell IPX");
173 ddp_aftype
.title
= _("Appletalk DDP");
176 ec_aftype
.title
= _("Econet");
179 x25_aftype
.title
= _("CCITT X.25");
182 rose_aftype
.title
= _("AMPR ROSE");
185 ash_aftype
.title
= _("Ash");
190 /* set the default AF list from the program name or a constant value */
191 void aftrans_def(char *tool
, char *argv0
, char *dflt
)
196 strcpy(afname
, dflt
);
198 if (!(tmp
= strrchr(argv0
, '/')))
199 tmp
= argv0
; /* no slash?! */
203 if (!(buf
= strdup(tmp
)))
206 if (strlen(tool
) >= strlen(tmp
)) {
210 tmp
= buf
+ (strlen(tmp
) - strlen(tool
));
212 if (strcmp(tmp
, tool
) != 0) {
217 if ((tmp
= strchr(buf
, '_')))
221 if (aftrans_opt(buf
))
228 /* Check our protocol family table for this family. */
229 struct aftype
*get_aftype(const char *name
)
237 while (*afp
!= NULL
) {
238 if (!strcmp((*afp
)->name
, name
))
242 if (index(name
, ','))
243 fprintf(stderr
, _("Please don't supply more than one address family.\n"));
248 /* Check our protocol family table for this family. */
249 struct aftype
*get_afntype(int af
)
257 while (*afp
!= NULL
) {
258 if ((*afp
)->af
== af
)
265 /* Check our protocol family table for this family and return its socket */
266 int get_socket_for_af(int af
)
274 while (*afp
!= NULL
) {
275 if ((*afp
)->af
== af
)
282 int aftrans_opt(const char *arg
)
284 struct aftrans_t
*paft
;
288 safe_strncpy(buf
, arg
, sizeof(buf
));
294 tmp2
= index(tmp1
, ',');
300 for (paft
= aftrans
; paft
->alias
; paft
++) {
301 if (strcmp(tmp1
, paft
->alias
))
303 if (strlen(paft
->name
) + strlen(afname
) + 1 >= sizeof(afname
)) {
304 fprintf(stderr
, _("Too much address family arguments.\n"));
311 strcat(afname
, paft
->name
);
315 fprintf(stderr
, _("Unknown address family `%s'.\n"), tmp1
);
324 /* type: 0=all, 1=getroute */
325 void print_aflist(int type
) {
334 while (*afp
!= NULL
) {
335 if ((type
== 1 && ((*afp
)->rprint
== NULL
)) || ((*afp
)->af
== 0)) {
338 if ((count
% 3) == 0) fprintf(stderr
,count
?"\n ":" ");
339 txt
= (*afp
)->name
; if (!txt
) txt
= "..";
340 fprintf(stderr
,"%s (%s) ",txt
,(*afp
)->title
);
344 fprintf(stderr
,"\n");