--- gvpe/src/util.h 2003/03/21 23:17:01 1.3 +++ gvpe/src/util.h 2003/10/16 02:41:21 1.9 @@ -2,7 +2,7 @@ util.h -- process management and other utility functions Copyright (C) 1998-2002 Ivo Timmermans 2000-2002 Guus Sliepen - 2003 Marc Lehmannn + 2003 Marc Lehmann 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 @@ -22,16 +22,9 @@ #ifndef UTIL_H__ #define UTIL_H__ -#include -#include - -#include - #include "iom.h" #include "device.h" -#define SOCKADDR sockaddr_in // this is lame, I know - /* * check for an existing vped for this net, and write pid to pidfile */ @@ -57,73 +50,9 @@ */ #define ABSOLUTE_PATH(c) ((c)[0] == '/') -static inline void -id2mac (unsigned int id, void *m) -{ - mac &p = *(mac *)m; - - p[0] = 0xfe; - p[1] = 0xfd; - p[2] = 0x80; - p[3] = 0x00; - p[4] = id >> 8; - p[5] = id; -} - -#define mac2id(p) (p[0] & 0x01 ? 0 : (p[4] << 8) | p[5]) - -struct sockinfo - { - u32 host; - u16 port; +extern void id2mac (unsigned int id, void *m); - void set (const SOCKADDR *sa) - { - host = sa->sin_addr.s_addr; - port = sa->sin_port; - } - - sockinfo() - { - host = port = 0; - } - - sockinfo(const SOCKADDR &sa) - { - set (&sa); - } - - sockinfo(const SOCKADDR *sa) - { - set (sa); - } - - SOCKADDR *sa() - { - static SOCKADDR sa; - - sa.sin_family = AF_INET; - sa.sin_port = port; - sa.sin_addr.s_addr = host; - - return &sa; - } - - operator const char *(); - }; - -inline bool -operator == (const sockinfo &a, const sockinfo &b) -{ - return a.host == b.host && a.port == b.port; -} - -inline bool -operator < (const sockinfo &a, const sockinfo &b) -{ - return a.host < b.host - || (a.host == b.host && a.port < b.port); -} +#define mac2id(p) ((p)[0] & 0x01 ? 0 : ((p)[4] << 8) | (p)[5]) struct sliding_window { u32 v[(WINDOWSIZE + 31) / 32]; @@ -160,7 +89,6 @@ u32 *cell = v + (s >> 5); u32 mask = 1 << (s & 31); - //printf ("received seqno %08lx, seq %08lx, mask %08lx is %08lx\n", seqno, seq, mask, ismask); if (*cell & mask) { slog (L_ERR, _("received duplicate packet (received %08lx, expected %08lx)\n" @@ -176,5 +104,14 @@ } }; +typedef callback0 run_script_cb; + +// run a shell script (or actually an external program). +void run_script (const run_script_cb &cb, bool wait); + +#if ENABLE_HTTP_PROXY +u8 *base64_encode (const u8 *data, unsigned int len); +#endif + #endif