Skip to content

Instantly share code, notes, and snippets.

View thongntit's full-sized avatar

Thong Nguyen thongntit

View GitHub Profile
@thongntit
thongntit / RawPacket.c
Last active March 12, 2019 19:18
Applet using raw socket to send and receive packet with ICMP protocal OUTPUT is packet in hexa format. Can print as %c to see data. IP header is 20bytes. ICMP header is 8bytes. The rest is data
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <inttypes.h>
#include <sys/socket.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
#include <arpa/inet.h>
@thongntit
thongntit / dataalignment.c
Created July 4, 2018 10:10
Data alignment - Padding Article khá hay và đầy đủ về data alignment và padding https://www.cppdeveloper.com/2018/01/28/data-alignment-trong-c-c/
/* For Windows */
__declspec(align(32)) struct s
{
char a;
int b;
};
/* For Unix-like */
alignas(32) struct s1
{
@thongntit
thongntit / gethostbyname.c
Created July 4, 2018 10:11
Gethostbyname Small app that prints of IP address of input domain name
#include <stdio.h>
#include <netdb.h>
#include <arpa/inet.h>
int main(int argc, char *argv[])
{
struct hostent *lh = gethostbyname(argv[1]);
if (lh){
printf("%s",inet_ntoa(*( struct in_addr*)lh->h_addr_list[0]));
@thongntit
thongntit / stringsplit.c
Created July 4, 2018 10:11
String Split Applet split string with character
//gcc 5.4.0
#include <stdio.h>
#include <string.h>
int main(void)
{
char str[50]="Hello, world!\n";
char *ptr;
ptr = strtok(str,",");
printf("%s",ptr);
@thongntit
thongntit / strtok.c
Created July 4, 2018 10:11
Read string with format Applet read string with format
//gcc 5.4.0
#include <stdio.h>
int main(void)
{
char str[100] = "MemFree: 3226700 kB";
char s1[50];
char s2[50];
sscanf(str,"%s%*[ ]%s",s1,s2);