28 Ocak 2018 Pazar

readelf komutu

-d seçeneği
dynamic section hakkında bilgi gösterir. Şöyle yaparız.
readelf -d a.out
NEEDED alanı
Eğer bir .so kütüphanesi bir başka .so kütüphanesine bağımlıysa elf dosyasında bu alan NEEDED olarak işaretlidir.  Şöyle yaparız.
$ readelf -d liba.so | grep NEEDED
 0x00000001 (NEEDED)                     Shared library: [libc.so.6]
-debug-dump seçeneği
debug section hakkında bilgi gösterir. Açıklaması şöyle.
The .debug_info section contains the actual debugging information. This section does not contain strings.
Şöyle yaparız.
readelf --debug-dump filename.o
Çıktı olarak şunu alırız.
    ...
Item 123:
    Type of information: Data type
    Name: 2b /* String #2b in ".debug_str" is "int" */
    Kind of data type: Signed integer
    Number of bits: 32
    ... some more information ...
Item 124:
    Type of information: Global variable
    Name: 8 /* "lvar" */
    Data type defined by: Item 123
    Stored at: Address 0x1234
    ... some more information ...
Begin item 125:
    Type of information: Function
    Name: 6 /* "main" */
    ... some more information ...
Item 126:
    Type of information: Local variable
    Name: 5 /* "svar" */
    Data type defined by: Item 123
    Stored at: Address 0x1238
    ... some more information ...
End item 125 /* Function "main" */
Item 127:
    ...
- h seçeneği
Header bilgisini gösterir. Şöyle yaparız.
readelf -h MyApp
Çıktı olarak şunu alırız.
ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              REL (Relocatable file)
  Machine:                           Intel 80386
  Version:                           0x1
  Entry point address:               0x0
  Start of program headers:          0 (bytes into file)
  Start of section headers:          2548 (bytes into file)
  Flags:                             0x0
  Size of this header:               52 (bytes)
  Size of program headers:           0 (bytes)
  Number of program headers:         0
  Size of section headers:           40 (bytes)
  Number of section headers:         16
  Section header string table index: 13
Class alanı 32/64 bit olduğunu gösterir. 64 bit uygulamanın çıktısı şöyledir.
ELF Header:
Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
Class:                             ELF64
Data:                              2's complement, little endian
Version:                           1 (current)
OS/ABI:                            UNIX - System V
ABI Version:                       0
Type:                              DYN (Shared object file)
Machine:                           Advanced Micro Devices X86-64
Version:                           0x1
Entry point address:               0x1158
Start of program headers:          64 (bytes into file)
Start of section headers:          308248 (bytes into file)
Flags:                             0x0
-S seçeneği
Section'lar hakkında bilgi gösterir. Şöyle yaparız.
$ readelf -S true
There are 30 section headers, starting at offset 0x7368:

Section Headers:
  [Nr] Name              Type             Address           Offset
       Size              EntSize          Flags  Link  Info  Align
  [ 0]                   NULL             0000000000000000  00000000
       0000000000000000  0000000000000000           0     0     0
  [ 1] .interp           PROGBITS         0000000000000238  00000238
       000000000000001c  0000000000000000   A       0     0     1
  [ 2] .note.ABI-tag     NOTE             0000000000000254  00000254
       0000000000000020  0000000000000000   A       0     0     4
  [ 3] .note.gnu.build-i NOTE             0000000000000274  00000274
       0000000000000024  0000000000000000   A       0     0     4
  ...
  [23] .dynamic          DYNAMIC          0000000000206dd8  00006dd8
       00000000000001e0  0000000000000010  WA       6     0     8
  [24] .got              PROGBITS         0000000000206fb8  00006fb8
       0000000000000030  0000000000000008  WA       0     0     8
  [25] .got.plt          PROGBITS         0000000000207000  00007000
       0000000000000188  0000000000000008  WA       0     0     8
  [26] .data             PROGBITS         00000000002071a0  000071a0
       0000000000000080  0000000000000000  WA       0     0     32
  [27] .bss              NOBITS           0000000000207220  00007220
       00000000000001a0  0000000000000000  WA       0     0     32
  [28] .gnu_debuglink    PROGBITS         0000000000000000  00007220
       0000000000000034  0000000000000000           0     0     1
  [29] .shstrtab         STRTAB           0000000000000000  00007254
       000000000000010f  0000000000000000           0     0     1


16 Ocak 2018 Salı

Windows ipconfig komutu

Giriş
Bu komut Windows'ta olmasına rağmen çok kullanıldığı için yazmak istedim.

all seçeneği
Windows'ta ipconfig /all ile hangi DHCP sunucusundan IP adresi aldığımız öğrenilebilir. Şöyle yaparız.
ipconfig /all > output.txt

flushdns seçeneği
Şöyle yaparız.
ipconfig /flushdns
release seçeneği
DHCP sunucusundan alına IP adresini bırakır. Şöyle yaparız.
ipconfig /release


14 Ocak 2018 Pazar

ethtool komutu

Giriş
ethtool ağ kartını kontrol etmek için kullanılıyor.

-k seçeneği
Tüm ayarların durumunu görmek için kullanılır.
ethtool -k eth0
-A pause parametrelerini değiştirir
Pause flowcontrol için kullanılır. Şöyle yaparız.
#pause on
ethtool -A eth0 tx on rx on

#auto-negotiation is on
ethtool -A eth0 autoneg on

#restart auto-negotiation
ethtool -r eth0
gso - generic segmentation offload ve generic receive offload
1500 byte'tan daha büyük paketlerin donanımda veya yazılımda bölünmesini kontrol eder. Bu seçenek genelde şöyledir.
generic-segmentation-offload: on
generic-receive-offload: on
Yazılımda bölme yapmak için şöyle yaparız.
ethtool -K eth0 gso off gro off
Şöyle yaparız.
ethtool -K <iface> gso off &&
ethtool -K <iface> tso off &&
ethtool -K <iface> gro off
Kod içinde GSO değerinin on/off olduğu şöyle kontrol edilir.
struct ethtool_value eval;

eval.cmd = ETHTOOL_GGSO;
ifr->ifr_data = (caddr_t)&eval;
err = ioctl(fd, SIOCETHTOOL, ifr);
if (err)
        perror("Cannot get device generic segmentation offload settings");
else {
        gso = eval.data;
        allfail = 0;
}
lro - large receive Offload
Örnek
Şöyle yaparız.
ethtool -K <interface_name> lro on
Örnek
Şöyle yaparız.
// Turn LRO off
ethtool -K eth2 lro off
echo -e “ethtool -K eth2 lro off” >> /etc/rc.local


// Check the result
cat /etc/rc.local
ethtool -k eth2 | grep large-receive-offload
tso - tcp segmentation offload

Örnek ver.

tx ve rx checksum
IP Checksum hesaplamasının donanımda veya yazılımda yapılmasını kontrol eder. Bu seçenek genelde şöyledir.
rx-checksumming: on
tx-checksumming: on
    tx-checksum-ipv4: off [fixed]
    tx-checksum-ip-generic: on
    tx-checksum-ipv6: off [fixed]
    tx-checksum-fcoe-crc: off [fixed]
    tx-checksum-sctp: off [fixed]
Yazılımda yapılması için şöyle yaparız.
$ ethtool --offload eth0 rx off tx off
-S seçeneği
statistics anlamına gelir. LRO sayacını görmek için şöyle yaparız.
ethtool -S <interface_name> | grep lro
-s seçeneği
change anlamına gelir. Şöyle yaparız.
# ethtool -s eth1 speed 1000 duplex full
Kodlama
Yukarıdak kod örneklerinin açıklaması şöyle. ethtool_value yapısı için şu satırı dahil ederiz.
include <linux/ethtool.h>
Bu yapının cmd ve data isimli iki alanı var. cmd alanına komutu yazarız. data alanı 1 = on 0=off değerini alır.

eval nesnesi ifreq nesnesinin ifr_data alanına atanır.
struct ifreq ifr;
struct ethtool_cmd edata;

strncpy(ifr.ifr_name, "eth0", sizeof(ifr.ifr_name));
ifr.ifr_data = &edata;
Bazı kodlarda şu şekilde cast görülebilir.
ifr.ifr_data = (caddr_t)&edata;



10 Ocak 2018 Çarşamba

Windows start komutu

Giriş
bat dosyasından başka uygulamayı çalıştırmak için start kullanılır.

/b seçeneği
Komutu arkaplanda (background) çalıştırır.  Şöyle yaparız
start /b "Window Title" "c:\Program Files\Wireshark\tshark.exe" -i 1 -w file1.pcap
/MIN seçeneği
Ekranı küçültmek için şöyle yaparız.
start /MIN java -jar my.jar

9 Ocak 2018 Salı

gunzip komutu

Giriş
gzip olarak sıkıştırılmış dosyayı açar.

gzip ve zip Farkı
gzip arşivinde sıkıştırılmış tek dosya vardır. zip dosyasınında ile birden fazla dosya vardır.

Örnek
gzip dosyalarının da ilk elemanını açabilir.Şöyle yaparız.
gunzip < file.zip | tail -n +3000 | head -n 20