forked from mohnkhan/xavl2tp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ipv6misc.c
executable file
·107 lines (97 loc) · 2.06 KB
/
ipv6misc.c
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
/*
* Layer Two Tunnelling Protocol Daemon
* Copyright (C) 1998 Adtran, Inc.
* Copyright (C) 2002 Jeff McAdams
*
* Mark Spencer
*
* This software is distributed under the terms
* of the GPL, which you should have received
* along with this source.
*
* Miscellaneous but important functions
*
*/
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <syslog.h>
#if defined(SOLARIS)
# include <varargs.h>
#endif
#include <netinet/in.h>
#include "l2tp.h"
void set_error6 (struct call6 *c, int error, const char *fmt, ...)
{
va_list args;
va_start (args, fmt);
c->error = error;
c->result = RESULT_ERROR;
c->needclose = -1;
vsnprintf (c->errormsg, sizeof (c->errormsg), fmt, args);
if (c->errormsg[strlen (c->errormsg) - 1] == '\n')
c->errormsg[strlen (c->errormsg) - 1] = 0;
va_end (args);
}
struct buffer6 *new_buf6 (int size)
{
struct buffer6 *b = malloc (sizeof (struct buffer6));
if (!b || !size || size < 0)
return NULL;
b->rstart = malloc (size);
if (!b->rstart)
{
free (b);
return NULL;
}
b->start = b->rstart;
b->rend = b->rstart + size - 1;
b->len = size;
b->maxlen = size;
return b;
}
inline void recycle_buf6 (struct buffer6 *b)
{
b->start = b->rstart;
b->len = b->maxlen;
}
void do_packet_dump6 (struct buffer6 *buf)
{
int x;
unsigned char *c = buf->start;
printf ("packet dump: \nHEX: { ");
for (x = 0; x < buf->len; x++)
{
printf ("%.2X ", *c);
c++;
};
printf ("}\nASCII: { ");
c = buf->start;
for (x = 0; x < buf->len; x++)
{
if (*c > 31 && *c < 127)
{
putchar (*c);
}
else
{
putchar (' ');
}
c++;
}
printf ("}\n");
}
inline void toss6 (struct buffer6 *buf)
{
/*
* Toss a frame and free up the buffer that contained it
*/
free (buf->rstart);
free (buf);
}