1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
struct sockaddr_in sin; //1
//struct sockaddr_in *sin; //2
malloc(sizeof(struct sockaddr_in));
//i'll take "error: request for member 'sin_family' in something not a structure or union ", therefore I'll use 2..., but I've got segfalt
sin.sin_family = AF_INET;
//sin->sin_family = AF_INET; //2
//Segmentation fault 2
my_send(socket,buffer,&sin); //1
sent=sendto(sock, buf, buf_siz, 0, (struct sockaddr *) &sin, sizeof(sin));
if(sent < 0) {
perror("sendto");
exit(1);
}
void my_send(int s,const char *buf, const struct sockaddr *addr){
int buflen = strlen(buf);
int sent =0;
sent = sendto(s, buf, buflen, 0, (struct sockaddr *)addr,sizeof(addr));
if(sent<0){
perror("sendto");
exit(1);
}// sendto: invalid argument 1 Without my_send function it's works very well, i think what it because somewhere I did a mistake.
}
|