| |
 |
|
|
Linux Forum Index » Linux Networking » tcp/ip illustrated volume2 page4 code (recvfrom...
Page 1 of 1
|
| Author |
Message |
| westnorth... |
Posted: Tue Aug 12, 2008 7:28 pm |
|
|
|
Guest
|
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 } |
|
|
| Back to top |
|
| Tauno Voipio... |
Posted: Wed Aug 13, 2008 1:34 pm |
|
|
|
Guest
|
westnorth wrote:
Quote: 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 |
|
|
| Back to top |
|
| |
|
Page 1 of 1
All times are GMT - 5 Hours
The time now is Thu Dec 04, 2008 4:43 pm
|
|