C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

win|unix icmp socket difference?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
tikviva
Guest





PostPosted: Sat Sep 18, 2004 8:02 pm    Post subject: win|unix icmp socket difference? Reply with quote



Hi,

I am trying to port my Ping module from window to linux, and I've
encountered some odd, but interesting things.

I have a function to keep creating new sockets.

bool PingIt(unsigned long targetip)
{
// Create Variables
struct sockaddr_in target;
int newSocket = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);

// Setup destination socket address
target.sin_addr.s_addr = inet_addr(szIP);
target.sin_family = AF_INET;
target.sin_port = 0;

// Send Echo
SendEcho(newSocket, &target);

// Use select() to wait for data to be received
// default timeout value = 2 sec
return(WaitForEchoReply(newSocket, timeout));
}

this guy works fine on window, but when it comes it linux, everytime
when the program calls PingIt(), the *newSocket* will remain the same
value. Unlike windows, it changes eveytime. That gives the program a
brand new socket. Do you guys know why?

This is interesting. Thanks for helping.

Best wishes,

- eric

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
tikviva
Guest





PostPosted: Mon Sep 20, 2004 5:54 am    Post subject: Re: win|unix icmp socket difference? Reply with quote



I know what I did wrong, in unix the select() requires *n+1* as the
first parameter. Since I've put the socket num in FD_SET(socketnum,
&readfds), it requres me to put socketnum+1 as the 1st parameter of
select().

- tikviva

[email]tikviva (AT) yahoo (DOT) com[/email] (tikviva) wrote in message news:<4b2febc7.0409172205.5219192f (AT) posting (DOT) google.com>...
Quote:
Hi,

I am trying to port my Ping module from window to linux, and I've
encountered some odd, but interesting things.

I have a function to keep creating new sockets.

bool PingIt(unsigned long targetip)
{
// Create Variables
struct sockaddr_in target;
int newSocket = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);

// Setup destination socket address
target.sin_addr.s_addr = inet_addr(szIP);
target.sin_family = AF_INET;
target.sin_port = 0;

// Send Echo
SendEcho(newSocket, &target);

// Use select() to wait for data to be received
// default timeout value = 2 sec
return(WaitForEchoReply(newSocket, timeout));
}

this guy works fine on window, but when it comes it linux, everytime
when the program calls PingIt(), the *newSocket* will remain the same
value. Unlike windows, it changes eveytime. That gives the program a
brand new socket. Do you guys know why?


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.