enable -fno-strict-aliasing until the code base gets a hefty clean up to fix all...
[platform/upstream/net-tools.git] / lib / econet.c
1 /*
2  * lib/econet.c This file contains an implementation of the Econet
3  *              support functions for the net-tools.
4  *              (NET-3 base distribution).
5  *
6  * Version:     $Id: econet.c,v 1.11 2000/05/27 17:36:16 pb Exp $
7  *
8  * Author:      Philip Blundell <philb@gnu.org>
9  *
10  * Modified:
11  *
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.
17  */
18
19 #include "config.h"
20
21 #if HAVE_AFECONET
22
23 #include <sys/types.h>
24 #include <sys/socket.h>
25 #include <stdio.h>
26 #include <neteconet/ec.h>
27
28 #include "version.h"
29 #include "net-support.h"
30 #include "pathnames.h"
31 #include "intl.h"
32
33
34 /* Display an Econet address */
35 static char *
36 ec_print(unsigned char *ptr)
37 {
38     static char buff[64];
39     struct ec_addr *ec = (struct ec_addr *) ptr;
40     sprintf(buff, "%d.%d", ec->net, ec->station);
41     return buff;
42 }
43
44
45 /* Display an Econet socket address */
46 static char *
47 ec_sprint(struct sockaddr *sap, int numeric)
48 {
49     struct sockaddr_ec *sec = (struct sockaddr_ec *) sap;
50
51     if (sap->sa_family != AF_ECONET)
52         return _("[NONE SET]");
53
54     return ec_print((unsigned char *) &sec->addr);
55 }
56
57 static int 
58 ec_input(int type, char *bufp, struct sockaddr *sap)
59 {
60     struct sockaddr_ec *sec = (struct sockaddr_ec *) sap;
61     int net, stn;
62     switch (sscanf(bufp, "%d.%d", &net, &stn)) {
63     case 2:
64         sec->addr.station = stn;
65         sec->addr.net = net;
66         return 0;
67     case 1:
68         if (sscanf(bufp, "%d", &stn) == 1) {
69             sec->addr.net = 0;
70             sec->addr.station = stn;
71             return 0;
72         }
73     }
74     return -1;
75 }
76
77 struct aftype ec_aftype =
78 {
79     "ec", NULL, AF_ECONET, 0,
80     ec_print, ec_sprint, ec_input, NULL,
81     NULL, NULL, NULL,
82     -1,
83     "/proc/sys/net/econet"
84 };
85
86 #endif                          /* HAVE_AFECONET */