File: ipxutil.c

package info (click to toggle)
ipxripd 0.7-12
  • links: PTS
  • area: main
  • in suites: woody
  • size: 200 kB
  • ctags: 265
  • sloc: ansic: 2,867; makefile: 74; sh: 32
file content (129 lines) | stat: -rw-r--r-- 2,628 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
    IPX support library - general functions

    Copyright (C) 1994, 1995  Ales Dryak <e-mail: A.Dryak@sh.cvut.cz>
    Copyright (C) 1996, Volker Lendecke <lendecke@namu01.gwdg.de>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/
#include <string.h>
#include <netinet/in.h>
#include "ipxutil.h"

void
ipx_fprint_node(FILE *file, IPXNode node)
{
	fprintf(file,"%02X%02X%02X%02X%02X%02X",
		(unsigned char)node[0],
		(unsigned char)node[1],
		(unsigned char)node[2],
		(unsigned char)node[3],
		(unsigned char)node[4],
		(unsigned char)node[5]
		);
}

void
ipx_fprint_network(FILE *file, IPXNet net)
{
	fprintf(file,"%08lX",net);
}

void
ipx_fprint_port(FILE *file, IPXPort port)
{
	fprintf(file,"%04X",port);
}

void
ipx_fprint_saddr(FILE *file, struct sockaddr_ipx *sipx)
{
	ipx_fprint_network(file,ntohl(sipx->sipx_network));
	fprintf(file,":");
	ipx_fprint_node(file,sipx->sipx_node);
	fprintf(file,":");
	ipx_fprint_port(file,ntohs(sipx->sipx_port));
}

void
ipx_print_node(IPXNode node)
{
	ipx_fprint_node(stdout,node);
}

void
ipx_print_network(IPXNet net)
{
	ipx_fprint_network(stdout,net);
}

void
ipx_print_port(IPXPort port)
{
	ipx_fprint_port(stdout,port);
}

void
ipx_print_saddr(struct sockaddr_ipx *sipx)
{
	ipx_fprint_saddr(stdout,sipx);
}

void
ipx_assign_node(IPXNode dest, IPXNode src)
{
	memcpy(dest,src,sizeof(IPXNode));
}

int
ipx_node_equal(IPXNode n1, IPXNode n2)
{
	return memcmp(n1,n2,sizeof(IPXNode))==0;
}

int
ipx_sscanf_node(char *buf, IPXNode node)
{
	int i;
	int n[6];

	if ((i = sscanf(buf, "%2x%2x%2x%2x%2x%2x",
			&(n[0]), &(n[1]), &(n[2]),
			&(n[3]), &(n[4]), &(n[5]))) != 6)
	{
		return -1;
	}

	for (i=0; i<6; i++)
	{
		node[i] = n[i];
	}
	return 0;
}

int
ipx_sscanf_net(char *buf, IPXNet *target)
{
	if (sscanf(buf, "%8lX", target) == 1)
	{
		return 0;
	}
	return -1;
}

IPXNode ipx_this_node={0,0,0,0,0,0};
IPXNode ipx_broadcast_node={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
char ipx_err_string[IPX_MAX_ERROR+1]="no error detected";