[pso] Fwd: test tema 5 win
Octavian Purdila
pso@cursuri.cs.pub.ro
Wed, 9 Jun 2004 12:16:09 +0300
--Boundary-00=_ZVtxAt06buFyfyP
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Ioana a portat utilitarul si testul de la tema 5 pe windows. Mai jos aveti
detalii si atasate sunt testul/utilitarul. O sa le pun si pe site.
---------- Forwarded Message ----------
Subject: test tema 5 win
Date: Tuesday 08 June 2004 20:27
From: Ioana Cutcutache <ioana_c@idilis.ro>
To: "Octavian Purdila" <tavi@cs.pub.ro>
Am portat eu utilitarul si testul pt. tema 5 pe windows.
Pentru FW_LIST trebuie facut insa un pic altfel intrucat DeviceIoControl nu
intoarce nimic. Astfel driver-ul primeste in buffer-ul de input un numar de
reguli care indica zona alocata. Daca numarul de reguli e mai mare decat cel
dat driver-ul trebuie sa puna in buffer-ul de iesire numarul de reguli si sa
intoarca STATUS_SUCCESS (ideea e ca daca nu intoarce succes nu se copiaza in
buffer-ul de iesire ce pune el). Daca zona alocata e suficient de mare
driver-ul trebuie sa puna in buffer-ul de iesire mai intai numarul de reguli
si apoi lista lor. Trebuie pus si numarul de reguli pentru ca utilitarul sa
aiba cum sa isi dea seama daca apelul a reusit si a fost intoarsa si lista
de reguli.
In ceea ce priveste testul, cum pe win nu sunt semnale si nu am ceva de genul
alarm, singura solutie gasita era ca la accept sa fac un select cu un
timeout. Connect-ul am vazut ca are el un timeout care insa este ceva mai
mare de aceea la testul de connect care trebuie sa esueze o sa dureze ceva
mai mult.
--Boundary-00=_ZVtxAt06buFyfyP
Content-Type: text/html;
charset="iso-8859-1";
name=" "
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2600.0" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Am portat eu utilitarul si testul pt. =
tema 5 pe=20
windows.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Pentru FW_LIST trebuie facut insa un =
pic altfel=20
intrucat DeviceIoControl nu intoarce nimic.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Astfel driver-ul primeste in buffer-ul =
de input un=20
numar de reguli care indica zona alocata. Daca numarul de reguli e mai =
mare=20
decat cel dat driver-ul trebuie sa puna in buffer-ul de iesire numarul =
de reguli=20
si sa intoarca STATUS_SUCCESS (ideea e ca daca nu intoarce succes nu se =
copiaza=20
in buffer-ul de iesire ce pune el). Daca zona alocata e suficient de =
mare=20
driver-ul trebuie sa puna in buffer-ul de iesire mai =
intai numarul de=20
reguli si apoi lista lor. Trebuie pus si numarul de reguli pentru ca =
utilitarul=20
sa aiba cum sa isi dea seama daca apelul a reusit si a fost intoarsa si =
lista de=20
reguli.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>In ceea ce priveste testul, cum pe win =
nu sunt=20
semnale si nu am ceva de genul alarm, singura solutie gasita era ca la =
accept sa=20
fac un select cu un timeout. Connect-ul am vazut ca are el un timeout =
care insa=20
este ceva mai mare de aceea la testul de connect care trebuie sa esueze =
o sa=20
dureze ceva mai mult.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>ps : nu am reusit sa citesc cd-ul :( . =
eu maine o=20
sa am un examen si ajung la facultate. este ok daca trec sa aduc un alt=20
cd?</FONT></DIV></BODY></HTML>
--Boundary-00=_ZVtxAt06buFyfyP
Content-Type: text/plain;
charset="iso-8859-1";
name="test.c"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="test.c"
#include <stdio.h>=0A=
#include <time.h>=0A=
#include <windows.h>=0A=
=0A=
#include "ipnecklace.h"=0A=
=0A=
int seq=3D1, rules=3D0, in=3D0;=0A=
SOCKET control_socket;=0A=
HANDLE null_handle;=0A=
char *list=3D"ipnecklace.exe list";=0A=
char *null=3D"null";=0A=
=0A=
const char* print_error()=0A=
{=0A=
char *error;=0A=
=0A=
=
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|F=
ORMAT_MESSAGE_IGNORE_INSERTS,=0A=
NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), =
(char*)&error, 0, NULL);=0A=
return error;=0A=
}=0A=
=0A=
#define test(s, t) \=0A=
{\=0A=
unsigned int i;\=0A=
\=0A=
printf("test: %s", s); \=0A=
fflush(stdout);\=0A=
for(i=3D0; i<60-strlen(s); i++)\=0A=
putchar('.');\=0A=
if (!(t))\=0A=
printf("failed: %s\n", print_error());\=0A=
else\=0A=
printf("passed\n");\=0A=
fflush(stdout);\=0A=
}=0A=
=0A=
int convert(SOCKET x)=0A=
{=0A=
if (x =3D=3D INVALID_SOCKET)=0A=
return -1;=0A=
return 1;=0A=
}=0A=
=0A=
int execute(char * cmd_line, HANDLE fis_output)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
int cod;
ZeroMemory(&si, sizeof(si));
si.cb =3D sizeof(si);
si.hStdOutput =3D fis_output;=0A=
si.dwFlags =3D STARTF_USESTDHANDLES;
ZeroMemory(&pi, sizeof(pi));
CreateProcess(NULL, cmd_line, NULL, NULL, FALSE, 0, NULL, NULL, &si, =
&pi);
WaitForSingleObject(pi.hProcess, INFINITE);
GetExitCodeProcess(pi.hProcess, &cod);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return cod;
}=0A=
=0A=
=0A=
=0A=
void test_rules(int x)=0A=
{=0A=
if (in) {=0A=
rules+=3Dx;=0A=
test("no of rules", (x=3Dexecute(list, null_handle)) =3D=3D rules);=0A=
}=0A=
}=0A=
=0A=
int do_read(SOCKET fd, char *buffer, int size)=0A=
{=0A=
int n, from=3D0;=0A=
=0A=
while (1) {=0A=
n=3Drecv(fd, &buffer[from], size-from, 0);=0A=
if (n =3D=3D SOCKET_ERROR)=0A=
return -1;=0A=
if (n+from =3D=3D size)=0A=
return 0;=0A=
from+=3Dn;=0A=
}=0A=
}=0A=
=0A=
int do_write(SOCKET fd, char *buffer, int size)=0A=
{=0A=
int n, from=3D0;=0A=
=0A=
while (1) {=0A=
n=3Dsend(fd, &buffer[from], size-from, 0);=0A=
if (n =3D=3D SOCKET_ERROR)=0A=
return -1;=0A=
if (n+from =3D=3D size)=0A=
return 0;=0A=
from+=3Dn;=0A=
}=0A=
}=0A=
=0A=
SOCKET do_listen(int type, unsigned short port)=0A=
{=0A=
SOCKET sock;=0A=
SOCKADDR_IN name;=0A=
=0A=
/* Create the socket. */=0A=
sock =3D socket(PF_INET, type, 0);=0A=
if (sock =3D=3D INVALID_SOCKET)=0A=
return INVALID_SOCKET;=0A=
=0A=
/* Look for a free port */=0A=
ZeroMemory(&name, sizeof(name));=0A=
name.sin_family=3DAF_INET;=0A=
name.sin_addr.s_addr=3Dhtonl(INADDR_ANY);=0A=
name.sin_port =3D htons(port);=0A=
=0A=
if (bind(sock, (struct sockaddr *) &name, sizeof(name)) =3D=3D =
SOCKET_ERROR) {=0A=
closesocket(sock);=0A=
return INVALID_SOCKET;=0A=
}=0A=
=0A=
=0A=
if (type =3D=3D SOCK_STREAM && (listen(sock, 1) =3D=3D SOCKET_ERROR)) {=0A=
closesocket(sock);=0A=
return INVALID_SOCKET;=0A=
}=0A=
=0A=
return sock;=0A=
=0A=
}=0A=
=0A=
SOCKET do_connect(int type, const char *hostname, unsigned short port)=0A=
{=0A=
struct hostent *hostinfo;=0A=
SOCKADDR_IN name;=0A=
SOCKET sock;=0A=
=0A=
/* Create the socket. */=0A=
sock =3D socket(PF_INET, type, 0);=0A=
if (sock =3D=3D INVALID_SOCKET)=0A=
return INVALID_SOCKET;=0A=
=0A=
/* fill the address */=0A=
ZeroMemory(&name, sizeof(name));=0A=
name.sin_family=3DAF_INET;=0A=
name.sin_port =3D htons(port);=0A=
name.sin_addr.s_addr =3D inet_addr(hostname);=0A=
=0A=
if (connect(sock, (struct sockaddr*)&name, sizeof(name)) =3D=3D =
SOCKET_ERROR) {=0A=
closesocket(sock);=0A=
return INVALID_SOCKET;=0A=
}=0A=
=0A=
return sock;=0A=
}=0A=
=0A=
=0A=
SOCKET do_accept(SOCKET sock)=0A=
{=0A=
SOCKET csock;=0A=
SOCKADDR_IN caddr;=0A=
int csize=3Dsizeof(caddr), ret;=0A=
fd_set read_fds;=0A=
=0A=
struct timeval timeout;=0A=
timeout.tv_sec =3D 5;=0A=
timeout.tv_usec =3D 0;=0A=
=0A=
FD_ZERO(&read_fds);=0A=
FD_SET(sock, &read_fds);=0A=
=0A=
//astept 5 secunde cerere de conectare=0A=
ret =3D select(sock+1, &read_fds, NULL, NULL, &timeout);=0A=
if (ret =3D=3D SOCKET_ERROR || ret =3D=3D 0)=0A=
return INVALID_SOCKET;=0A=
if (FD_ISSET(sock, &read_fds))=0A=
csock =3D accept(sock, (struct sockaddr*)&caddr, &csize);=0A=
else return INVALID_SOCKET;=0A=
=0A=
return csock;=0A=
}=0A=
=0A=
=0A=
int do_send(SOCKET sock, int seq)=0A=
{=0A=
return do_write(sock, (char*)&seq, sizeof(seq));=0A=
}=0A=
=0A=
int do_recv(SOCKET sock)=0A=
{=0A=
int seq;=0A=
=0A=
if (do_read(sock, (char*)&seq, sizeof(seq)))=0A=
return -1;=0A=
return seq;=0A=
}=0A=
=0A=
#define ping_pong(sock) \=0A=
test("ping", do_send(sock, seq++) =3D=3D 0);\=0A=
test("pong", do_recv(sock) =3D=3D seq++);=0A=
=0A=
#define pong_ping(sock) \=0A=
test("pong", do_recv(sock) =3D=3D seq++);\=0A=
test("ping", do_send(sock, seq++) =3D=3D 0);=0A=
=0A=
=0A=
=0A=
=0A=
void wait_conn(int type, int pass, int add_rule)=0A=
{=0A=
SOCKET sock, sock2;=0A=
int port;=0A=
=0A=
do {=0A=
port=3D1024+(rand()%64000);=0A=
} while ((sock=3Ddo_listen(type, port)) =3D=3D INVALID_SOCKET);=0A=
=0A=
if (add_rule) {=0A=
char add_rule[1024];=0A=
sprintf(add_rule, "ipnecklace.exe add 0.0.0.0/0 0.0.0.0/0 0:65535 =
%d:%d ", port, port);=0A=
test("add firewall rule", execute(add_rule, =
GetStdHandle(STD_OUTPUT_HANDLE)) =3D=3D 0);=0A=
test_rules(1);=0A=
}=0A=
=0A=
test("send port", do_send(control_socket, port) =3D=3D 0);=0A=
if (type =3D=3D SOCK_STREAM)=0A=
test("wait connection", convert(sock2=3Ddo_accept(sock))*pass > 0);=0A=
=0A=
if (pass > 0) {=0A=
if (type =3D=3D SOCK_STREAM) {=0A=
pong_ping(sock2);=0A=
closesocket(sock2);=0A=
} else {=0A=
SOCKADDR_IN addr;=0A=
int tmp, tmp2=3Dsizeof(addr);=0A=
=0A=
test("UDP pong", recvfrom(sock, (char*) &tmp, 4, 0, (struct =
sockaddr*)&addr, &tmp2) =3D=3D 4 && tmp =3D=3D seq++);=0A=
test("UDP ping", (tmp=3Dseq++,sendto(sock, (char*) &tmp, 4, =
sizeof(tmp), (struct sockaddr*)&addr, sizeof(addr)) =3D=3D 4));=0A=
}=0A=
}=0A=
=0A=
closesocket(sock);=0A=
}=0A=
=0A=
=0A=
void make_conn(int type, const char *hostname, int pass)=0A=
{=0A=
int port;=0A=
SOCKET sock;=0A=
=0A=
test("recv port", (port=3Ddo_recv(control_socket)) > 0);=0A=
sock=3Ddo_connect(type, hostname, port);=0A=
if (type =3D=3D SOCK_STREAM)=0A=
test("make connection", sock*pass > 0);=0A=
=0A=
if (pass > 0) {=0A=
ping_pong(sock);=0A=
test_rules(1);=0A=
closesocket(sock);=0A=
Sleep(1000);=0A=
test_rules(-1);=0A=
}=0A=
}=0A=
=0A=
=0A=
int inside(const char *hostname, int cport)=0A=
{=0A=
char *enable=3D"ipnecklace.exe enable ";=0A=
=0A=
in=3D1;=0A=
=0A=
test("enable firewall", execute(enable, =
GetStdHandle(STD_OUTPUT_HANDLE)) =3D=3D 0);=0A=
test("establish control connection", =
(control_socket=3Ddo_connect(SOCK_STREAM, hostname, cport)) !=3D =
INVALID_SOCKET);=0A=
=0A=
test_rules(1);=0A=
=0A=
pong_ping(control_socket);=0A=
=0A=
wait_conn(SOCK_STREAM, -1, 0);=0A=
=0A=
ping_pong(control_socket);=0A=
=0A=
wait_conn(SOCK_DGRAM, -1, 0);=0A=
=0A=
pong_ping(control_socket);=0A=
=0A=
wait_conn(SOCK_STREAM, 1, 1);=0A=
=0A=
ping_pong(control_socket);=0A=
=0A=
wait_conn(SOCK_DGRAM, 1, 1);=0A=
=0A=
pong_ping(control_socket);=0A=
=0A=
make_conn(SOCK_STREAM, hostname, 2);=0A=
=0A=
ping_pong(control_socket);=0A=
=0A=
make_conn(SOCK_DGRAM, hostname, 2);=0A=
=0A=
pong_ping(control_socket);=0A=
=0A=
return 0;=0A=
}=0A=
=0A=
=0A=
int outside(const char *hostname, int cport)=0A=
{=0A=
=0A=
SOCKET sock;=0A=
=0A=
test("establish control connection", (sock=3Ddo_listen(SOCK_STREAM, =
cport)) !=3D INVALID_SOCKET && (control_socket=3Ddo_accept(sock)) !=3D =
INVALID_SOCKET);=0A=
=0A=
ping_pong(control_socket);=0A=
=0A=
make_conn(SOCK_STREAM, hostname, -1);=0A=
=0A=
pong_ping(control_socket);=0A=
=0A=
make_conn(SOCK_DGRAM, hostname, -1);=0A=
=0A=
ping_pong(control_socket);=0A=
=0A=
make_conn(SOCK_STREAM, hostname, 1);=0A=
=0A=
pong_ping(control_socket);=0A=
=0A=
make_conn(SOCK_DGRAM, hostname, 1);=0A=
=0A=
ping_pong(control_socket);=0A=
=0A=
wait_conn(SOCK_STREAM, 1, 0);=0A=
=0A=
pong_ping(control_socket);=0A=
=0A=
wait_conn(SOCK_DGRAM, 1, 0);=0A=
=0A=
ping_pong(control_socket);=0A=
=0A=
return 0;=0A=
}=0A=
=0A=
#define exit_with_syntax \=0A=
{\=0A=
printf("syntax: test inside ip_address port\n");\=0A=
printf(" test outside ip_address port\n");\=0A=
}=0A=
=0A=
/*=0A=
test inside ip_address port=0A=
test outside ip_address port=0A=
*/=0A=
=0A=
int main(int argc, char **argv)=0A=
{=0A=
WSADATA wsaData;=0A=
int ret=3D0;=0A=
=0A=
srand(time(NULL));=0A=
=0A=
if (argc !=3D 4) {=0A=
exit_with_syntax;=0A=
return -1;=0A=
}=0A=
=0A=
null_handle =3D CreateFile(null, GENERIC_READ | GENERIC_WRITE, 0, NULL, =
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);=0A=
=0A=
if (WSAStartup(MAKEWORD(2,0), &wsaData)!=3D0)
return -1;=0A=
=0A=
if (strcmp(argv[1], "inside") =3D=3D 0)=0A=
ret=3Dinside(argv[2], atoi(argv[3]));=0A=
else if (strcmp(argv[1], "outside") =3D=3D 0)=0A=
ret=3Doutside(argv[2], atoi(argv[3]));=0A=
else exit_with_syntax;=0A=
=0A=
WSACleanup();=0A=
CloseHandle(null_handle);=0A=
return ret;=0A=
}=0A=
--Boundary-00=_ZVtxAt06buFyfyP
Content-Type: text/plain;
charset="iso-8859-1";
name="ipnecklace.c"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="ipnecklace.c"
#include <stdio.h>=0A=
#include <string.h>=0A=
#include <windows.h>=0A=
=0A=
#include "ipnecklace.h"=0A=
=0A=
/*=0A=
ipnecklace add ip_src/mask ip_dsk/mask port_src:port_src =
port_dst:port_dst =0A=
ipnecklace disable=0A=
ipnecklace enable=0A=
ipnecklace list=0A=
*/=0A=
=0A=
#define exit_with_syntax \=0A=
{\=0A=
printf("syntax: ipnecklace add ip_src/mask ip_dst/mask =
port_src:port_src port_dst:port_dst\n");\=0A=
printf(" ipnecklace disable\n");\=0A=
printf(" ipnecklace enable\n"); \=0A=
printf(" ipnecklace list\n");\=0A=
ExitProcess(-1);\=0A=
}\=0A=
=0A=
const char* print_error()=0A=
{=0A=
char *error;=0A=
=0A=
=
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|F=
ORMAT_MESSAGE_IGNORE_INSERTS,=0A=
NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), =
(char*)&error, 0, NULL);=0A=
return error;=0A=
}=0A=
=0A=
void parse_ip(char *s, unsigned int *ip, unsigned int *mask)=0A=
{=0A=
char *tmp, *check;=0A=
unsigned int i;=0A=
unsigned int tmp2=3D0;=0A=
=0A=
if (!(tmp=3Dstrchr(s, '/')))=0A=
exit_with_syntax;=0A=
*tmp=3D0; tmp++;=0A=
=0A=
if ((*ip=3Dinet_addr(s)) =3D=3D INADDR_NONE)=0A=
exit_with_syntax;=0A=
=0A=
*mask=3Dstrtoul(tmp, &check, 10);=0A=
if (*check !=3D 0 || *mask > 32)=0A=
exit_with_syntax;=0A=
for(i=3D0; i<*mask; i++) =0A=
tmp2|=3D1<<i;=0A=
*mask=3Dtmp2;=0A=
}=0A=
=0A=
=0A=
void parse_range(char *s, unsigned int *start, unsigned int *stop)=0A=
{=0A=
char *tmp, *check;=0A=
=0A=
if (!(tmp=3Dstrchr(s, ':' )))=0A=
exit_with_syntax;=0A=
*tmp=3D0; tmp++;=0A=
=0A=
*start=3Dstrtoul(s, &check, 10);=0A=
if (*check !=3D 0 || *start > 0xffff)=0A=
exit_with_syntax;=0A=
=0A=
*stop=3Dstrtoul(tmp, &check, 10);=0A=
if (*check !=3D 0 || *stop > 0xffff)=0A=
exit_with_syntax;=0A=
=0A=
*start=3Dhtons(*start);=0A=
*stop=3Dhtons(*stop);=0A=
}=0A=
=0A=
int mask_len(int x)=0A=
{=0A=
int i;=0A=
=0A=
for(i=3D0; i<32; i++)=0A=
if (!(x&(1<<i)))=0A=
return i;=0A=
return i;=0A=
}=0A=
=0A=
=0A=
int main(int argc, char **argv)=0A=
{=0A=
fwr_t rule;=0A=
HANDLE fd;=0A=
int temp;=0A=
=0A=
if ((fd=3DCreateFile(FIREWALL_DEVICE, GENERIC_READ|GENERIC_WRITE, =
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, =
FILE_ATTRIBUTE_NORMAL, NULL)) =3D=3D INVALID_HANDLE_VALUE) {=0A=
printf("%s", print_error());=0A=
ExitProcess(-1);=0A=
}=0A=
=0A=
if (argc < 2) {=0A=
CloseHandle(fd);=0A=
exit_with_syntax;=0A=
}=0A=
=0A=
if (strcmp(argv[1], "add") =3D=3D 0) {=0A=
=0A=
parse_ip(argv[2], &rule.ip_src, &rule.ip_src_mask);=0A=
parse_ip(argv[3], &rule.ip_dst, &rule.ip_dst_mask);=0A=
parse_range(argv[4], &rule.port_src[0], &rule.port_src[1]);=0A=
parse_range(argv[5], &rule.port_dst[0], &rule.port_dst[1]);=0A=
=0A=
if (DeviceIoControl(fd, FW_ADD_RULE, &rule, sizeof(rule), NULL, 0, =
&temp, NULL) =3D=3D 0) {=0A=
printf("failed to add rule: %s", print_error());=0A=
CloseHandle(fd);=0A=
ExitProcess(-1);=0A=
}=0A=
=0A=
CloseHandle(fd);=0A=
return 0;=0A=
}=0A=
=0A=
if (strcmp(argv[1], "disable") =3D=3D 0) {=0A=
=0A=
if (DeviceIoControl(fd, FW_DISABLE, NULL, 0, NULL, 0, &temp, NULL) =
=3D=3D 0) {=0A=
printf("failed to disable firewall: %s", print_error());=0A=
CloseHandle(fd);=0A=
ExitProcess(-1);=0A=
}=0A=
=0A=
CloseHandle(fd);=0A=
return 0;=0A=
=0A=
}=0A=
=0A=
if (strcmp(argv[1], "enable") =3D=3D 0) {=0A=
=0A=
if (DeviceIoControl(fd, FW_ENABLE, NULL, 0, NULL, 0, &temp, NULL) =
=3D=3D 0) {=0A=
printf("failed to enable firewall: %s", print_error());=0A=
CloseHandle(fd);=0A=
ExitProcess(-1);=0A=
}=0A=
=0A=
CloseHandle(fd);=0A=
return 0;=0A=
}=0A=
=0A=
if (strcmp(argv[1], "list") =3D=3D 0) {=0A=
fwr_t *fwr=3DNULL;=0A=
int size, size2, i;=0A=
=0A=
if (!(fwr=3Dmalloc(sizeof(int)))) {=0A=
printf("out of memory\n");=0A=
CloseHandle(fd);=0A=
return -1;=0A=
}=0A=
size2=3Dsizeof(int);=0A=
=0A=
do {=0A=
size=3D0;=0A=
=0A=
if (DeviceIoControl(fd, FW_LIST, &size, sizeof(size), fwr, =
sizeof(int), &temp, NULL) =3D=3D 0) {=0A=
printf("failed to list rules: %s", print_error());=0A=
CloseHandle(fd);=0A=
ExitProcess(-1);=0A=
}=0A=
=0A=
size2=3D*((int*) fwr);=0A=
=0A=
if (!fwr)=0A=
free(fwr);=0A=
=0A=
if (!(fwr=3Dmalloc(size2*sizeof(*fwr)+sizeof(int)))) {=0A=
printf("out of memory\n");=0A=
CloseHandle(fd);=0A=
return -1;=0A=
}=0A=
=0A=
if (DeviceIoControl(fd, FW_LIST, &size2, sizeof(size2), fwr, =
size2*sizeof(fwr_t)+sizeof(int), &temp, NULL) =3D=3D 0) {=0A=
printf("failed to list rules: %s", print_error());=0A=
print_error();=0A=
CloseHandle(fd);=0A=
ExitProcess(-1);=0A=
}=0A=
=0A=
size=3D*((int*) fwr);=0A=
if (size <=3D size2)=0A=
break;=0A=
=0A=
} while (1);=0A=
=0A=
fwr=3D(fwr_t*)((char*) fwr + sizeof(int));=0A=
for(i=3D0; i<size; i++,fwr++) {=0A=
printf("%d.%d.%d.%d/%d %d.%d.%d.%d/%d %d:%d %d:%d\n",=0A=
((unsigned char*)&fwr->ip_src)[0], ((unsigned =
char*)&fwr->ip_src)[1], ((unsigned char*)&fwr->ip_src)[2],((unsigned =
char*)&fwr->ip_src)[3],=0A=
mask_len(fwr->ip_src_mask),=0A=
((unsigned char*)&fwr->ip_dst)[0], ((unsigned =
char*)&fwr->ip_dst)[1], ((unsigned char*)&fwr->ip_dst)[2],((unsigned =
char*)&fwr->ip_dst)[3],=0A=
mask_len(fwr->ip_dst_mask),=0A=
ntohs(fwr->port_src[0]), ntohs(fwr->port_src[1]),=0A=
ntohs(fwr->port_dst[0]), ntohs(fwr->port_dst[1]));=0A=
}=0A=
=0A=
CloseHandle(fd);=0A=
return size; =0A=
=0A=
}=0A=
=0A=
CloseHandle(fd);=0A=
exit_with_syntax;=0A=
=0A=
=0A=
return 0; =0A=
}=0A=
--Boundary-00=_ZVtxAt06buFyfyP--