Networking Forums

Networking Forums > Computer Networking > Linux Networking > tcp/ip illustrated volume2 page4 code (recvfrom function)does notwork

Reply
Thread Tools Display Modes

tcp/ip illustrated volume2 page4 code (recvfrom function)does notwork

 
 
westnorth
Guest
Posts: n/a

 
      08-13-2008, 05:28 AM
this is the code,but after compile ,run .
it doesn't work.
use gdb debug,it stopped at recvfrom (line 24),no error return,but it
stopped,how can I do?

1 #include <sys/types.h>
2 #include <sys/socket.h>
3 #include <netinet/in.h>
4 #include <arpa/inet.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #define BUFFSIZE 150
9 //#define int socklen_t

10 int main()
11 {
12 struct sockaddr_in serv;
13 char buff[BUFFSIZE];
14 int sockfd,n;
15 if((sockfd = socket(PF_INET,SOCK_DGRAM,0)) <0)
16 printf("socket error");
17 bzero((char*)&serv ,sizeof(serv));
18 serv.sin_family=AF_INET;
19 serv.sin_addr.s_addr=inet_addr("64.233.189.104");
20 serv.sin_port=htons(13);

21 if(sendto(sockfd,buff,BUFFSIZE,0,
22 (struct sockaddr*)&serv,sizeof(serv))!=BUFFSIZE)
23 printf("sendto error");

24 if((n=recvfrom(sockfd,buff,BUFFSIZE,0,
25 (struct sockaddr*)NULL,(int*) NULL))<2)
26 printf("recvfrom error");
27 buff[n-2]=0;
28 printf("%s\n",buff);
29 // exit(0);
30 return 0;
31 }
 
Reply With Quote
 
 
 
 
Tauno Voipio
Guest
Posts: n/a

 
      08-13-2008, 06:34 PM
westnorth wrote:
> this is the code,but after compile ,run .
> it doesn't work.
> use gdb debug,it stopped at recvfrom (line 24),no error return,but it
> stopped,how can I do?
>
> 1 #include <sys/types.h>
> 2 #include <sys/socket.h>
> 3 #include <netinet/in.h>
> 4 #include <arpa/inet.h>
> 5 #include <stdio.h>
> 6 #include <stdlib.h>
> 7 #include <string.h>
> 8 #define BUFFSIZE 150
> 9 //#define int socklen_t
>
> 10 int main()
> 11 {
> 12 struct sockaddr_in serv;
> 13 char buff[BUFFSIZE];
> 14 int sockfd,n;
> 15 if((sockfd = socket(PF_INET,SOCK_DGRAM,0)) <0)
> 16 printf("socket error");
> 17 bzero((char*)&serv ,sizeof(serv));
> 18 serv.sin_family=AF_INET;
> 19 serv.sin_addr.s_addr=inet_addr("64.233.189.104");
> 20 serv.sin_port=htons(13);
>
> 21 if(sendto(sockfd,buff,BUFFSIZE,0,
> 22 (struct sockaddr*)&serv,sizeof(serv))!=BUFFSIZE)
> 23 printf("sendto error");
>
> 24 if((n=recvfrom(sockfd,buff,BUFFSIZE,0,
> 25 (struct sockaddr*)NULL,(int*) NULL))<2)
> 26 printf("recvfrom error");
> 27 buff[n-2]=0;
> 28 printf("%s\n",buff);
> 29 // exit(0);
> 30 return 0;
> 31 }



What makes you think that there's an UDP daytime server
at that address of Google?

It is perfectly correct to get held in the recvfrom() if
the addressed computer elects not to respond.

--

Tauno Voipio
tauno voipio (at) iki fi
 
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Socket: recvfrom sathya Linux Networking 1 05-07-2009 01:08 PM
Multicast recvfrom not working?????? cs3266@gmail.com Linux Networking 3 06-26-2006 04:17 PM
recvfrom() unblocking.. how to do it? manu Linux Networking 4 04-21-2006 08:12 PM
problem with recvfrom Omega Linux Networking 0 11-21-2005 08:17 PM
Compile the 'sock' program in the book 'TCP/IP Illustrated Vol.1' Steven Woody Linux Networking 2 11-21-2005 08:16 AM



1 2 3 4 5 6 7 8 9 10 11