- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
as a newbie with nios II, I am trying to create an application which is capable of receiving UDP-packages. So far it did not work yet. Could anyone give me tips on how to do this. My collegue wrote an application in Delphi which is able to send and receive UDP-packets. He sends them to port 666. I would like to receive these packages and show them in the console. Could anyone help me out or send me an example? I am working with NIOS II IDE 5.0 Thanks in advance... Cheers, DannyLink Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
here is:
# include <sys/types.h># include <sys/socket.h># include <arpa/inet.h># include <stdio.h> int main(int argc, char **argv) { struct sockaddr_in peeraddr, /*IP and socke port*/ localaddr;/*local socket address*/ int sockfd; char recmsg[BUFLEN+1]; int socklen, n; if(argc!=5){ printf("%s <dest IP address> <dest port> <source IP address> <source port>\n", argv [0]); exit(0); } sockfd = socket(AF_INET, SOCK_DGRAM, 0); if(sockfd<0){ printf("socket creating err in udptalk\n"); exit(1); } socklen = sizeof(struct sockaddr_in); memset(&peeraddr, 0, socklen); peeraddr.sin_family=AF_INET; peeraddr.sin_port=htons(atoi(argv[2])); if(inet_pton(AF_INET, argv[1], &peeraddr.sin_addr)<=0){ printf("Wrong dest IP address!\n"); exit(0); } memset(&localaddr, 0, socklen); localaddr.sin_family=AF_INET; if(inet_pton(AF_INET, argv[3], &localaddr.sin_addr)<=0){ printf("Wrong source IP address!\n"); exit(0); } localaddr.sin_port=htons(atoi(argv[4])); if(bind(sockfd, &localaddr, socklen)<0){ printf("bind local address err in udptalk!\n"); exit(2); } if(fgets(recmsg, BUFLEN, stdin) == NULL) exit(0); if(sendto(sockfd, recmsg, strlen(recmsg), 0, &peeraddr, socklen)<0){ printf("sendto err in udptalk!\n"); exit(3); } for(;;){ /*recv&send message loop*/ n = recvfrom(sockfd, recmsg, BUFLEN, 0, &peeraddr, &socklen); if(n<0){ printf("recvfrom err in udptalk!\n"); exit(4); }else{ recmsg[n]=0; printf("peer:%s", recmsg); } if(fgets(recmsg, BUFLEN, stdin) == NULL) exit(0); if(sendto(sockfd, recmsg, strlen(recmsg), 0, &peeraddr, socklen)<0){ printf("sendto err in udptalk!\n"); exit(3); } } } os: uclinux ,- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Asaa,
thank you for your help, but unfortunately my boss doesn't want to use an OS, so I need one for the stand-alone lwip.... Cheers, Danny- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hi asaa and dannyjacobs,
Could you left you email?thanks
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page