4 bits | 4 bits | 1 octet | 2 octets | 4 octets | 1 octet | 1 octet | 2 octets | 4 octets | 4 octets |
Version | Longueur entêtes | Services et congestion | Longueur totale | Fragmentation | Durée vie | Protocole | Somme de contrôle | @ IPv4 source | @ IPv4 destination |
0x4 | 0x5 | 0x00 | - | 0x00000000 | 0x40 | - | - | - | - |
192.168.0.1 |
193.48.57.34 |
fe80::1 |
2001:660:4401:6002:215:c5ff:fef3:e3f |
192.168.0.0/255.255.255.0 |
193.48.57.0/26 |
#include <stdio.h> #include <stdint.h> int main(void){ uint32_t sum=0; uint8_t h,l; while(scanf("%hhx",&h)==1){ if(scanf("%hhx",&l)!=1) l=0; sum += ((uint16_t)h<<8)|l; } while(sum>>16) sum=(sum&0xffff)+(sum>>16); printf("%04x\n",(uint16_t)~sum); return 0; }