[insert project logo here (125x200px max)]

Navigator

Mailinglists

Please report any errors or ommissions you find to our `Help' mailinglist, or post a message in the Forums.

Copyright and Licensing Information

Snap is (c) Jonathan T. Moore, 1999-2002 and licensed under the GNU General Public License (GPL).

All other parts of Splash are (c) Willem de Bruijn, 2002-2003 and licensed under the BSD Open Source License.

All sourcecode is made publicly available.

Acknowledgement

Splash and the Splash website are hosted by SourceForge.net

SourceForge.net Logo

osi-open source certified logo

Splash - Documentation

SNMP Plus a Lightweight API for SNAP Handling

Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

snap-1.1-wjdb/lib/af.c

Go to the documentation of this file.
00001 /*
00002  * lib/af.c This file contains the top-level part of the protocol
00003  *      support functions module for the NET-2 base distribution.
00004  *
00005  * Version: lib/af.c 1.13 (1996-02-21)
00006  *
00007  * Author:  Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
00008  *      Copyright 1993 MicroWalt Corporation
00009  *
00010  *      This program is free software; you can redistribute it
00011  *      and/or  modify it under  the terms of  the GNU General
00012  *      Public  License as  published  by  the  Free  Software
00013  *      Foundation;  either  version 2 of the License, or  (at
00014  *      your option) any later version.
00015  */
00016 #include <sys/types.h>
00017 #include <sys/socket.h>
00018 #include <stdlib.h>
00019 #include <stdio.h>
00020 #include <errno.h>
00021 #include <ctype.h>
00022 #include <string.h>
00023 #include <unistd.h>
00024 #include "config.h"
00025 #include "net-support.h"
00026 #include "pathnames.h"
00027 #include "intl.h"
00028 
00029 
00030 int flag_unx = 0;
00031 int flag_ipx = 0;
00032 int flag_ax25 = 0;
00033 int flag_ddp = 0;
00034 int flag_netrom = 0;
00035 int flag_inet = 0;
00036 int flag_inet6 = 0;
00037 int flag_econet = 0;
00038 
00039 
00040 struct aftrans_t {
00041     char *alias;
00042     char *name;
00043     int  *flag;
00044 } aftrans[]={
00045     {"ax25",    "ax25",     &flag_ax25},
00046     {"ip",      "inet",     &flag_inet},
00047     {"ip6",     "inet6",        &flag_inet6},
00048     {"ipx",     "ipx",      &flag_ipx},
00049     {"appletalk",   "ddp",      &flag_ddp},
00050     {"netrom",  "netrom",   &flag_netrom},
00051     {"inet",    "inet",     &flag_inet},
00052     {"inet6",   "inet6",        &flag_inet6},
00053     {"ddp",     "ddp",      &flag_ddp},
00054     {"unix",    "unix",     &flag_unx},
00055     {"tcpip",   "inet",     &flag_inet},
00056     {"econet",  "ec",       &flag_econet},
00057     {0,     0,      0}
00058 };
00059 
00060 char        afname[256]="";
00061 
00062 extern  struct aftype   unspec_aftype;
00063 extern  struct aftype   unix_aftype;
00064 extern  struct aftype   inet_aftype;
00065 extern  struct aftype   inet6_aftype;
00066 extern  struct aftype   ax25_aftype;
00067 extern  struct aftype   netrom_aftype;
00068 extern  struct aftype   ipx_aftype;
00069 extern  struct aftype   ddp_aftype;
00070 extern  struct aftype   ec_aftype;
00071 
00072 static short sVafinit = 0;
00073 
00074 static struct aftype *aftypes[] = {
00075 #if HAVE_AFUNIX
00076   &unix_aftype,
00077 #endif
00078 #if HAVE_AFINET
00079   &inet_aftype,
00080 #endif
00081 #if HAVE_AFINET6
00082   &inet6_aftype,
00083 #endif
00084 #if HAVE_AFAX25
00085   &ax25_aftype,
00086 #endif
00087 #if HAVE_AFNETROM
00088   &netrom_aftype,
00089 #endif
00090 #if HAVE_AFIPX
00091   &ipx_aftype,
00092 #endif
00093 #if HAVE_AFATALK
00094   &ddp_aftype,
00095 #endif
00096 #if HAVE_AFECONET
00097   &ec_aftype,
00098 #endif
00099   &unspec_aftype,
00100   NULL
00101 };
00102 
00103 void afinit ()
00104 {
00105   unspec_aftype.title = _("UNSPEC");
00106 #if HAVE_AFINET
00107   unix_aftype.title = _("UNIX Domain");
00108 #endif
00109 #if HAVE_AFINET
00110   inet_aftype.title = _("DARPA Internet");
00111 #endif
00112 #if HAVE_AFINET6
00113   inet6_aftype.title = _("IPv6");
00114 #endif
00115 #if HAVE_AFAX25
00116   ax25_aftype.title = _("AMPR AX.25");
00117 #endif
00118 #if HAVE_AFNETROM
00119   netrom_aftype.title = _("AMPR NET/ROM");
00120 #endif
00121 #if HAVE_AFIPX
00122   ipx_aftype.title = _("IPX");
00123 #endif
00124 #if HAVE_AFATALK
00125   ddp_aftype.title = _("Appletalk DDP");
00126 #endif
00127 #if HAVE_AFCONET
00128   ec_aftype.title = _("Econet");
00129 #endif
00130   sVafinit = 1;
00131 }
00132 
00133 /* set the default AF list from the program name or a constant value    */
00134 void
00135 aftrans_def(char *tool, char *argv0, char *dflt)
00136 {
00137   char *tmp;
00138   char *buf;
00139   
00140   strcpy(afname, dflt);
00141 
00142   if (!(tmp = strrchr(argv0, '/')))
00143     tmp = argv0;            /* no slash?! */
00144   else
00145     tmp++;
00146   
00147   if (!(buf = strdup(tmp)))
00148     return;
00149 
00150   if (strlen(tool) >= strlen(tmp)) {
00151     free(buf);
00152     return;
00153   }
00154   tmp = buf+(strlen(tmp)-strlen(tool));
00155   
00156   if (strcmp(tmp, tool)!=0) {
00157     free(buf);
00158     return;
00159   }
00160   
00161   *tmp = '\0';
00162   if ((tmp = strchr(buf,'_')))
00163     *tmp = '\0';
00164   
00165   afname[0]='\0';
00166   if (aftrans_opt(buf))
00167     strcpy(afname, buf);
00168 
00169   free(buf);
00170 }
00171 
00172 
00173 /* Check our protocol family table for this family. */
00174 struct aftype *
00175 get_aftype(const char *name)
00176 {
00177   struct aftype **afp;
00178 
00179   if (!sVafinit)
00180     afinit ();
00181   
00182   afp = aftypes;
00183   while (*afp != NULL) {
00184     if (!strcmp((*afp)->name, name)) return(*afp);
00185     afp++;
00186   }
00187   if (index(name,','))
00188     fprintf(stderr,_("Please don't supply more than one address family.\n"));
00189   return(NULL);
00190 }
00191 
00192 
00193 /* Check our protocol family table for this family. */
00194 struct aftype *
00195 get_afntype(int af)
00196 {
00197   struct aftype **afp;
00198 
00199   if (!sVafinit)
00200     afinit ();
00201   
00202   afp = aftypes;
00203   while (*afp != NULL) {
00204     if ((*afp)->af == af) return(*afp);
00205     afp++;
00206   }
00207   return(NULL);
00208 }
00209 
00210 
00211 int aftrans_opt(const char *arg)
00212 {
00213     struct aftrans_t *paft;
00214     char *tmp1, *tmp2;
00215     char buf[256];
00216         
00217     strncpy(buf,arg,sizeof(buf));
00218     buf[sizeof(buf)-1]='\0';
00219     
00220     tmp1=buf;
00221     
00222     while(tmp1) {
00223     
00224         tmp2=index(tmp1,',');
00225 
00226         if (tmp2)
00227             *(tmp2++)='\0';
00228             
00229         paft=aftrans;
00230         for(paft=aftrans;paft->alias;paft++) {
00231             if (strcmp(tmp1,paft->alias))
00232                 continue;
00233             if (strlen(paft->name)+strlen(afname)+1 >= sizeof(afname)) {
00234                 fprintf(stderr,_("Too much address family arguments.\n"));              
00235                 return(0);
00236             }
00237             if (paft->flag)
00238                 (*paft->flag)++;
00239             if (afname[0])
00240                 strcat(afname,",");
00241             strcat(afname,paft->name);
00242             break;
00243         }
00244         if (!paft->alias) {
00245             fprintf(stderr,_("Unknown address family `%s'.\n"),tmp1);           
00246             return(1);
00247         }
00248         tmp1=tmp2;
00249     }
00250 
00251     return(0);
00252 }