[En-Nut-Discussion] ICMP Sockets

Viktor Dvorak dvorakvik at seznam.cz
Mon Aug 11 11:21:04 CEST 2003


Dear Ralph,

    please can you send me the ICMP socket source code. I need PING very
much.

    Many thanks

    Viktor Dvorak
    Praha
    dvorakvik at seznam.cz

33333333333333333333333333333333333

----- Original Message -----
From: "Ralph Mason" <ralph.mason at telogis.com>
To: "en-Nut-Discussion" <en-nut-discussion at egnite.de>
Sent: Monday, August 11, 2003 10:10 AM
Subject: [En-Nut-Discussion] ICMP Sockets


> I have implemented ICMP sockets for NutOS if anyone is interested.
>
> You can do tracert, ping etc.
>
> You can also receive unreachable messages etc for a given TCP or UDP
> connection.
>
> Example code
>
> int ping(char* args[],int argc, FILE* f){
>
> u_long addr;
> ICMPSOCKET* sock;
> u_char data[32];
> int i;
>
> if ( argc < 2 ){
> fputs_P(PSTR("usage: ping host [timeout]\r\n"),f);
> return -1;
> }
>
> if( (addr = resolve_address_name(args[1],f)) == 0 ){
> cr(f);
> return 0;
> }
>
> sock = NutIcmpCreateSocket(IPPROTO_ICMP,1);
>
> fprintf_P(f,PSTR("Pinging %s [%a] with 32 bytes\r\n\r\n"),args[1],addr);
> fflush(f);
>
> for( i = 0 ; i < 4 ; i++){
> u_long reply_addr;
> u_char type;
> u_char code;
> u_long ticks;
>
> NutIcmpSendTo(sock,addr,ICMP_ECHO,0,data,32);
> ticks = NutGetTickCount();
>
> if ( NutIcmpReceiveFrom(sock,&reply_addr,&type,&code,data,32,3000) != 0){
>
> switch( type){
> case ICMP_ECHOREPLY:
> fprintf_P(f,PSTR("Relpy from %a %i ms\r\n"),reply_addr,
> (int)(((NutGetTickCount()-ticks)*1000)/ 40L));
> break;
>
> default:
> fprintf_P(f,PSTR("Relpy from %a type %i code %i\r\n"),
> reply_addr,type,code);
> }
> }
> else{
> fputs_P(PSTR("Request timed out.\r\n"),f);
> }
>
> fflush(f);
> }
>
> NutIcmpDestroySocket(sock);
>
> return 0;
> }
>
>
>
> If you want the code reply via email.
>
> Cheers
> Ralph
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.491 / Virus Database: 290 - Release Date: 18/06/2003
>
> _______________________________________________
> En-Nut-Discussion mailing list
> En-Nut-Discussion at egnite.de
> http://www.egnite.de/mailman/listinfo/en-nut-discussion
>




More information about the En-Nut-Discussion mailing list