vde_autolink: Add missing null entry in getopt_long array.
[vde.git] / vde-2 / src / vde_over_ns / util.c
blobf41d3a007b7305cad1fed2e40e3ac6cc6cab6ca9
1 /* ----------------------------------------------------------------------------
3 VDE_OVER_NS
4 (C) 2007 Daniele Lacamera
6 Derived from:
7 NSTX -- tunneling network-packets over DNS
9 (C) 2000 by Florian Heinz and Julien Oster
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License version 2, as
13 published by the Free Software Foundation.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 -------------------------------------------------------------------------- */
26 #include <string.h>
27 #include <stdlib.h>
28 #include <fcntl.h>
29 #include <unistd.h>
30 #include <netinet/in.h>
31 #include <stdio.h>
32 #include <sys/types.h>
33 #include <sys/socket.h>
35 #include <config.h>
36 #include <vde.h>
37 #include <vdecommon.h>
39 #include "fun.h"
41 int checksum (unsigned char *buf, int len)
43 int x = 0;
45 while (len--)
46 x ^= buf[len];
48 return x;
51 void dwrite (char *path, char *buf, int len) {
52 int fd;
54 fd = open(path, O_RDWR|O_CREAT|O_TRUNC, 0600);
55 write(fd, buf, len);
56 close(fd);
59 #ifdef WITH_PKTDUMP
60 void
61 pktdump (const char *prefix, unsigned short id, const char *data,
62 size_t len, int s) {
63 int fd;
64 char buf[30];
65 return;
66 snprintf(buf, 30, "%s%hu%c", prefix, id, s ? 's' : 'r');
67 if ((fd = open(buf, O_WRONLY|O_CREAT|O_TRUNC, 0600)) >= 0) {
68 write(fd, data, len);
69 close(fd);
72 #endif