标题:
求救,望各位老虾帮助,关于UDP编程的
[打印本页]
作者:
gongfar
时间:
2005-8-31 21:42
标题:
求救,望各位老虾帮助,关于UDP编程的
将UDP报文分解,加序号,然后发送的。编译时有很多语法错误,望各位老虾指出错误,小弟不胜感激 #include
#include
#include
#include
#include
#include
#include
#include
#define PORT 4321 #define LEN 50 #define MAXLINE 1024 #define NUM 6 int main(int argc,char* argv) { int socketfd; struct sockaddr_in addr; bzero(&addr,siziof(addr)); addr_sin_family = AF_INET; addr.sin_port=htons(PORT); inet_pton(AF_INET,argv[1],&addr,sin_addr); if((sockfd=socket(AF_INET,SOCK_DGRAM,0))<0) { perror("socket error"); exit(1); } dg_porta(stdlin, sockfd, (struct sockaddr *)&addr, sizeof(addr)); exit(0); } void dg_porta(FILE *fp, int sockfd, (const struct sockaddr)*paddr, socklen_t len ) { char sendline[MAXLINE]; int n; while(fgets(sendline,MAXLINE,fp)!=NULL) { n= strlen (sendline); if(n<=LEN) sendto(sockfd, sendline, n, 0, paddr, len )); else { printf("the buffer is lager,fragment is needed\n"); fragment(sendline, sockfd, (const struct sockaddr)*paddr, socklen_t len ); } } } void fragment(char* pBuffer, int fd,(const struct sockaddr)*paddr, socklen_t len ) { unsigned char aa[NUM-1]; memset((void*) aa, 0X00, sizeof(unsigned char)*6); char gp[LEN]; char* data; while(pBuffer) { int j=0; bzero(data,sizeof(data)); unsigned char or=sequence(aa); unsigned char order=htons(or); strcpy(data[j],oder); for(pBuffer,i=0; i
, sizeof(pdata), 0, (const struct sockaddr)*paddr, socklen_t len ); } void not_order(char* pdata, int m, int fd, (const struct sockaddr)*psddr, socklent_t len) { randomize(); for(int i=0; i
作者:
风灵风之子
时间:
2005-8-31 23:46
标题:
求救,望各位老虾帮助,关于UDP编程的
一看头文件就是linux下的
你用gcc试试。。
欢迎光临 黑色海岸线论坛 (http://bbs.thysea.com/)
Powered by Discuz! 7.2