This commit is contained in:
2025-09-04 11:23:03 +02:00
parent 00268af4fb
commit d57594fc06
24 changed files with 1045 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
$TTL 3600
@ IN SOA kheops.mos. root.mos. (
2007010401 ; Serial
3600 ; Refresh [1h]
600 ; Retry [10m]
86400 ; Expire [1d]
600 ) ; Negative Cache TTL [1h]
;
@ IN NS kheops.mos.
10.0.80.80.in-addr.arpa IN PTR kheops.mos.
20.0.80.80.in-addr.arpa IN PTR sethi.mos.
1.0.80.80.in-addr.arpa IN PTR host1.mos.
2.0.80.80.in-addr.arpa IN PTR host2.mos.
3.0.80.80.in-addr.arpa IN PTR host3.mos.
4.0.80.80.in-addr.arpa IN PTR host4.mos.
5.0.80.80.in-addr.arpa IN PTR host5.mos.

View File

@@ -0,0 +1,17 @@
$TTL 3600
@ IN SOA sethi.mos. root.mos. (
2007010401 ; Serial
3600 ; Refresh [1h]
600 ; Retry [10m]
86400 ; Expire [1d]
600 ) ; Negative Cache TTL [1h]
;
@ IN NS sethi.mos.
10.0.80.80.in-addr.arpa IN PTR kheops.mos.
20.0.80.80.in-addr.arpa IN PTR sethi.mos.
1.0.80.80.in-addr.arpa IN PTR host1.mos.
2.0.80.80.in-addr.arpa IN PTR host2.mos.
3.0.80.80.in-addr.arpa IN PTR host3.mos.
4.0.80.80.in-addr.arpa IN PTR host4.mos.
5.0.80.80.in-addr.arpa IN PTR host5.mos.

View File

@@ -0,0 +1,18 @@
$TTL 3600
@ IN SOA kheops.mos. root.mos. (
2007010401 ; Serial
3600 ; Refresh [1h]
600 ; Retry [10m]
86400 ; Expire [1d]
600 ) ; Negative Cache TTL [1h]
;
@ IN NS kheops.mos.
sethi IN A 80.80.0.20
kheops IN A 80.80.0.10
host1 IN A 80.80.0.1
host2 IN A 80.80.0.2
host3 IN A 80.80.0.3
host4 IN A 80.80.0.4
host5 IN A 80.80.0.5

View File

@@ -0,0 +1,18 @@
$TTL 3600
@ IN SOA sethi.mos. root.mos. (
2007010401 ; Serial
3600 ; Refresh [1h]
600 ; Retry [10m]
86400 ; Expire [1d]
600 ) ; Negative Cache TTL [1h]
;
@ IN NS sethi.mos.
sethi IN A 80.80.0.20
kheops IN A 80.80.0.10
host1 IN A 80.80.0.1
host2 IN A 80.80.0.2
host3 IN A 80.80.0.3
host4 IN A 80.80.0.4
host5 IN A 80.80.0.5

View File

@@ -0,0 +1,12 @@
zone "mos" {
type slave;
file "/etc/bind/db.mos";
master{80.80.80.20};
};
zone "80.80.in-addr.arpa" {
type slave;
file "/etc/bind/db.mos.inv";
master{80.80.80.20};
};

BIN
SCR2.2/TP24.tar Normal file

Binary file not shown.

84
SCR2.2/TP24/dhcpd.conf Normal file
View File

@@ -0,0 +1,84 @@
# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#
# option definitions common to all supported networks...
#option domain-name "example.org";
#option domain-name-servers ns1.example.org, ns2.example.org;
default-lease-time 600;
max-lease-time 7200;
# The ddns-updates-style parameter controls whether or not the server will
# attempt to do a DNS update when a lease is confirmed. We default to the
# behavior of the version 2 packages ('none', since DHCP v2 didn't
# have support for DDNS.)
#ddns-update-style none;
# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;
# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
#log-facility local7;
# No service will be given on this subnet, but declaring it helps the
# DHCP server to understand the network topology.
#subnet 10.152.187.0 netmask 255.255.255.0 {
#}
# This is a very basic subnet declaration.
#subnet 10.254.239.0 netmask 255.255.255.224 {
# range 10.254.239.10 10.254.239.20;
# option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org;
#}
# This declaration allows BOOTP clients to get dynamic addresses,
# which we don't really recommend.
#subnet 10.254.239.32 netmask 255.255.255.224 {
# range dynamic-bootp 10.254.239.40 10.254.239.60;
# option broadcast-address 10.254.239.31;
# option routers rtr-239-32-1.example.org;
#}
# A slightly different configuration for an internal subnet.
#subnet 10.5.5.0 netmask 255.255.255.224 {
# range 10.5.5.26 10.5.5.30;
# option domain-name-servers ns1.internal.example.org;
# option domain-name "internal.example.org";
# option routers 10.5.5.1;
# option broadcast-address 10.5.5.31;
# default-lease-time 600;
# max-lease-time 7200;
#}
# Hosts which require special configuration options can be listed in
# host statements. If no address is specified, the address will be
# allocated dynamically (if possible), but the host-specific information
# will still come from the host declaration.
#host passacaglia {
# hardware ethernet 0:0:c0:5d:bd:95;
# filename "vmunix.passacaglia";
# server-name "toccata.example.com";
#}
# Fixed IP addresses can also be specified for hosts. These addresses
# should not also be listed as being available for dynamic assignment.
# Hosts for which fixed IP addresses have been specified can boot using
# BOOTP or DHCP. Hosts for which no fixed address is specified can only
# be booted with DHCP, unless there is an address range on the subnet
# to which a BOOTP client is connected which has the dynamic-bootp flag
# set.
#host fantasia {
# hardware ethernet 08:00:07:26:c0:a5;
option RFC-3442-classless-static-routes code 121=array of unsigned integer 8;
subnet 192.168.0.0 netmask 255.255.240.0 {
range 192.168.10.20 192.168.10.40;
option RFC-3442-classless-static-routes 172,16,2,192,168,10,254,0,192,168,10,253;
}

84
SCR2.2/TP24/dhcpd.conf~ Normal file
View File

@@ -0,0 +1,84 @@
# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#
# option definitions common to all supported networks...
#option domain-name "example.org";
#option domain-name-servers ns1.example.org, ns2.example.org;
default-lease-time 600;
max-lease-time 7200;
# The ddns-updates-style parameter controls whether or not the server will
# attempt to do a DNS update when a lease is confirmed. We default to the
# behavior of the version 2 packages ('none', since DHCP v2 didn't
# have support for DDNS.)
#ddns-update-style none;
# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;
# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
#log-facility local7;
# No service will be given on this subnet, but declaring it helps the
# DHCP server to understand the network topology.
#subnet 10.152.187.0 netmask 255.255.255.0 {
#}
# This is a very basic subnet declaration.
#subnet 10.254.239.0 netmask 255.255.255.224 {
# range 10.254.239.10 10.254.239.20;
# option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org;
#}
# This declaration allows BOOTP clients to get dynamic addresses,
# which we don't really recommend.
#subnet 10.254.239.32 netmask 255.255.255.224 {
# range dynamic-bootp 10.254.239.40 10.254.239.60;
# option broadcast-address 10.254.239.31;
# option routers rtr-239-32-1.example.org;
#}
# A slightly different configuration for an internal subnet.
#subnet 10.5.5.0 netmask 255.255.255.224 {
# range 10.5.5.26 10.5.5.30;
# option domain-name-servers ns1.internal.example.org;
# option domain-name "internal.example.org";
# option routers 10.5.5.1;
# option broadcast-address 10.5.5.31;
# default-lease-time 600;
# max-lease-time 7200;
#}
# Hosts which require special configuration options can be listed in
# host statements. If no address is specified, the address will be
# allocated dynamically (if possible), but the host-specific information
# will still come from the host declaration.
#host passacaglia {
# hardware ethernet 0:0:c0:5d:bd:95;
# filename "vmunix.passacaglia";
# server-name "toccata.example.com";
#}
# Fixed IP addresses can also be specified for hosts. These addresses
# should not also be listed as being available for dynamic assignment.
# Hosts for which fixed IP addresses have been specified can boot using
# BOOTP or DHCP. Hosts for which no fixed address is specified can only
# be booted with DHCP, unless there is an address range on the subnet
# to which a BOOTP client is connected which has the dynamic-bootp flag
# set.
#host fantasia {
# hardware ethernet 08:00:07:26:c0:a5;
subnet 192.168.0.0 netmask 255.255.240.0 {
range 192.168.10.20 192.168.10.40
option RFC-3442-classless-static-routes 172,16,2,192,168,10,254,0,192,168,10,253;
}
option RFC-3442-classless-static-routes code 121=array of unsigned interger = 8;

294
SCR2.2/TP24/dhcpv4-serv.imn Normal file
View File

@@ -0,0 +1,294 @@
node n0 {
type host
network-config {
hostname DHCPsrv
!
interface eth0
mac address 42:00:aa:00:00:03
ip address 192.168.10.10/20
!
interface lo0
type lo
ip address 127.0.0.1/8
ipv6 address ::1/128
!
!
}
canvas c0
iconcoords {144 168}
labelcoords {130 130}
interface-peer {eth0 n6}
}
node n1 {
type host
network-config {
hostname GW1
!
interface eth1
mac address 42:00:aa:00:00:06
ip address 172.16.2.254/24
!
interface eth0
mac address 42:00:aa:00:00:02
ip address 192.168.10.254/20
!
interface lo0
type lo
ip address 127.0.0.1/8
ipv6 address ::1/128
!
}
canvas c0
iconcoords {432 264}
labelcoords {427 222}
interface-peer {eth0 n6}
interface-peer {eth1 n7}
custom-configs {
custom-config-id default {
custom-command /bin/sh
config {
i
}
}
}
custom-selected default
}
node n2 {
type pc
network-config {
hostname pc1-1
!
interface eth0
mac address 42:00:aa:00:00:00
!
interface lo0
type lo
ip address 127.0.0.1/8
ipv6 address ::1/128
!
}
canvas c0
iconcoords {96 480}
labelcoords {96 511}
interface-peer {eth0 n6}
}
node n3 {
type pc
network-config {
hostname pc1-2
!
interface eth0
mac address 42:00:aa:00:00:01
!
interface lo0
type lo
ip address 127.0.0.1/8
ipv6 address ::1/128
!
}
canvas c0
iconcoords {288 480}
labelcoords {288 511}
interface-peer {eth0 n6}
}
node n4 {
type pc
network-config {
hostname pc2-1
!
interface eth0
mac address 42:00:aa:00:00:04
ip address 172.16.2.1/24
!
interface lo0
type lo
ip address 127.0.0.1/8
ipv6 address ::1/128
!
}
canvas c0
iconcoords {576 504}
labelcoords {576 535}
interface-peer {eth0 n7}
}
node n5 {
type pc
network-config {
hostname pc2-2
!
interface eth0
mac address 42:00:aa:00:00:05
ip address 172.16.2.2/24
!
interface lo0
type lo
ip address 127.0.0.1/8
ipv6 address ::1/128
!
}
canvas c0
iconcoords {792 504}
labelcoords {792 535}
interface-peer {eth0 n7}
}
node n6 {
type lanswitch
network-config {
hostname switch1
!
}
canvas c0
iconcoords {192 336}
labelcoords {136 318}
interface-peer {e0 n2}
interface-peer {e1 n3}
interface-peer {e2 n1}
interface-peer {e3 n0}
interface-peer {e4 n8}
}
node n7 {
type lanswitch
network-config {
hostname switch2
!
}
canvas c0
iconcoords {648 312}
labelcoords {704 287}
interface-peer {e0 n4}
interface-peer {e1 n5}
interface-peer {e2 n1}
}
node n8 {
type host
network-config {
hostname GW2
!
interface eth1
mac address 42:00:aa:00:00:09
ip address 163.63.63.253/22
!
interface eth0
mac address 42:00:aa:00:00:07
ip address 192.168.10.253/20
!
interface lo0
type lo
ip address 127.0.0.1/8
ipv6 address ::1/128
!
!
!
}
canvas c0
iconcoords {432 96}
labelcoords {387 68}
interface-peer {eth0 n6}
interface-peer {eth1 n9}
}
node n9 {
type router
model quagga
network-config {
hostname router1
!
interface eth0
mac address 42:00:aa:00:00:08
ip address 163.63.63.254/22
!
interface lo0
type lo
ip address 127.0.0.1/8
ipv6 address ::1/128
!
router rip
redistribute static
redistribute connected
redistribute ospf
network 0.0.0.0/0
!
router ripng
redistribute static
redistribute connected
redistribute ospf6
network ::/0
!
}
canvas c0
iconcoords {744 168}
labelcoords {744 193}
interface-peer {eth0 n8}
}
link l0 {
nodes {n2 n6}
bandwidth 0
}
link l1 {
nodes {n3 n6}
bandwidth 0
}
link l2 {
nodes {n1 n6}
bandwidth 0
}
link l3 {
nodes {n0 n6}
bandwidth 0
}
link l4 {
nodes {n7 n4}
bandwidth 0
}
link l5 {
nodes {n5 n7}
bandwidth 0
}
link l6 {
nodes {n7 n1}
bandwidth 0
}
link l7 {
nodes {n8 n6}
bandwidth 0
}
link l8 {
nodes {n9 n8}
bandwidth 0
}
canvas c0 {
name {Canvas0}
}
option show {
interface_names yes
ip_addresses yes
ipv6_addresses yes
node_labels yes
link_labels yes
background_images no
annotations yes
hostsAutoAssign no
grid yes
iconSize normal
zoom 1.0
}

View File

@@ -0,0 +1,138 @@
I.
1)
apt list --installed "*dhcp*"
isc-dhcp-client/oldoldstable,now 4.3.5-3+deb9u1 amd64 [installed]
isc-dhcp-common/oldoldstable,now 4.3.5-3+deb9u1 amd64 [installed,automatic]
isc-dhcp-relay/oldoldstable,now 4.3.5-3+deb9u1 amd64 [installed]
isc-dhcp-server/oldoldstable,now 4.3.5-3+deb9u1 amd64 [installed]
udhcpd/oldoldstable,now 1:1.22.0-19+b3 amd64 [installed]
2)
ls /etc/init.d/
Le service sera isc-dhcp-server
3)
less /etc/init.d/isc-dhcp-server
Sur la ligne start daemon on a -exec /usr/sbin/dhcpd
Grace a la commande which dhcpd on a une confirmation.
4)
man dhcpd
On constate que le fichier est dhcpd.conf se trouvant dans /etc/dhcp/
III.
1)
Je sais que CIDR signifie Classless Inter-Domain Routing.
Je vais sur le site donné pour connaitre le code (Tag) et le RFC (Reference).
Ctrl + F puis j'écrit Classless.
J'obtiens les ligne suivant:
Tag Name Data Length Meaning Reference
121 Classless Static Route Option N Classless Static Route Option [RFC3442]
Je peux donc répondre à la question en disant que le code est 121 et le RFC3442.
2)
Je vais sur le 2ème site puis je vais dans DEFINING NWE OPTIONS à droite.
Je constate que la commande doit ressemblé à quelque chose comme au minimum a option new-name code new-code ;
Je décide donc ce faire:
option RFC3442_Classless_Inter-Domain_Routing code 121=arrays interger 8;
A notifier que :
Le nom peut être un autre, mais que j'ai mis la RFC3442 pour plus d'information et le Classless Inter-Domain Routing car on cherche l'option pour communiquer aux clients une route CIDR.
Le code j'ai mis le même donc le numéro 121.
Puis interger 8 afin de donner des information sur le nombre de bits qui sera utilisé à ne pas oublié qu'il y a plusieurs 8 , 16 , 32 tout dépend du besoin.
IV.
Exemple:
Code Len Destination 1 Router 1
+-----+---+----+-----+----+----+----+----+----+
| 121 | n | d1 | ... | dN | r1 | r2 | r3 | r4 |
+-----+---+----+-----+----+----+----+----+----+
Destination 2 Router 2
+----+-----+----+----+----+----+----+
| d1 | ... | dN | r1 | r2 | r3 | r4 |
+----+-----+----+----+----+----+----+
code lenght d1 d2 d3 d4| Router1 | d1
121 13 24 172 16 2 192 168 10 254 0 192 168 10 253
1)
Regardez dhcpd.conf
2)
Commande pour tester dhcpd -t
3)
Dans /etc/default/isc-dhcp-server,
On commente INTERFACESv6=""
On rajoute eth0 pour avoir INTERFACESv4="eth0"
V.
1)
On lance avec la commande /etc/init.d/isc-dhcp-server start
udp UNCONN 0 0 *:67 *:*
udp UNCONN 0 0 *:bootps *:*
2)
ps -a
92 ? 00:00:00 dhcp
Le PID est 92
Aussi visible dans le man dhcpd qui dit qu'il est aussi disponible dans /var/run/dhcpd.pid
3)
ps -eo pid,command
root@DHCPsrv:~# ps -eo pid,command
PID COMMAND
1 /sbin/docker-init -- /bin/bash
7 /bin/bash
35 rpcbind
37 inetd
64 /bin/bash
92 /usr/sbin/dhcpd -4 -q -cf /etc/dhcp/dhcpd.conf eth0
181 ps -eo pid,command
4)
PC1-1
ip r
Rien
Puis dhclient eth0
ip r
192.168.0.0/20 dev eth0 proto kernel scope link src 192.168.10.20
dhclient -v
eth0Internet Systems Consortium DHCP Client 4.3.5
Copyright 2004-2016 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Listening on LPF/eth0/42:00:aa:00:00:00
Sending on LPF/eth0/42:00:aa:00:00:00
Sending on Socket/fallback
DHCPREQUEST of 192.168.10.20 on eth0 to 255.255.255.255 port 67
DHCPACK of 192.168.10.20 from 192.168.10.10
RTNETLINK answers: File exists
bound to 192.168.10.20 -- renewal in 204 seconds.
5.
6.
7.
8.
pc1-1# ping -c1 172.16.2.1
connect: Network is unreachable

View File

@@ -0,0 +1,138 @@
I.
1)
apt list --installed "*dhcp*"
isc-dhcp-client/oldoldstable,now 4.3.5-3+deb9u1 amd64 [installed]
isc-dhcp-common/oldoldstable,now 4.3.5-3+deb9u1 amd64 [installed,automatic]
isc-dhcp-relay/oldoldstable,now 4.3.5-3+deb9u1 amd64 [installed]
isc-dhcp-server/oldoldstable,now 4.3.5-3+deb9u1 amd64 [installed]
udhcpd/oldoldstable,now 1:1.22.0-19+b3 amd64 [installed]
2)
ls /etc/init.d/
Le service sera isc-dhcp-server
3)
less /etc/init.d/isc-dhcp-server
Sur la ligne start daemon on a -exec /usr/sbin/dhcpd
Grace a la commande which dhcpd on a une confirmation.
4)
man dhcpd
On constate que le fichier est dhcpd.conf se trouvant dans /etc/dhcp/
III.
1)
Je sais que CIDR signifie Classless Inter-Domain Routing.
Je vais sur le site donné pour connaitre le code (Tag) et le RFC (Reference).
Ctrl + F puis j'écrit Classless.
J'obtiens les ligne suivant:
Tag Name Data Length Meaning Reference
121 Classless Static Route Option N Classless Static Route Option [RFC3442]
Je peux donc répondre à la question en disant que le code est 121 et le RFC3442.
2)
Je vais sur le 2ème site puis je vais dans DEFINING NWE OPTIONS à droite.
Je constate que la commande doit ressemblé à quelque chose comme au minimum a option new-name code new-code ;
Je décide donc ce faire:
option RFC3442_Classless_Inter-Domain_Routing code 121=arrays interger 8;
A notifier que :
Le nom peut être un autre, mais que j'ai mis la RFC3442 pour plus d'information et le Classless Inter-Domain Routing car on cherche l'option pour communiquer aux clients une route CIDR.
Le code j'ai mis le même donc le numéro 121.
Puis interger 8 afin de donner des information sur le nombre de bits qui sera utilisé à ne pas oublié qu'il y a plusieurs 8 , 16 , 32 tout dépend du besoin.
IV.
Exemple:
Code Len Destination 1 Router 1
+-----+---+----+-----+----+----+----+----+----+
| 121 | n | d1 | ... | dN | r1 | r2 | r3 | r4 |
+-----+---+----+-----+----+----+----+----+----+
Destination 2 Router 2
+----+-----+----+----+----+----+----+
| d1 | ... | dN | r1 | r2 | r3 | r4 |
+----+-----+----+----+----+----+----+
code lenght d1 d2 d3 d4| Router1 | d1
121 13 24 172 16 2 192 168 10 254 0 192 168 10 253
1)
Regardez dhcpd.conf
2)
Commande pour tester dhcpd -t
3)
Dans /etc/default/isc-dhcp-server,
On commente INTERFACESv6=""
On rajoute eth0 pour avoir INTERFACESv4="eth0"
V.
1)
On lance avec la commande /etc/init.d/isc-dhcp-server start
udp UNCONN 0 0 *:67 *:*
udp UNCONN 0 0 *:bootps *:*
2)
ps -a
92 ? 00:00:00 dhcp
Le PID est 92
Aussi visible dans le man dhcpd qui dit qu'il est aussi disponible dans /var/run/dhcpd.pid
3)
ps -eo pid,command
root@DHCPsrv:~# ps -eo pid,command
PID COMMAND
1 /sbin/docker-init -- /bin/bash
7 /bin/bash
35 rpcbind
37 inetd
64 /bin/bash
92 /usr/sbin/dhcpd -4 -q -cf /etc/dhcp/dhcpd.conf eth0
181 ps -eo pid,command
4)
PC1-1
ip r
Rien
Puis dhclient eth0
ip r
192.168.0.0/20 dev eth0 proto kernel scope link src 192.168.10.20
dhclient -v
eth0Internet Systems Consortium DHCP Client 4.3.5
Copyright 2004-2016 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Listening on LPF/eth0/42:00:aa:00:00:00
Sending on LPF/eth0/42:00:aa:00:00:00
Sending on Socket/fallback
DHCPREQUEST of 192.168.10.20 on eth0 to 255.255.255.255 port 67
DHCPACK of 192.168.10.20 from 192.168.10.10
RTNETLINK answers: File exists
bound to 192.168.10.20 -- renewal in 204 seconds.
5.
6.
7.
8.
pc1-1# ping -c1 172.16.2.1
connect: Network is unreachable

Binary file not shown.

BIN
SCR3.1/TP1/Ex1/a.out Executable file

Binary file not shown.

View File

@@ -0,0 +1,27 @@
/* adresses virtuelles d'un processus */
#include<stdio.h>
#include<sys/types.h>
#include <sys/time.h>
#include<unistd.h>
#include<stdlib.h>
int t[1000] = {[0 ... 999] = 2};
int main(int argc, char * argv[])
{
int i=3;
static int j = 3;
char * m = (char*)malloc(1);
printf("je suis le pid %d\n\n",getpid());
/* ------- Affichage des adresses --------*/
printf("main\t\t=\t%p\n",main);
printf("gettimeofday\t=\t%p\n",gettimeofday);
printf("&argc\t\t=\t%p\n",&argc);
printf("&i\t\t=\t%p\n",&i);
printf("&j\t\t=\t%p\n",&j);
printf("t\t\t=\t%p\n",t);
printf("m\t\t=\t%p\n",m);
getchar();
}

17
SCR3.1/TP1/Ex2/Makefile Normal file
View File

@@ -0,0 +1,17 @@
CFLAGS := -Wall -g -O0
SRC=buf.c heap.c huge.c mmap.c null.c stack.c
DEPENDHELPERS=helpers.o
BINARIES=$(SRC:%.c=%)
%.o : %c
gcc -c $+
$(BINARIES): % : %.o $(DEPENDHELPERS)
gcc -o $@ $+
all : $(BINARIES)
clean:
rm -f *.o $(BINARIES)

9
SCR3.1/TP1/Ex2/buf.c Normal file
View File

@@ -0,0 +1,9 @@
#include "helpers.h"
static char buffer[16 MB] = {0};
int main(int argc, char **argv)
{
randomize(buffer, 16 MB);
return interlude();
}

8
SCR3.1/TP1/Ex2/heap.c Normal file
View File

@@ -0,0 +1,8 @@
#include "helpers.h"
int main(int argc, char **argv)
{
dirty(16 MB);
clean(32 MB);
return interlude();
}

36
SCR3.1/TP1/Ex2/helpers.c Normal file
View File

@@ -0,0 +1,36 @@
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "helpers.h"
#include <stdlib.h>
void randomize(char *buf, size_t n)
{
assert(buf);
memset(buf, rand() & 0xff, n);
}
void clean(size_t b)
{
for (; b > 0; b -= 1 KB)
calloc(1 KB, sizeof(char));
}
void dirty(size_t b)
{
for (; b > 0; b -= 1 KB)
randomize(calloc(1 KB, sizeof(char)), 1 KB);
}
int interlude(void)
{
pid_t pid = getpid();
printf("pid %i\n", (int)pid);
printf("------------------------------------------\n"
"go check /proc/%i/smaps; I'll wait...\n"
"press <Enter> when you're done\n", pid);
fgetc(stdin);
return 0;
}

13
SCR3.1/TP1/Ex2/helpers.h Normal file
View File

@@ -0,0 +1,13 @@
#ifndef _HELPERS_H
#define _HELPERS_H
#include <stdlib.h>
#define KB * 1024
#define MB * 1024 * 1024
void randomize(char *buf, size_t n);
void clean(size_t n);
void dirty(size_t n);
int interlude(void);
#endif

12
SCR3.1/TP1/Ex2/huge.c Normal file
View File

@@ -0,0 +1,12 @@
#include "helpers.h"
int main(int argc, char **argv)
{
char *under = malloc(96 KB);
randomize(under, 96 KB);
char *over = malloc(256 KB);
randomize(over, 256 KB);
return interlude();
}

38
SCR3.1/TP1/Ex2/mmap.c Normal file
View File

@@ -0,0 +1,38 @@
#include "helpers.h"
#include <sys/mman.h>
#include <assert.h>
#include <fcntl.h>
int main(int argc, char **argv)
{
/* inert map (never modified) */
char *inert = mmap(NULL, 16 KB,
PROT_READ|PROT_WRITE,
MAP_ANONYMOUS|MAP_PRIVATE,
-1, 0);
/* anonymous, private mmap */
char *anon_priv = mmap(NULL, 32 KB,
PROT_READ|PROT_WRITE,
MAP_ANONYMOUS|MAP_PRIVATE,
-1, 0);
randomize(anon_priv, 32 KB);
/* anonymous, shared map */
char *anon_shared = mmap(NULL, 64 KB,
PROT_READ|PROT_WRITE,
MAP_ANONYMOUS|MAP_SHARED,
-1, 0);
randomize(anon_shared, 64 KB);
/* private, file-backed map */
int fd = open("data/256k", O_RDWR);
assert(fd >= 0);
char *file = mmap(NULL, 256 KB,
PROT_READ|PROT_WRITE,
MAP_PRIVATE,
fd, 0);
randomize(file, 128 KB);
return interlude();
}

6
SCR3.1/TP1/Ex2/null.c Normal file
View File

@@ -0,0 +1,6 @@
#include "helpers.h"
int main(int argc, char **argv)
{
return interlude();
}

8
SCR3.1/TP1/Ex2/stack.c Normal file
View File

@@ -0,0 +1,8 @@
#include "helpers.h"
int main (int argc, char **argv)
{
char buf[28 KB] = {0};
randomize(buf, 28 KB);
return interlude();
}

51
SCR3.1/TP1/Reponses Normal file
View File

@@ -0,0 +1,51 @@
Après avoir fait ./a.out :
je suis le pid 2911
main = 0x55da4ede0179
gettimeofday = 0x7fc917925870
&argc = 0x7ffd1e269f5c
&i = 0x7ffd1e269f6c
&j = 0x55da4ede4000
t = 0x55da4ede3060
m = 0x55da8162c310
[solar@salle225-11 Ex1]$ cat /proc/2911/maps
55da4eddf000-55da4ede0000 r--p 00000000 00:3e 80832245 /export/home/an23/solar/SCR/SCR3.1/TP1/Ex1/a.out
55da4ede0000-55da4ede1000 r-xp 00001000 00:3e 80832245 /export/home/an23/solar/SCR/SCR3.1/TP1/Ex1/a.out
55da4ede1000-55da4ede2000 r--p 00002000 00:3e 80832245 /export/home/an23/solar/SCR/SCR3.1/TP1/Ex1/a.out
55da4ede2000-55da4ede3000 r--p 00002000 00:3e 80832245 /export/home/an23/solar/SCR/SCR3.1/TP1/Ex1/a.out
55da4ede3000-55da4ede5000 rw-p 00003000 00:3e 80832245 /export/home/an23/solar/SCR/SCR3.1/TP1/Ex1/a.out
55da8162c000-55da8164d000 rw-p 00000000 00:00 0 [heap]
7fc917600000-7fc917624000 r--p 00000000 103:05 6028 /usr/lib/libc.so.6
7fc917624000-7fc917796000 r-xp 00024000 103:05 6028 /usr/lib/libc.so.6
7fc917796000-7fc917805000 r--p 00196000 103:05 6028 /usr/lib/libc.so.6
7fc917805000-7fc917809000 r--p 00204000 103:05 6028 /usr/lib/libc.so.6
7fc917809000-7fc91780b000 rw-p 00208000 103:05 6028 /usr/lib/libc.so.6
7fc91780b000-7fc917813000 rw-p 00000000 00:00 0
7fc9178ee000-7fc9178f3000 rw-p 00000000 00:00 0
7fc91791f000-7fc917923000 r--p 00000000 00:00 0 [vvar]
7fc917923000-7fc917925000 r--p 00000000 00:00 0 [vvar_vclock]
7fc917925000-7fc917927000 r-xp 00000000 00:00 0 [vdso]
7fc917927000-7fc917928000 r--p 00000000 103:05 6019 /usr/lib/ld-linux-x86-64.so.2
7fc917928000-7fc917952000 r-xp 00001000 103:05 6019 /usr/lib/ld-linux-x86-64.so.2
7fc917952000-7fc917960000 r--p 0002b000 103:05 6019 /usr/lib/ld-linux-x86-64.so.2
7fc917960000-7fc917962000 r--p 00039000 103:05 6019 /usr/lib/ld-linux-x86-64.so.2
7fc917962000-7fc917963000 rw-p 0003b000 103:05 6019 /usr/lib/ld-linux-x86-64.so.2
7fc917963000-7fc917964000 rw-p 00000000 00:00 0
7ffd1e24a000-7ffd1e26b000 rw-p 00000000 00:00 0 [stack]
ffffffffff600000-ffffffffff601000 --xp 00000000 00:00 0 [vsyscall]
le main est dans 55da4ede0000-55da4ede1000 r-xp 00001000 00:3e 80832245 /export/home/an23/solar/SCR/SCR3.1/TP1/Ex1/a.out
gettimeofday dans 7fc917925000-7fc917927000 r-xp 00000000 00:00 0 [vdso]
&argc et &i dans 7ffd1e24a000-7ffd1e26b000 rw-p 00000000 00:00 0 [stack]
&j et t sont sur la même plage ils 55da4ede la seul différence est que &j est 4000 la ou le t est pour 3060 mais ils sont tous les 2 sur la même ligne : 55da4ede3000-55da4ede5000 rw-p 00003000 00:3e 80832245 /export/home/an23/solar/SCR/SCR3.1/TP1/Ex1/a.out
m dans 55da8162c000-55da8164d000 rw-p 00000000 00:00 0 [heap]