This commit is contained in:
Arnaud NGWALA NGWALA 2023-03-03 21:52:30 +01:00
parent fa1e48e9e0
commit 0241729e67
5 changed files with 81 additions and 0 deletions

34
SCR1.2/TP11/get_numb.c Normal file
View File

@ -0,0 +1,34 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
int main(int argc, char *argv[]){
if (argc != 3){
fprintf(stderr, "%c <file_name> <offset>", argv[0]);
exit(1);
}
off_t offset;
ssize_t nb_read;
int nb, n;
int fdin;
fdin = open(argv[1], O_RDONLY);
if (fdin == -1){
perror("File can't be opened");
exit(2);
}
offset = (off_t) strtol (argv[2], NULL, 0);
n = lseek(fdin, offset * sizeof(int), SEEK_SET);
if (!n){
perror("Offset is out of range!");
exit(3);
}
nb_read=read(fdin, &nb, sizeof(int));
if (nb_read < 0){
perror("File can't be read");
exit(4);
}
printf("The number at offset %s is %x --> %d\n", argv[2], nb, nb);
return EXIT_SUCCESS;
}

27
SCR1.2/TP11/put_nub.c Normal file
View File

@ -0,0 +1,27 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
int main(int argc, char *argv[]){
if (argc != 4){
fprintf(stderr, "%c <file_name> <32-bit in Hex> <Offset in Hex>", argv[0]);
exit(1);
}
off_t offset;
ssize_t nb_write;
int nb, n;
int fdin;
fdin = open(argv[1],O_WRONLY);
if (fdin == -1){
perror("File can't be opened");
exit(2);
}
offset = (off_t) strtol (argv[3], NULL, 16);
nb = (int) strtol(argv[2], NULL, 16);
n = lseek(fdin, offset * sizeof(int), SEEK_SET);
nb_write=write(fdin, &nb, sizeof(int));
printf("%x", nb);
return EXIT_SUCCESS;
}

0
SCR1.2/TP11/test.dat* Normal file
View File

Binary file not shown.

View File

@ -0,0 +1,20 @@
Question 1)
La commande ip addr permet d'afficher les interfaces réseau de notre machine
Question 2)
La commande ip addr show lo permet d'afficher l'interface réseau associée au loopback
Question 3)
La commande ip link show
Question 4)
ip link show eno1
Question 5)
ip neigh
Question 6)
ip neigh -r
Question 7)
ip route