1

I have tried to create socket in c for DCCP protocol,it complies with out error but when I run the program I get error "sendto: Broken pipe"

I have include the necesseray header definition.

#define SOCK_DCCP 6 #define IPPROTO_DCCP 33 #define SOL_DCCP 269

and in the function where I wanted to create a socket

int dccp_sockfd,port_num,addr_len,yes = 1;

struct sockaddr_in PMU_addr,their_addr;

struct Lower_Layer_Details *temp_pmu = (struct Lower_Layer_Details *) temp;

unsigned char *dccp_BUF,*ptr,length[2];

unsigned int flen;

uint16_t cal_crc,frame_crc;

port_num = temp_pmu->port;

struct Lower_Layer_Details *t ;


if ((dccp_sockfd = socket(AF_INET, SOCK_DCCP, IPPROTO_DCCP)) == -1) {
    perror("socket");
    exit(1);
}

if (setsockopt(dccp_sockfd,SOL_DCCP,SO_REUSEADDR,&yes,sizeof(int)) == -1) {
    perror("setsockopt");
    exit(1); 

dccp_BUF = malloc(MAXBUFLEN* sizeof(unsigned char));

addr_len = sizeof(struct sockaddr); 
int n,bytes_read;
unsigned char *cmdframe = malloc(19);
cmdframe[18] = '\0';
create_command_frame(1,temp_pmu->pmuid,(char *)cmdframe);


if ((n = sendto(dccp_sockfd,cmdframe, 18, 0, (struct sockaddr *)&PMU_addr,sizeof(PMU_addr)) == -1)) {

    perror("sendto"); 

} else {
Steve Schnepp
  • 4,620
  • 5
  • 39
  • 54
  • 1
    Is `IPPROTO_DCCP` or the other macros defined by you? Plus, you should show the code around `sendto` – Yu Hao Jun 09 '13 at 10:17
  • IPPROTO_DCCP and the other macros are defined by the protocol and I have included above the sendto part of the code – user2467971 Jun 09 '13 at 21:34
  • Somebody with 1.5k rep could maybe add the DCCP tag to this question, even though its pretty generic. – thuovila Jun 10 '13 at 07:01

1 Answers1

3

Do you call connect() or bind()and listen()? The current code snippets dont show those. In case those are missing, try adding them. To enable us to help you better, please make the question SSCCE.

In case your platform is Linux, please read http://www.linuxfoundation.org/collaborate/workgroups/networking/dccp especially the section "C Application Programming Interface to DCCP".

thuovila
  • 1,960
  • 13
  • 21