当前位置: 技术问答>linux和unix
linux下udp的recvfrom问题,大神,我需要你。。。
来源: 互联网 发布时间:2017-01-11
本文导语: #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define PORT 5000 int main...
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define PORT 5000
int main(int argc,char *argv[])
{
int sockfd;
struct sockaddr_in addr_remote;
char end[]="send overn";
int i;
int j;
int rn;
int sin_size=sizeof(struct sockaddr_in);
char name[128]={0};
rn=0;
i=0;
printf("1 ");
if (argc != 2)
{
printf ("Usage: talker HOST IP (ex: ./talker 192.168.0.94).n");
}
if ((sockfd = socket(AF_INET,SOCK_DGRAM,0)) == -1)
{
printf("ERROR: Failed to obtain Socket Descriptor!n");
return (0);
}
printf("2 ");
printf("3 ");
addr_remote.sin_family = AF_INET; // Protocol Family
addr_remote.sin_port = htons(PORT); // Port number
inet_pton(AF_INET, argv[1], &addr_remote.sin_addr); // Net Address
bzero(&(addr_remote.sin_zero), 8); // Flush the rest of struct
j=0;
printf("4 ");
while(j
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define PORT 5000
int main(int argc,char *argv[])
{
int sockfd;
struct sockaddr_in addr_remote;
char end[]="send overn";
int i;
int j;
int rn;
int sin_size=sizeof(struct sockaddr_in);
char name[128]={0};
rn=0;
i=0;
printf("1 ");
if (argc != 2)
{
printf ("Usage: talker HOST IP (ex: ./talker 192.168.0.94).n");
}
if ((sockfd = socket(AF_INET,SOCK_DGRAM,0)) == -1)
{
printf("ERROR: Failed to obtain Socket Descriptor!n");
return (0);
}
printf("2 ");
printf("3 ");
addr_remote.sin_family = AF_INET; // Protocol Family
addr_remote.sin_port = htons(PORT); // Port number
inet_pton(AF_INET, argv[1], &addr_remote.sin_addr); // Net Address
bzero(&(addr_remote.sin_zero), 8); // Flush the rest of struct
j=0;
printf("4 ");
while(j