2 * lib/x25.c This file contains an implementation of the "X.25"
3 * support functions for the NET-3 base distribution.
5 * Version: @(#)x25.c 1.00 08/15/98
7 * Author: Stephane Fillod, <sfillod@charybde.gyptis.frmug.org>
9 * Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
10 * Copyright 1993 MicroWalt Corporation
12 * This program is free software; you can redistribute it
13 * and/or modify it under the terms of the GNU General
14 * Public License as published by the Free Software
15 * Foundation; either version 2 of the License, or (at
16 * your option) any later version.
20 #if HAVE_AFX25 || HAVE_HWX25
21 #include <sys/types.h>
22 #include <sys/ioctl.h>
23 #include <sys/socket.h>
24 #include <linux/x25.h>
25 #include <net/if_arp.h> /* ARPHRD_X25 */
34 #include "net-support.h"
35 #include "pathnames.h"
38 #include "net-locale.h"
42 static char X25_errmsg[128];
45 extern struct aftype x25_aftype;
47 /* is in net/x25.h, not in the public header file linux/x25.h. Why?*/
49 #define X25_ADDR_LEN 16
54 X25_print(const char *ptr)
56 static char buff[X25_ADDR_LEN+1];
58 strncpy(buff, ptr, X25_ADDR_LEN);
59 buff[X25_ADDR_LEN] = '\0';
65 /* Display an X.25 socket address. */
67 X25_sprint(struct sockaddr *sap, int numeric)
69 if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
70 return( _("[NONE SET]"));
71 return(X25_print(((struct sockaddr_x25 *)sap)->sx25_addr.x25_addr));
76 * return the sigdigits of the address
79 X25_input(int type, char *bufp, struct sockaddr *sap)
83 unsigned int sigdigits;
85 sap->sa_family = x25_aftype.af;
86 ptr = ((struct sockaddr_x25 *)sap)->sx25_addr.x25_addr;
89 /* Address the correct length ? */
90 if (strlen(bufp)>18) {
91 strcpy(X25_errmsg, _("Address can't exceed eighteen digits with sigdigits"));
93 fprintf(stderr, "x25_input(%s): %s !\n", X25_errmsg, orig);
100 if ((p = strchr(bufp, '/')) != NULL) {
102 sigdigits = atoi(p + 1);
104 sigdigits = strlen(bufp);
107 if (strlen(bufp) < 1 || strlen(bufp) > 15 || sigdigits > strlen(bufp)) {
110 strcpy(X25_errmsg, _("Invalid address"));
112 fprintf(stderr, "x25_input(%s): %s !\n", X25_errmsg, orig);
118 strncpy(ptr, bufp, sigdigits+1);
122 fprintf(stderr, "x25_input(%s): ", orig);
123 for (i = 0; i < sizeof(x25_address); i++)
124 fprintf(stderr, "%02X ", sap->sa_data[i] & 0377);
125 fprintf(stderr, "\n");
132 /* Display an error message. */
134 X25_herror(char *text)
136 if (text == NULL) fprintf(stderr, "%s\n", X25_errmsg);
137 else fprintf(stderr, "%s: %s\n", text, X25_errmsg);
142 X25_hinput(char *bufp, struct sockaddr *sap)
144 if (X25_input(0, bufp, sap) < 0) return(-1);
145 sap->sa_family = ARPHRD_X25;
150 struct hwtype x25_hwtype = {
151 "x25", NULL, /*"CCITT X.25",*/ ARPHRD_X25, X25_ADDR_LEN,
152 X25_print, X25_hinput, NULL
155 struct aftype x25_aftype =
157 "x25", NULL, /*"CCITT X.25", */ AF_X25, X25_ADDR_LEN,
158 X25_print, X25_sprint, X25_input, X25_herror,
159 X25_rprint, X25_rinput, NULL /* getmask */,
165 #endif /* HAVE_xxX25 */