當前位置:首頁 » 操作系統 » gethostbyname源碼

gethostbyname源碼

發布時間: 2022-03-02 10:51:00

⑴ gethostbyname()的源碼

struct hostent* gethostbyname(const char *name)
{
err_t err;
ip_addr_t addr;
/* buffer variables for lwip_gethostbyname() */
HOSTENT_STORAGE struct hostent s_hostent;
HOSTENT_STORAGE char *s_aliases;
HOSTENT_STORAGE ip_addr_t s_hostent_addr;
HOSTENT_STORAGE ip_addr_t *s_phostent_addr[2];
/* query host IP address */
err = netconn_gethostbyname(name, &addr);
if (err != ERR_OK) {
LWIP_DEBUGF(DNS_DEBUG, (lwip_gethostbyname(%s) failed, err=%d , name, err));
h_errno = HOST_NOT_FOUND;
return NULL;
}

⑵ delphi2010下 gethostbyname的返回值始終是空,怎麼解決

delphi 2010中的string默認是widestring,直接使用PAnsiChar轉換會有問題的,你可以把url定義為AnsiString而不是string。

⑶ 高分求200行的c程序源代碼!!

經典c程序100例==61--70

【程序61】
題目:列印出楊輝三角形(要求列印出10行如下圖)
1.程序分析:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
2.程序源代碼:
main()
{int i,j;
int a[10][10];
printf("\n");
for(i=0;i<10;i++)
{a[i][0]=1;
a[i][i]=1;}
for(i=2;i<10;i++)
for(j=1;j a[i][j]=a[i-1][j-1]+a[i-1][j];
for(i=0;i<10;i++)
{for(j=0;j<=i;j++)
printf("%5d",a[i][j]);
printf("\n");
}
}
==============================================================
【程序62】
題目:學習putpixel畫點。
1.程序分析:
2.程序源代碼:
#include "stdio.h"
#include "graphics.h"
main()
{
int i,j,driver=VGA,mode=VGAHI;
initgraph(&driver,&mode,"");
setbkcolor(YELLOW);
for(i=50;i<=230;i+=20)
for(j=50;j<=230;j++)
putpixel(i,j,1);
for(j=50;j<=230;j+=20)
for(i=50;i<=230;i++)
putpixel(i,j,1);
}
==============================================================
【程序63】
題目:畫橢圓ellipse
1.程序分析:
2.程序源代碼:
#include "stdio.h"
#include "graphics.h"
#include "conio.h"
main()
{
int x=360,y=160,driver=VGA,mode=VGAHI;
int num=20,i;
int top,bottom;
initgraph(&driver,&mode,"");
top=y-30;
bottom=y-30;
for(i=0;i {
ellipse(250,250,0,360,top,bottom);
top-=5;
bottom+=5;
}
getch();
}
==============================================================
【程序64】
題目:利用ellipse and rectangle 畫圖。
1.程序分析:
2.程序源代碼:
#include "stdio.h"
#include "graphics.h"
#include "conio.h"
main()
{
int driver=VGA,mode=VGAHI;
int i,num=15,top=50;
int left=20,right=50;
initgraph(&driver,&mode,"");
for(i=0;i {
ellipse(250,250,0,360,right,left);
ellipse(250,250,0,360,20,top);
rectangle(20-2*i,20-2*i,10*(i+2),10*(i+2));
right+=5;
left+=5;
top+=10;
}
getch();
}
==============================================================
【程序65】
題目:一個最優美的圖案。
1.程序分析:
2.程序源代碼:
#include "graphics.h"
#include "math.h"
#include "dos.h"
#include "conio.h"
#include "stdlib.h"
#include "stdio.h"
#include "stdarg.h"
#define MAXPTS 15
#define PI 3.1415926
struct PTS {
int x,y;
};
double AspectRatio=0.85;
void LineToDemo(void)
{
struct viewporttype vp;
struct PTS points[MAXPTS];
int i, j, h, w, xcenter, ycenter;
int radius, angle, step;
double rads;
printf(" MoveTo / LineTo Demonstration" );
getviewsettings( &vp );
h = vp.bottom - vp.top;
w = vp.right - vp.left;
xcenter = w / 2; /* Determine the center of circle */
ycenter = h / 2;
radius = (h - 30) / (AspectRatio * 2);
step = 360 / MAXPTS; /* Determine # of increments */
angle = 0; /* Begin at zero degrees */
for( i=0 ; i rads = (double)angle * PI / 180.0; /* Convert angle to radians */
points[i].x = xcenter + (int)( cos(rads) * radius );
points[i].y = ycenter - (int)( sin(rads) * radius * AspectRatio );
angle += step; /* Move to next increment */
}
circle( xcenter, ycenter, radius ); /* Draw bounding circle */
for( i=0 ; i for( j=i ; j moveto(points[i].x, points[i].y); /* Move to beginning of cord */
lineto(points[j].x, points[j].y); /* Draw the cord */
} } }
main()
{int driver,mode;
driver=CGA;mode=CGAC0;
initgraph(&driver,&mode,"");
setcolor(3);
setbkcolor(GREEN);
LineToDemo();}

c語言/C++,用recv獲取網頁源代碼,中文為什麼是亂碼 代碼如下:

這種問題通常是你的代碼在處理字元串是弄錯了。。。
接收過來的內容應該沒問題吧。。。。
只是顯示的時候弄錯了吧。。
仔細檢查一下,中文字元佔2個位元組,指針頭別弄錯了,最後加上'\0'別加錯位置。。。
如果英文字元都不可以正確顯示的話,那可能是粘包。
還有是不是編碼問題。

⑸ 代碼編程——ping命令流程(圖)

不是我寫的,找的。

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#define WIN32_LEAN_AND_MEAN
#include <winsock.h>
#pragma comment(lib, "Wsock32.lib")

#define ICMP_ECHO 8
#define ICMP_ECHOREPLY 0

//#define ICMP_MIN 8 // minimum 8 byte icmp packet (just header)
#define ICMP_MIN (8 + 4) // minimum 8 byte icmp packet (just header + timestamp)

// IP header
typedef struct _tagX_iphdr
{
unsigned char h_len:4; // length of the header
unsigned char version:4; // Version of IP
unsigned char tos; // Type of service
unsigned short total_len; // total length of the packet

unsigned short ident; // unique identifier
unsigned short frag_and_flags; // flags

unsigned char ttl; // ttl
unsigned char proto; // protocol (TCP, UDP etc)
unsigned short checksum; // IP checksum

unsigned int sourceIP;
unsigned int destIP;
}XIpHeader;

// ICMP header
typedef struct _tagX_icmphdr
{
unsigned char i_type;
unsigned char i_code;
unsigned short i_cksum;
unsigned short i_id;
unsigned short i_seq;
unsigned long i_timestamp;
}XIcmpHeader;

//puclic code
//網際校驗和生產演算法
//網際校驗和是被校驗數據16位值的反碼和(ones-complement sum)
unsigned short in_cksum(unsigned short* addr, int len)
{
int nleft = len;
int sum = 0;
unsigned short* w = addr;
unsigned short answer = 0;

while(nleft > 1) {
sum += *w++;
nleft -= 2;
}

if(nleft == 1) {
*(unsigned char*)(&answer) = *(unsigned char*)w;
sum += answer;
}

sum = (sum >> 16) + (sum & 0xffff);
sum += (sum >> 16);
answer = ~sum;

return (answer);
}

void fill_IcmpData(char *buf, int datasize)
{
if (buf)
{
char ch = 0;
char* icmpdata = buf + sizeof(XIcmpHeader);
fprintf(stdout, "(IcmpData)\r\n");
for (int i = 0; i < datasize; i++)
{
ch = 'A' + i%('z' - 'A');
*(icmpdata + i) = ch;
fprintf(stdout, "%c", ch);
}
fprintf(stdout, "\r\n");
}
}

void fill_IcmpHeader(char *buf, int datasize)
{
static unsigned short seq_no = 0;
XIcmpHeader *icmp_hdr = (XIcmpHeader *)buf;
if (icmp_hdr)
{
icmp_hdr->i_type = ICMP_ECHO;
icmp_hdr->i_code = 0;
icmp_hdr->i_cksum = 0;

icmp_hdr->i_id = (unsigned short)GetCurrentProcessId();

icmp_hdr->i_seq = seq_no++;

icmp_hdr->i_timestamp = (unsigned long)::GetTickCount();

icmp_hdr->i_cksum = in_cksum((unsigned short*)buf, sizeof(XIcmpHeader) + datasize);

fprintf(stdout, "(IcmpHeader)\r\n");
fprintf(stdout, "%02X%02X%04X\r\n", icmp_hdr->i_type, icmp_hdr->i_code, icmp_hdr->i_cksum);
fprintf(stdout, "%04X%04X\r\n", icmp_hdr->i_id, icmp_hdr->i_seq);
fprintf(stdout, "%08X\r\n", icmp_hdr->i_timestamp);
}
}

// decode
void decode_IpIcmp(char *buf, int size)
{
XIpHeader *ip_hdr = (XIpHeader *)buf;
unsigned short iphdrlen;
if (ip_hdr)
{
fprintf(stdout, "(IpHeader)\r\n");
fprintf(stdout, "%01X%01X%02X%04X\r\n", ip_hdr->version, ip_hdr->h_len, ip_hdr->tos, ip_hdr->total_len);
fprintf(stdout, "%04X%04X\r\n", ip_hdr->ident, ip_hdr->frag_and_flags);
fprintf(stdout, "%02X%02X%04X\r\n", ip_hdr->ttl, ip_hdr->proto, ip_hdr->checksum);

//iphdrlen = ip_hdr->h_len * 4; // number of 32-bit words *4 = bytes
iphdrlen = ip_hdr->h_len << 2; // number of 32-bit words *4 = bytes
fprintf(stdout, "(IcmpHeader)\r\n");
if (size < iphdrlen + ICMP_MIN)
{
fprintf(stdout, "Reply %d bytes Too few\r\n", size);
}
else
{
XIcmpHeader *icmp_hdr = (XIcmpHeader *)(buf + iphdrlen);

fprintf(stdout, "%02X%02X%04X\r\n", icmp_hdr->i_type, icmp_hdr->i_code, icmp_hdr->i_cksum);
fprintf(stdout, "%04X%04X\r\n", icmp_hdr->i_id, icmp_hdr->i_seq);
fprintf(stdout, "%08X\r\n", icmp_hdr->i_timestamp);

unsigned long timestamp = 0;

timestamp = (unsigned long)::GetTickCount();

timestamp -= icmp_hdr->i_timestamp;

struct sockaddr_in from;
from.sin_addr.s_addr = ip_hdr->sourceIP;

fprintf(stdout, "Reply %d bytes from: %s time<%d TTL=%d icmp_seq=%d\r\n",
size,
inet_ntoa(from.sin_addr),
timestamp,
ip_hdr->ttl,
icmp_hdr->i_seq
);
}
}
}

int main(int argc, char **argv)
{
int ret = 0;

WSADATA ws;
WSAStartup(0x0101,&ws);

int iIcmpDataSize = 0;
struct sockaddr_in dest,from;
unsigned int addr = 0;
struct hostent *hp;

char buffer[1024];
char recv_buffer[1024];

if(argc < 2)
{
fprintf(stderr, "Usage: %s [host|ip] [datasize]\r\n", argv[0]);
return 0;
}

if (argc > 2)
iIcmpDataSize = atoi(argv[2]);
if (iIcmpDataSize < 1 || iIcmpDataSize > 1024)
iIcmpDataSize = 10;

memset(&dest, 0, sizeof dest);
dest.sin_family = AF_INET;
hp = gethostbyname(argv[1]);
if (!hp)
addr = inet_addr(argv[1]);
if ((!hp) && (addr == INADDR_NONE))
{
fprintf(stderr,"Unable to resolve %s\r\n",argv[1]);
return 0;
}
if (hp != NULL)
memcpy(&(dest.sin_addr), hp->h_addr,hp->h_length);
else
dest.sin_addr.s_addr = addr;

int sockfd;
sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);

fprintf(stdout, "XPing...\r\n");
for (int i = 0; i < 3; i++)
{
fprintf(stdout, "Echo...\r\n");
memset(buffer, 0, 1024);
fill_IcmpData(buffer, iIcmpDataSize);
fill_IcmpHeader(buffer, iIcmpDataSize);
XIcmpHeader *icmp_hdr = (XIcmpHeader *)buffer;
int iSendSize = sendto(sockfd, buffer, sizeof(XIcmpHeader) + iIcmpDataSize, 0, (struct sockaddr*)&dest, sizeof(dest));

fprintf(stdout, "Reply...\r\n");
memset(&from, 0, sizeof from);
memset(recv_buffer, 0, 1024);

int fromlen = sizeof(from);
int iRecvSize = recvfrom(sockfd, recv_buffer, 1024, 0, (struct sockaddr*)&from, &fromlen);

if (iRecvSize > 0)
decode_IpIcmp(recv_buffer, iRecvSize);
}

WSACleanup();

return ret;
}

⑹ gethostbyname源碼在哪個目錄

你所說的源代碼是哪一部分的源代碼?因為我們一般說的linux源碼是指內核,這個在裝好的系統里是沒有的,你要下載才行。

⑺ c語言獲取網頁源碼

這個不是c語言的問題,網頁很明確的告訴這個文檔已經搬到t.sina.com.cn。這是一個跳轉網頁,你手動復制weibo.sina.com到瀏覽器,你看會跳轉到weibo.com/guide/welcome,c不會像瀏覽器那樣跳轉後再獲取吧,除非你改下程序,但是可能要涉及到http協議了,學術淺薄,就不多講,祝你好運!

⑻ C++高手來啊,對一個軟體源碼修改一個小地方:就是把填ip地址的地方修改成填域名也有效

嗯,這需要轉換一下,可以用gethostbyname網路搜索傑迅網路

⑼ WSAAsyncGetHostByName()的簡介

簡述:
獲得對應於一個主機名的主機信息.-非同步版本.
#include <winsock.h>
HANDLE PASCAL FAR WSAAsyncGetHostByName (HWND hWnd,
unsigned int wMsg,const char FAR * name,char FAR * buf,
int buflen);
hWnd 當非同步請求完成時,應該接收消息的窗口句柄.
wMsg 當非同步請求完成時,將要接收的消息.
name 指向主機名的指針.
buf 接收hostent數據的數據區指針.注意該數據區必須大於hostent結構的大小.這是因為不僅Windows Sockets實現要用該數據區域容納hostent結構,hostent結構的成員引用的所有數據也要在該區域內.建議用戶提供一個MAXGETHOSTSTRUCT位元組大小的緩沖區.
buflen上述數據區的大小.
注釋:
本函數是gethostbyname()的非同步版本,是用來獲取對應於一個主機名的主機名稱和地址信息.Windows Sockets的實現啟動該操作後立刻返回調用方,並傳回一個非同步任務句柄,應用程序可以用它來標識該操作.當操作完成時,結果(若有的話)將會拷貝到調用方提供的緩沖區,同時向應用程序的窗口發一條消息.
當非同步操作完成時,應用程序的窗口hWnd接收到消息wMsg. wParam參數包含了初次函數調用時返回的非同步任務句柄.lParam的高16位包含著錯誤代碼.該代碼可以是winsock.h中定義的任何錯誤.錯誤代碼為0說明非同步操作成功.在成功完成的情況下,提供給初始函數調用的緩沖區中包含了一個hostent結構.為存取該結構中的元素,初始的緩沖區指針應置為hostent結構的指針,並一如平常地存取.
注意若錯誤代碼為WSAENOBUFS,它說明在初始調用時由buflen指出的緩沖區大小對於容納所有的結果信息來說太小了.在這種情況下,lParam的低16位含有提供所有信息所需的緩沖區大小數值.如果應用程序認為獲取的數據不夠,它就可以在設置了足夠容納所需信息的緩沖區後,重新調用WSAAsyncGetHostByName().(也就是大於lParam低16位提供的大小.)
錯誤代碼和緩沖區大小應使用WSAGETASYNCERROR和WSAGETASYNCBUFLEN宏從lParam中取出.兩個宏定義如下:
#define WSAGETASYNCERROR(lParam) HIWORD(lParam)
#define WSAGETASYNCBUFLEN(lParam) LOWORD(lParam)
使用這些宏可最大地提高應用程序源代碼的可移植性.
返回值:
返回值指出非同步操作是否成功地初啟.注意它並不隱含操作本身的成功或失敗.
若操作成功地初啟,WSAAsyncGetHostByName()返回一個HANDLE類型的非0值,作為請求需要的非同步任務句柄.該值可在兩種方式下使用.它可通過WSACancelAsyncRequest()用來取消該操作.也可通過檢查wParam消息參數,以匹配非同步操作和完成消息.
如果非同步操作不能初啟,WSAAsyncGetHostByName()返回一個0值,並且可使用WSAGetLastError()來獲取錯誤號.
評價:
Windows Sockets的實現使用提供給該函數的緩沖區來構造hostent結構以及該結構成員引用的數據區內容.為避免上述的WSAENOBUFS錯誤,應用程序應提供一個至少MAXGETHOSTSTRUCT位元組大小的緩沖區.
關於Windows Sockets提供者的說明:
Windows Sockets的實現應保證消息能成功地傳給應用程序.如果PostMessage()操作失敗,Windows Sockets的實現必須重發該消息-只要窗口存在.
Windows Sockets的提供者在消息中組織lParam時應使用WSAMAKEASYNCREPLY宏.

⑽ 求windows下ping程序c源代碼,模擬的ping也行,能編譯通過就行,網上很多通不過

#pragma pack(4)
#define WIN32_LEAN_AND_MEAN
#include
#include
#include
#define ICMP_ECHO 8
#define ICMP_ECHOREPLY 0
#define ICMP_MIN 8 // minimum 8 byte icmp packet (just header)
/* The IP header */
typedef struct iphdr {
unsigned int h_len:4; // length of the header
unsigned int version:4; // Version of IP
unsigned char tos; // Type of service
unsigned short total_len; // total length of the packet
unsigned short ident; // unique identifier
unsigned short frag_and_flags; // flags
unsigned char ttl;
unsigned char proto; // protocol (TCP, UDP etc)
unsigned short checksum; // IP checksum
unsigned int sourceIP;
unsigned int destIP;
}IpHeader;
//
// ICMP header
//
typedef struct _ihdr {
BYTE i_type;
BYTE i_code; /* type sub code */
USHORT i_cksum;
USHORT i_id;
USHORT i_seq;
/* This is not the std header, but we reserve space for time */
ULONG timestamp;
}IcmpHeader;
#define STATUS_FAILED 0xFFFF
#define DEF_PACKET_SIZE 32
#define MAX_PACKET 1024
#define xmalloc(s) HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(s))
#define xfree(p) HeapFree (GetProcessHeap(),0,(p))
void fill_icmp_data(char *, int);
USHORT checksum(USHORT *, int);
void decode_resp(char *,int ,struct sockaddr_in *);
void Usage(char *progname){
fprintf(stderr,"Usage: ");
fprintf(stderr,"%s [data_size] ",progname);
fprintf(stderr,"datasize can be up to 1Kb ");
ExitProcess(STATUS_FAILED);
}
int main(int argc, char **argv){
WSADATA wsaData;
SOCKET sockRaw;
struct sockaddr_in dest,from;
struct hostent * hp;
int bread,datasize;
int fromlen = sizeof(from);
int timeout = 1000;
char *dest_ip;
char *icmp_data;
char *recvbuf;
unsigned int addr=0;
USHORT seq_no = 0;
if (WSAStartup(MAKEWORD(2,1),&wsaData) != 0){
fprintf(stderr,"WSAStartup failed: %d ",GetLastError());
ExitProcess(STATUS_FAILED);
}
if (argc <2 ) {
Usage(argv[0]);
}
sockRaw = WSASocket (AF_INET,
SOCK_RAW,
IPPROTO_ICMP,
NULL, 0,0);
if (sockRaw == INVALID_SOCKET) {
fprintf(stderr,"WSASocket() failed: %d ",WSAGetLastError());
ExitProcess(STATUS_FAILED);
}
bread = setsockopt(sockRaw,SOL_SOCKET,SO_RCVTIMEO,(char*)&timeout,
sizeof(timeout));
if(bread == SOCKET_ERROR) {
fprintf(stderr,"failed to set recv timeout: %d ",WSAGetLastError());
ExitProcess(STATUS_FAILED);
}
timeout = 1000;
bread = setsockopt(sockRaw,SOL_SOCKET,SO_SNDTIMEO,(char*)&timeout,
sizeof(timeout));
if(bread == SOCKET_ERROR) {
fprintf(stderr,"failed to set send timeout: %d ",WSAGetLastError());
ExitProcess(STATUS_FAILED);
}
memset(&dest,0,sizeof(dest));
hp = gethostbyname(argv[1]);
if (!hp){
addr = inet_addr(argv[1]);
}
if ((!hp) && (addr == INADDR_NONE) ) {
fprintf(stderr,"Unable to resolve %s ",argv[1]);
ExitProcess(STATUS_FAILED);
}
if (hp != NULL)
memcpy(&(dest.sin_addr),hp->h_addr,hp->h_length);
else
dest.sin_addr.s_addr = addr;
if (hp)
dest.sin_family = hp->h_addrtype;
else
dest.sin_family = AF_INET;
dest_ip = inet_ntoa(dest.sin_addr);
if (argc >2) {
datasize = atoi(argv[2]);
if (datasize == 0)
datasize = DEF_PACKET_SIZE;
}
else
datasize = DEF_PACKET_SIZE;
datasize += sizeof(IcmpHeader);
icmp_data = xmalloc(MAX_PACKET);
recvbuf = xmalloc(MAX_PACKET);
if (!icmp_data) {
fprintf(stderr,"HeapAlloc failed %d ",GetLastError());
ExitProcess(STATUS_FAILED);
}
memset(icmp_data,0,MAX_PACKET);
fill_icmp_data(icmp_data,datasize);
while(1) {
int bwrote;
((IcmpHeader*)icmp_data)->i_cksum = 0;
((IcmpHeader*)icmp_data)->timestamp = GetTickCount();
((IcmpHeader*)icmp_data)->i_seq = seq_no++;
((IcmpHeader*)icmp_data)->i_cksum = checksum((USHORT*)icmp_data,
datasize);
bwrote = sendto(sockRaw,icmp_data,datasize,0,(struct sockaddr*)&dest,
sizeof(dest));
if (bwrote == SOCKET_ERROR){
if (WSAGetLastError() == WSAETIMEDOUT) {
printf("timed out ");
continue;
}
fprintf(stderr,"sendto failed: %d ",WSAGetLastError());
ExitProcess(STATUS_FAILED);
}
if (bwrote < datasize ) {
fprintf(stdout,"Wrote %d bytes ",bwrote);
}
bread = recvfrom(sockRaw,recvbuf,MAX_PACKET,0,(struct sockaddr*)&from,
&fromlen);
if (bread == SOCKET_ERROR){
if (WSAGetLastError() == WSAETIMEDOUT) {
printf("timed out ");
continue;
}
fprintf(stderr,"recvfrom failed: %d ",WSAGetLastError());
ExitProcess(STATUS_FAILED);
}
decode_resp(recvbuf,bread,&from);
Sleep(1000);
}
return 0;
}
/*
The response is an IP packet. We must decode the IP header to locate
the ICMP data
*/
void decode_resp(char *buf, int bytes,struct sockaddr_in *from) {
IpHeader *iphdr;
IcmpHeader *icmphdr;
unsigned short iphdrlen;
iphdr = (IpHeader *)buf;
iphdrlen = iphdr->h_len * 4 ; // number of 32-bit words *4 = bytes
if (bytes < iphdrlen + ICMP_MIN) {
printf("Too few bytes from %s ",inet_ntoa(from->sin_addr));
}
icmphdr = (IcmpHeader*)(buf + iphdrlen);
if (icmphdr->i_type != ICMP_ECHOREPLY) {
fprintf(stderr,"non-echo type %d recvd ",icmphdr->i_type);
return;
}
if (icmphdr->i_id != (USHORT)GetCurrentProcessId()) {
fprintf(stderr,"someone else's packet! ");
return ;
}
printf("%d bytes from %s:",bytes, inet_ntoa(from->sin_addr));
printf(" icmp_seq = %d. ",icmphdr->i_seq);
printf(" time: %d ms ",GetTickCount()-icmphdr->timestamp);
printf(" ");
}
USHORT checksum(USHORT *buffer, int size) {
unsigned long cksum=0;
while(size >1) {
cksum+=*buffer++;
size -=sizeof(USHORT);
}
if(size ) {
cksum += *(UCHAR*)buffer;
}
cksum = (cksum >> 16) + (cksum & 0xffff);
cksum += (cksum >>16);
return (USHORT)(~cksum);
}
/*
Helper function to fill in various stuff in our ICMP request.
*/
void fill_icmp_data(char * icmp_data, int datasize){
IcmpHeader *icmp_hdr;
char *datapart;
icmp_hdr = (IcmpHeader*)icmp_data;
icmp_hdr->i_type = ICMP_ECHO;
icmp_hdr->i_code = 0;
icmp_hdr->i_id = (USHORT)GetCurrentProcessId();
icmp_hdr->i_cksum = 0;
icmp_hdr->i_seq = 0;
datapart = icmp_data + sizeof(IcmpHeader);
//
// Place some junk in the buffer.
//
memset(datapart,'E', datasize - sizeof(IcmpHeader));
}

估計你也試過,網上搜到的。

熱點內容
intel快速存儲ssd 發布:2024-11-15 20:00:27 瀏覽:142
吃雞配置太低怎麼調高畫質 發布:2024-11-15 19:58:19 瀏覽:734
王者怎麼設置來電屏蔽安卓 發布:2024-11-15 19:56:08 瀏覽:449
伺服器如何搭建多個ip 發布:2024-11-15 19:42:10 瀏覽:102
價錢低高配置的有哪些車 發布:2024-11-15 19:34:53 瀏覽:380
androidgps定位開發 發布:2024-11-15 19:34:52 瀏覽:334
如何掃碼添加伺服器地址 發布:2024-11-15 19:31:48 瀏覽:278
sql語句復制資料庫 發布:2024-11-15 19:28:02 瀏覽:837
演算法的薪資 發布:2024-11-15 19:15:22 瀏覽:322
ubuntu可以重新編譯嗎 發布:2024-11-15 19:09:10 瀏覽:649