Winsock / Socket Created / Packet not send

Winsock / Socket Created / Packet not send

Post by monoch.. » Fri, 29 Nov 2002 22:04:26



Hi out there !

I hope someone can help me in this.

I am new to Winsock Programming, but now I have written an Applicatian
that should send an UDP packet. It is compiled without errors.

When I stat the Programm it outputs:

Winsock startet !
UDP Socket createt !
11 Bytes Data send  !

Than the Firewall Allerts:

Outbound Connection
Port xxx
Remote IP: < IP adress provided by my Providert>

of Course, I allow this Connection...

Now there should be an Inbound connection Alert, but It isn't. I have
tried to grab the UDP PAcket - but there is simply no UDP PAcket to
Sniff. I have tried to send the packet to a friend - the same result -
nothing is reaching it's Destination.

sorry for my Bad English :-)
Help would be really Great !

Greetz,
Ole

Here's the code I have written:

#include <windows.h>
#include <winsock2.h>
#include <stdio.h>

int ini_Winsock(void);
int startWinsock(void);
int open_socket(int);
int send_data(void);

long rc;
SOCKET sock_1;
SOCKADDR_IN addr;
SOCKADDR_IN remoteAddr;
int remoteAddrLen;
char buf[256];

void main(void){
  open_socket(1);
  closesocket(sock_1);
  WSACleanup();

  }

int startWinsock()
{
 rc=ini_Winsock();
 if(rc!=0)
 {
  printf("Fehler: startWinsock, error code: %d\n",rc);
  return 1;
 }else{
     printf("Winsock startet!\n");
     }

  return 0;
 }

int ini_Winsock()
{
 WSADATA wsa;
 return WSAStartup(MAKEWORD(1,2),&wsa);

Quote:}

int open_socket(int option){
  startWinsock();
  if (option == 1){
     printf("einz ist der Fall");
     sock_1=socket(AF_INET,SOCK_DGRAM,0);
     if(sock_1==INVALID_SOCKET){
     printf("Error the UDP Socket couldn't be Created \n");
     }else {printf("UDP SOCKET Createt \n");}
     }else if (option == 2){
            printf("zwei ist der Fall");
            }else if (option == 3){
                  printf("drei ist der Fall");
                  }

 printf("%d", option);
 send_data();
 getch();
 return 0;}

int send_data(){

    addr.sin_family=AF_INET;
    addr.sin_port=htons(2172);
    addr.sin_addr.s_addr=inet_addr("212.6.79.173");

    strcpy(buf,"Hallo Welt!");

rc=sendto(sock_1,buf,strlen(buf),0,(SOCKADDR*)&addr,sizeof(SOCKADDR_IN));
    if(rc==SOCKET_ERROR)
    {
    printf("Error: sendto, Errorr code: %d\n",WSAGetLastError());
    return 1;
    }else{
    printf("%d Bytes gesendet!\n", rc);
    printf("%d\n", WSAGetLastError());
    }
    return 0;}

 
 
 

Winsock / Socket Created / Packet not send

Post by Ciaran Keatin » Sat, 30 Nov 2002 13:39:57



> Now there should be an Inbound connection Alert, but It isn't. I have
> tried to grab the UDP PAcket - but there is simply no UDP PAcket to
> Sniff. I have tried to send the packet to a friend - the same result -
> nothing is reaching it's Destination.

Hi Ole,

I've tested your code and it works fine. I think the problem is on your
receiving end. The code you've posted only shows the sending operation,
so I added the following code to yours to receive the data:

In main, I check for a command line paramter: "send" => open_socket(1)
and "receive" => open_socket(2).  I borrowed your "option 1" and "option
2" for this purpose:

   if(strcmpi(argv[1],"send") == 0)
   {
     printf("Sending...\r\n");
     open_socket(1);
     closesocket(sock_1);
     WSACleanup();
   }
   else if(strcmpi(argv[1],"receive") == 0)
   {
     printf("Receiving...\r\n");
     open_socket(2);
     closesocket(sock_1);
     WSACleanup();
   }

Then in open_socket:

   else if (option == 2)
   {
     sock_1=socket(AF_INET,SOCK_DGRAM,0);
     struct sockaddr_in addr;
     memset(&addr,0,sizeof(addr));
     addr.sin_family = AF_INET;
     addr.sin_port = htons(2172);
     bind(sock_1,(struct sockaddr*)&addr,sizeof(addr));
     char buf[100];
     recvfrom(sock_1,buf,100,0,NULL,NULL);
     printf("%s\r\n",buf);
   }

When I ran these two versions (either on the same machine, or on two
machines) it worked perfectly.

Maybe you'd like us to look at your receiver code?

Cheers,
Ciaran

 
 
 

Winsock / Socket Created / Packet not send

Post by monoch.. » Sun, 01 Dec 2002 01:56:35


Hi,

thanx for the code, i will try soon. Before I didn't had a listener,
and I thought, I would not need such thing. Think about Portscanning -
there is no listener, but my Firewall also grabs a Connection try.


some Question.

meanwhile...

I have made a receiver - it works, it receives 11 Bytes Data when i
run the sender. but only with my local IP. After using that
Application, other programs on my PC wantet to connect to Outbound to

(Trillian instant messenger and Emule wanted to do that.)

Ok, when I put 127.0.0.1 it works, but Ethereal still grabs no
packets.

Greetz,
Ole

On Fri, 29 Nov 2002 15:39:57 +1100, Ciaran Keating



>> Now there should be an Inbound connection Alert, but It isn't. I have
>> tried to grab the UDP PAcket - but there is simply no UDP PAcket to
>> Sniff. I have tried to send the packet to a friend - the same result -
>> nothing is reaching it's Destination.

>Hi Ole,

>I've tested your code and it works fine. I think the problem is on your
>receiving end. The code you've posted only shows the sending operation,
>so I added the following code to yours to receive the data:

>In main, I check for a command line paramter: "send" => open_socket(1)
>and "receive" => open_socket(2).  I borrowed your "option 1" and "option
>2" for this purpose:

>   if(strcmpi(argv[1],"send") == 0)  

what purpose of  strcmpi  ?  

- Show quoted text -

Quote:>   {
>     printf("Sending...\r\n");
>     open_socket(1);
>     closesocket(sock_1);
>     WSACleanup();
>   }
>   else if(strcmpi(argv[1],"receive") == 0)
>   {
>     printf("Receiving...\r\n");
>     open_socket(2);
>     closesocket(sock_1);
>     WSACleanup();
>   }

>Then in open_socket:

>   else if (option == 2)
>   {
>     sock_1=socket(AF_INET,SOCK_DGRAM,0);
>     struct sockaddr_in addr;
>     memset(&addr,0,sizeof(addr));
>     addr.sin_family = AF_INET;
>     addr.sin_port = htons(2172);
>     bind(sock_1,(struct sockaddr*)&addr,sizeof(addr));
>     char buf[100];
>     recvfrom(sock_1,buf,100,0,NULL,NULL);
>     printf("%s\r\n",buf);
>   }

>When I ran these two versions (either on the same machine, or on two
>machines) it worked perfectly.

>Maybe you'd like us to look at your receiver code?

>Cheers,
>Ciaran

 
 
 

Winsock / Socket Created / Packet not send

Post by John Smit » Sun, 01 Dec 2002 03:31:40


strcmpi() compares two strings WITHOUT case sensitivity...

Regards,
John Smith

> Hi,

> thanx for the code, i will try soon. Before I didn't had a listener,
> and I thought, I would not need such thing. Think about Portscanning -
> there is no listener, but my Firewall also grabs a Connection try.


> some Question.

> meanwhile...

> I have made a receiver - it works, it receives 11 Bytes Data when i
> run the sender. but only with my local IP. After using that
> Application, other programs on my PC wantet to connect to Outbound to

> (Trillian instant messenger and Emule wanted to do that.)

> Ok, when I put 127.0.0.1 it works, but Ethereal still grabs no
> packets.

> Greetz,
> Ole

> On Fri, 29 Nov 2002 15:39:57 +1100, Ciaran Keating


> >> Now there should be an Inbound connection Alert, but It isn't. I have
> >> tried to grab the UDP PAcket - but there is simply no UDP PAcket to
> >> Sniff. I have tried to send the packet to a friend - the same result -
> >> nothing is reaching it's Destination.

> >Hi Ole,

> >I've tested your code and it works fine. I think the problem is on your
> >receiving end. The code you've posted only shows the sending operation,
> >so I added the following code to yours to receive the data:

> >In main, I check for a command line paramter: "send" => open_socket(1)
> >and "receive" => open_socket(2).  I borrowed your "option 1" and "option
> >2" for this purpose:

> >   if(strcmpi(argv[1],"send") == 0)

> what purpose of  strcmpi  ?

> >   {
> >     printf("Sending...\r\n");
> >     open_socket(1);
> >     closesocket(sock_1);
> >     WSACleanup();
> >   }
> >   else if(strcmpi(argv[1],"receive") == 0)
> >   {
> >     printf("Receiving...\r\n");
> >     open_socket(2);
> >     closesocket(sock_1);
> >     WSACleanup();
> >   }

> >Then in open_socket:

> >   else if (option == 2)
> >   {
> >     sock_1=socket(AF_INET,SOCK_DGRAM,0);
> >     struct sockaddr_in addr;
> >     memset(&addr,0,sizeof(addr));
> >     addr.sin_family = AF_INET;
> >     addr.sin_port = htons(2172);
> >     bind(sock_1,(struct sockaddr*)&addr,sizeof(addr));
> >     char buf[100];
> >     recvfrom(sock_1,buf,100,0,NULL,NULL);
> >     printf("%s\r\n",buf);
> >   }

> >When I ran these two versions (either on the same machine, or on two
> >machines) it worked perfectly.

> >Maybe you'd like us to look at your receiver code?

> >Cheers,
> >Ciaran

 
 
 

Winsock / Socket Created / Packet not send

Post by Ciaran Keatin » Sun, 01 Dec 2002 08:16:44



> Hi,

> thanx for the code, i will try soon. Before I didn't had a listener,
> and I thought, I would not need such thing. Think about Portscanning -
> there is no listener, but my Firewall also grabs a Connection try.

Maybe I misunderstood your intention... what exactly are you trying to
do? Are you trying to send UDP data as part of an application, or are
you trying to write a packet sniffer?

If you're writing an application, then you know that your send/receive
code works, so the problem lies somewhere on the network - your network
stack, your firewall, your ISP, your friend's ISP, your friend's
firewall, or your friend's network stack.

If you're writing a packet sniffer, then... probably the same things,
actually.

 From your original post:

 > I have written an Applicatian that should send an UDP packet.

I think your _application_ successfully does this, but maybe you've got
network/firewall problems?

 > Now there should be an Inbound connection Alert, but It isn't.

Why should there be in inbound connection? I'm not an expert, but...
when you send data (via either TCP or UDP) to the local machine, the
network stack doesn't send the data to the physical layer - I think it
only goes as far as the transport layer, where it gets passed from the
sender side to the receiver side. So, depending on how your firewall
works, it might not see the packet.

 > I have tried to send the packet to a friend - the same result -
 > nothing is reaching it's Destination.

Can you make other connections to your friend? For example, can you make
a TCP connection to the same port on his machine? Does his firewall
allow UDP connections to that port? What happens if you both disable
your firewalls for ten minutes to perform a test? Can you arrange to
have two machines in one room, connected via ethernet (or whatever),
thereby removing your ISP from the equation? (Or maybe you can do some
tests in a university or work lab?)

Quote:>>  if(strcmpi(argv[1],"send") == 0)  

> what purpose of  strcmpi  ?  

Same as strcmp except that it's case insensitive. It's not important in
this case - I could have used strcmp instead.

I hope I'm helping here... if I'm on the wrong track then please tell me :-)

Cheers,
Ciaran

 
 
 

Winsock / Socket Created / Packet not send

Post by monoch.. » Mon, 02 Dec 2002 03:03:26


Hello again,

Quote:>Maybe I misunderstood your intention... what exactly are you trying to
>do? Are you trying to send UDP data as part of an application, or are
>you trying to write a packet sniffer?

nothing of that. I just wanted to programm an Application that sends a
Packet to a speciefied IP / port with UDP. When it's working I wanted
to programm a ICQ Client, or HTTP client - something like that. But I
don't have a big Idead about what I want to Programm in the first
winsock steps - later when I am familiar with Winsock and IP
Programming, I wanted to write a Programm that captures incoming  ICMP
Packets and sends some, too.

Quote:

>If you're writing an application, then you know that your send/receive
>code works, so the problem lies somewhere on the network - your network
>stack, your firewall, your ISP, your friend's ISP, your friend's
>firewall, or your friend's network stack.

probably not, because the Application (client) runs very buggy, the
last Time i had run the UDP Packet sender Borland De* told me

(don't know how much f exactly the de* told me.)

Quote:

>If you're writing a packet sniffer, then... probably the same things,
>actually.
> > Now there should be an Inbound connection Alert, but It isn't.

>Why should there be in inbound connection? I'm not an expert, but...
>when you send data (via either TCP or UDP) to the local machine, the
>network stack doesn't send the data to the physical layer - I think it
>only goes as far as the transport layer, where it gets passed from the
>sender side to the receiver side. So, depending on how your firewall
>works, it might not see the packet.

ok, when I send Data that's may true, when I use local IP 127.0.0.1 -
But If i use the Dynamic IP provided by my INET Provider it should go
out to the Provider, and then come back and because of that, there
should be an "inbound Connection".

Quote:>Can you make other connections to your friend? For example, can you make
>a TCP connection to the same port on his machine? Does his firewall
>allow UDP connections to that port? What happens if you both disable
>your firewalls for ten minutes to perform a test? Can you arrange to
>have two machines in one room, connected via ethernet (or whatever),
>thereby removing your ISP from the equation? (Or maybe you can do some
>tests in a university or work lab?)


Firewall, I use AtGuard. They were configured correct. I will try via
Ethernet next week, and I will ask my ISP - maybe they Discard that
packet ... ?

Anyone of you Guys / Girls :-) know how to change the Time To Live of
a Packet ? Maybe it's entry is to short.

OK, thanx and greetz - till next time.

Ole

Quote:

>>>  if(strcmpi(argv[1],"send") == 0)  

>> what purpose of  strcmpi  ?  

>Same as strcmp except that it's case insensitive. It's not important in
>this case - I could have used strcmp instead.

>I hope I'm helping here... if I'm on the wrong track then please tell me :-)

>Cheers,
>Ciaran

 
 
 

Winsock / Socket Created / Packet not send

Post by Ciaran Keatin » Tue, 03 Dec 2002 07:13:56


 > nothing of that. I just wanted to programm an Application that sends a
 > Packet to a speciefied IP / port with UDP. When it's working I wanted
 > to programm a ICQ Client, or HTTP client - something like that. But I
 > don't have a big Idead about what I want to Programm in the first
 > winsock steps - later when I am familiar with Winsock and IP
 > Programming, I wanted to write a Programm that captures incoming  ICMP
 > Packets and sends some, too.

OK, gotcha.

 > probably not, because the Application (client) runs very buggy, the
 > last Time i had run the UDP Packet sender Borland De* told me

 > (don't know how much f exactly the de* told me.)

Ah, now that's interesting. Perhaps you should fix this problem first?
What variable is at that address?

 > ok, when I send Data that's may true, when I use local IP 127.0.0.1 -
 > But If i use the Dynamic IP provided by my INET Provider it should go
 > out to the Provider, and then come back and because of that, there
 > should be an "inbound Connection".

When your ISP gives you a dynamic IP address, your computer reconfigures
itself to use that address. So you still have the same situation - your
packet doesn't need to go anywhere on the wire. (Well, that's how I
understand it - I could be wrong.)

 > I will ask my ISP - maybe they Discard that
 > packet ... ?

I doubt that.

 > Anyone of you Guys / Girls :-) know how to change the Time To Live of
 > a Packet ? Maybe it's entry is to short.

You can use setsockopt with the SO_SNDTIMEO/SO_RCVTIMEO options. But I
doubt that this is your problem.

Cheers,
Ciaran

 
 
 

Winsock / Socket Created / Packet not send

Post by monoch.. » Tue, 03 Dec 2002 15:02:16


> > probably not, because the Application (client) runs very buggy, the
> > last Time i had run the UDP Packet sender Borland De* told me

> > (don't know how much f exactly the de* told me.)

>Ah, now that's interesting. Perhaps you should fix this problem first?
>What variable is at that address?

Fixed that Problem. It was a Wrong Pointer Argument in sendto();
(no, that's not the reason for the lost packet)

Quote:>When your ISP gives you a dynamic IP address, your computer reconfigures
>itself to use that address. So you still have the same situation - your
>packet doesn't need to go anywhere on the wire. (Well, that's how I
>understand it - I could be wrong.)

could be the Answer. But that wouldn't explain why The Firewall don't
sees the Packet. The Client / Server now works fine when i use the
Local IP - Firewall Alerts inbound and Outbound. But it only Reports
inbound, when there is a listener. And that's what I don't get into my
Brain - My Firewall Alerts the whole Day "Inbound Connection"  - Even
if there is no listener at that port. Thanks for all the nice answers
- i will collect more info on that "lost Packet" issue... ok, byby  
and til next time.

Greetz,
Ole

Quote:> > I will ask my ISP - maybe they Discard that
> > packet ... ?

>I doubt that.

> > Anyone of you Guys / Girls :-) know how to change the Time To Live of
> > a Packet ? Maybe it's entry is to short.

>You can use setsockopt with the SO_SNDTIMEO/SO_RCVTIMEO options. But I
>doubt that this is your problem.

>Cheers,
>Ciaran

 
 
 

Winsock / Socket Created / Packet not send

Post by Ciaran Keatin » Wed, 04 Dec 2002 06:11:14



> Thanks for all the nice answers
> - i will collect more info on that "lost Packet" issue... ok, byby  
> and til next time.

OK, good luck :-)

Ciaran