Below you will find pages that utilize the taxonomy term “C”
简单TFTP协议实现
简单实现了传输的功能,基本没有错误和异常处理……
服务器端
<br></br>#include <stdio.h><br></br>#include <stdlib.h><br></br>#include <string.h><br></br>#include <strings.h><br></br>#include <sys><br></br>#include <sys><br></br>#include <netdb.h><br></br>#include <fcntl.h></fcntl.h></netdb.h></sys></sys></strings.h></string.h></stdlib.h></stdio.h>
#define DEBUG 1
#define OPCODE_RRQ (1)
#define OPCODE_WRQ (2)
#define OPCODE_DATA (3)
#define OPCODE_ACK (4)
#define OPCODE_ERR (5)
#define BLOCKSIZE (512)
struct TFTPHeader{
short opcode;
}__attribute__((packed));
struct TFTPWRRQ{
struct TFTPHeader header;
char *filename; // Terminal as \0x00
char *mode; // Terminal as \0x00
}__attribute__((packed));
struct TFTPData{
struct TFTPHeader header;
short block;
void* data;
}__attribute__((packed));
struct TFTPACK{
struct TFTPHeader header;
short block;
}__attribute__((packed));
DNS客户端改进版
对[link2post id=”797″]上一个DNS客户端[/link2post]的简单改进。稍微封装了一下,同时修改了接收返回部分的代码,可以读到被GFW劫持域名的正确记录。
<br></br>#include <stdio.h><br></br>#include <stdlib.h><br></br>#include <string.h><br></br>#include <strings.h></strings.h></string.h></stdlib.h></stdio.h>
#include
#include
#include
#include <netdb.h>
#include <unistd.h></unistd.h></netdb.h>
#define DNSSERVER (“8.8.8.8”)
extern int errno;
struct DNSHeader{
short TranscationID;
short Flags;
short Questions;
short AnswerRRs;
short AuthorityRRs;
short AdditionalRRs;
}__attribute__((packed));
struct DNSQuery{
short Type;
short Class;
}__attribute__((packed));
struct DNSQueryFull{
char* domain;
short Type;
short Class;
}__attribute__((packed));
简单的C语言DNS客户端实现
写着玩儿的……
只能查询并解析A记录。
<br></br>#include <stdio.h><br></br>#include <stdlib.h><br></br>#include <string.h><br></br>#include <strings.h></strings.h></string.h></stdlib.h></stdio.h>
#include
#include
#include <netdb.h></netdb.h>
#define DNSSERVER (“8.8.8.8”)
extern int errno;
struct DNSHeader{
short TranscationID;
short Flags;
short Questions;
short AnswerRRs;
short AuthorityRRs;
short AdditionalRRs;
}__attribute__((packed));
struct DNSQuery{
short Type;
short Class;
}__attribute__((packed));
struct DNSAnswerRR{
short Name;
short Type;
short Class;
int TTL;
short Length;
int Address;
}__attribute__((packed));