[pso] eroare enunt tema 5: network byte order

Razvan Deaconescu razvan.deaconescu at cs.pub.ro
Mon Aug 18 15:17:23 EEST 2008


On Mon, 2008-08-18 at 14:31 +0300, foxX wrote:
> enunt: Valorile numerice sunt exprimate in network byte-order.

Da, valorile numerice asociate campurilor structurii struct fwr.

> checker: run: build
>        ./test inside $(OUTSIDE_IP) 55555
> 
> test.c:
> static int do_connect (int type, const char *hostname, unsigned short port)
> ...
>        /* fill the address */
>        name.sin_family = AF_INET;
>        name.sin_port = htons (port);
> 
> 
> pana la urma cum fac sa compar 2 porturi venite la ioctl?
> 
> ntohs(a) <=> ntohs(b) sau direct a <=> b ?

Campurile transmise din user-space in structura struct fwr sunt in
network byte order. Porturile se compara in host byte order pentru ca
asa le furnizeaza utilizatorul.

Daca te vei uita in ipnecklace.c in functia parse_range vei vedea ca se
face conversia in network byte order (folosind htons) inainte de ioctl.
Range-ul este dat de utilizator in host byte order in momentul invocarii
executabilul ipnecklace:
---
strcpy (add_rule, "./ipnecklace add 0.0.0.0/0 0.0.0.0/0 0:65535 22:22");
---

Razvan



More information about the pso mailing list