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
|
/*
* MacGated - User Space interface to Appletalk-IP decapsulation.
* - Node IP registration and routing daemon.
* Written By: Jay Schulist <Jay.Schulist@spacs.k12.wi.us>
* Copyright (C) 1997-1998 Jay Schulist
*
* Various functions used by the MacGate program suite
*
* Some of the following functions are taken from other
* source code distributed under the GPL. Those functions
* are not under Copyright nor ownership of Jay Schulist.
* Those functions are under the restrictions of the packages from
* which they have been taken from.
*
* This software may be used and distributed according to the terms
* of the GNU Public License, incorporated herein by reference.
*/
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <ctype.h>
#include <sys/socket.h>
#include <linux/in.h>
#include <linux/atalk.h>
#include "MacGate.h"
/*
* Display an IP address in readable format, stolen from
* the Linux kernel.
*/
char *in_ntoa(unsigned long in)
{
static char buff[18];
char *p;
p = (char *) ∈
sprintf(buff, "%d.%d.%d.%d",
(p[0] & 255), (p[1] & 255), (p[2] & 255), (p[3] & 255));
return(buff);
}
/*
* Convert an ASCII string to binary IP, taken from
* the Linux kernel.
*/
unsigned long in_aton(const char *str)
{
unsigned long l;
unsigned int val;
int i;
l = 0;
for (i = 0; i < 4; i++)
{
l <<= 8;
if (*str != '\0')
{
val = 0;
while (*str != '\0' && *str != '.')
{
val *= 10;
val += *str - '0';
str++;
}
l |= val;
if (*str != '\0')
str++;
}
}
return(htonl(l));
}
/*
* HexDump a nice module to help debug localtalk.
*/
int HexDump(unsigned char *pkt_data, int pkt_len)
{
int i;
while(pkt_len>0)
{
printf(" "); /* Leading spaces. */
/* Print the HEX representation. */
for(i=0; i<8; ++i)
{
if(pkt_len - (long)i>0)
printf("%2.2X ", pkt_data[i] & 0xFF);
else
printf(" ");
}
printf(":");
for(i=8; i<16; ++i)
{
if(pkt_len - (long)i>0)
printf("%2.2X ", pkt_data[i]&0xFF);
else
printf(" ");
}
/* Print the ASCII representation. */
printf(" ");
for(i=0; i<16; ++i)
{
if(pkt_len - (long)i>0)
{
if(isprint(pkt_data[i]))
printf("%c", pkt_data[i]);
else
printf(".");
}
}
printf("\n");
pkt_len -= 16;
pkt_data += 16;
}
printf("\n");
return 0;
}
|