首页 > 代码库 > ping(1)
ping(1)
/*ping program for learning IP protocol author: jeff date: 2014/10/25*/#include <stdio.h>#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <errno.h>static int ICMP_create();static int opt_set(int sockfd);intmain(int argc, char* argv[]){ int sockfd = ICMP_create(); int optset = 0; if(sockfd != -1) printf("create socket ICMP success!\n"); else printf("create socket ICMP failed [%d]!\n", errno); optset = opt_set(sockfd); if(optset != -1) printf("sock set success\n"); else printf("sock set failed\n"); return 0;}static int ICMP_create(){ return socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);}static int opt_set(int sockfd){ int on =1; return setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on)); }
ping(1)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。