DCCP Socket programming in C

1.9k Views Asked by At

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 {
1

There are 1 best solutions below

1
On

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".