You are not logged in.
Pages: 1
Dear All
I have a program to generate UDP IPv6 packet.
It works on Redhat 9 (gcc3.2.2) but is not working on Fedora core 5 (gcc 4.1)
I think the problem is in "Sendto()" but i dont know how to rectify it.
Any suggestion or help will be very appreciated.
here's the program:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/select.h>
#include <sys/time.h>
int main(int argc, char **argv)
{
int pkt_size, pkt_interval_msec;
struct sockaddr_in6 a;
int s;
int ser_num;
if (argc != 5) {
fprintf(stderr, "usage: unicast_gen pkt_size
pkt_interval_msec addr udp_port\n");
exit(-1);
}
pkt_size = atoi(argv[1]);
if (pkt_size < 20 || pkt_size > 1400) {
fprintf(stderr, "packet size must be at least 20 bytes, and
at most 1400 bytes!\n");
exit(-1);
}
pkt_interval_msec = atoi(argv[2]);
if (pkt_interval_msec <= 0) {
fprintf(stderr, "packet interval must be greater than 0!\n");
exit(-1);
}
s = socket(AF_INET6, SOCK_DGRAM, 0);
if (s < 0) {
perror("socket");
exit(-1);
}
// filling sendto address struct
memset(&a, 0, sizeof(a));
a.sin6_port = htons(atoi(argv[4]));
if (inet_pton(AF_INET6, argv[3], a.sin6_addr.s6_addr) <= 0) {
perror("inet_pton");
exit(-1);
}
for (ser_num = 0; ; ser_num++) {
struct timeval t, now;
char buffer[1400];
t.tv_sec = pkt_interval_msec / 1000;
t.tv_usec = (pkt_interval_msec * 1000) % 1000000;
//Put serial no and current time as payload in every packet
gettimeofday(&now, NULL);
memset(buffer, 0, 1400);
sprintf(buffer, "%d", ser_num);
sprintf(buffer+8, "%ld.%06ld", now.tv_sec, now.tv_usec);
if (sendto(s,buffer,1400,0,(struct sockaddr*)&a,sizeof(a))==-1)
{
fprintf(stderr, "Couldn't send packet\n");
}
// wait pkt_interval time beofre sending next packet
select(0, NULL, NULL, NULL, &t);
}
}
Thanks in Advance
A.Mehdizadeh
Offline
Offline
Offline
Oh, man, it took me forever to find that trivial little mistake! I can't believe it didn't
smack me in the face immediately! You forgot one important line:
a.sin6_family = AF_INET6;
So, your sockaddr was marked as AF_UNSPEC, which is why it thought there was
no address specified... If it worked on previous systems, then you were just lucky,
and they were a bit sloppy... In any case, it would've been a kernel change that bit
you, not anything GCC-related...
Offline
Hi Robseace
Thanks alot :smile: , you were right.
I added that line, now is working.
I really appreciate your help and guide from i3839.
Regards
A.Mehdizadeh
Offline
Hi Guys,
Also found similar bug in my case while using busybox-1.17.1.
Great and very helpful to narrow the problem
Regards,
Punith Kumar
Offline
Pages: 1