Hi,

I was trying to generate a simple broadcasting message in sel4. I have used a c code I found in the internet.

#include <stdio.h>     
#include <sys/socket.h> 
#include <arpa/inet.h>  
#include <stdlib.h>    
#include <string.h>    
#include <unistd.h> 

void DieWithError(char *errorMessage)
{
    perror(errorMessage);
    exit(1);
}



int main(int argc, char *argv[]) {

    int sock;                        
    struct sockaddr_in broadcastAddr;
    char *broadcastIP;                
    unsigned short broadcastPort;    
    char *sendString;                
    int broadcastPermission;        
    unsigned int sendStringLen;      

    broadcastIP = "0.0.0.0";          
    broadcastPort = 6741;    
    sendString = "Hello World!";
    printf("start\n");

    printf("Socket is about to be created!\n");
    if ( (sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0 ) {
        perror("socket creation failed");
        exit(EXIT_FAILURE);
    }
    printf("Socket is created! \n");

    broadcastPermission = 1;
    if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (void *) &broadcastPermission,
          sizeof(broadcastPermission)) < 0)
        DieWithError("setsockopt() failed");

    memset(&broadcastAddr, 0, sizeof(broadcastAddr));  
    broadcastAddr.sin_family = AF_INET;                
    broadcastAddr.sin_addr.s_addr = inet_addr(broadcastIP);
    broadcastAddr.sin_port = htons(broadcastPort);        

    sendStringLen = strlen(sendString);

for (;;)
    {
         if (sendto(sock, sendString, sendStringLen, 0, (struct sockaddr *)
               &broadcastAddr, sizeof(broadcastAddr)) != sendStringLen)
             DieWithError("sendto() sent a different number of bytes than expected");

        sleep(3);  
    }

   return 0;
}

However, I get the error in syscall 41. What I understood is that for some reason the socket
is not created successfully and can't find an endpoint. What can be the reason for that?


libsel4muslcsys: Error attempting syscall 41
Caught cap fault in send phase at address (nil)
while trying to handle:
vm fault on data at address 0x28 with status 0x4
in thread 0xffffff801fe09400 "rootserver" at address 0x40e3af
With stack:
0x41ce28: 0x40c0fe
0x41ce30: 0x418720
0x41ce38: 0x0
0x41ce40: 0x41ceb0
0x41ce48: 0x0
0x41ce50: 0x0
0x41ce58: 0x4011bd
0x41ce60: 0x41cf10
0x41ce68: 0x200402323
0x41ce70: 0x3
0x41ce78: 0x3
0x41ce80: 0x41ceb0
0x41ce88: 0x401ce2
0x41ce90: 0xffffffff00000000
0x41ce98: 0x412008
0x41cea0: 0x1a5500000041cf20
Thanks!
--

Regards'

Shahnewaz Karim Sakib