Open62541 Building a Simple Server

Hi astyle,

here is the original function

Code:
static UA_StatusCode
UA_PubSubChannelUDPMC_unregist(UA_PubSubChannel *channel, UA_ExtensionObject *transportSettings) {
    if(!(channel->state == UA_PUBSUB_CHANNEL_PUB_SUB || channel->state == UA_PUBSUB_CHANNEL_SUB)){
        UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "PubSub Connection unregist failed.");
        return UA_STATUSCODE_BADINTERNALERROR;
    }
    UA_PubSubChannelDataUDPMC * connectionConfig = (UA_PubSubChannelDataUDPMC *) channel->handle;
    if(connectionConfig->ai_family == PF_INET){//IPv4 handling
        struct ip_mreq groupV4 = { 0 };

        memcpy(&groupV4.imr_multiaddr,
               &((const struct sockaddr_in *) &connectionConfig->ai_addr)->sin_addr,
               sizeof(struct in_addr));
        groupV4.imr_interface.s_addr = UA_htonl(INADDR_ANY);

        if(UA_setsockopt(channel->sockfd, IPPROTO_IP, IP_DROP_MEMBERSHIP,
                         (char *) &groupV4, sizeof(groupV4)) != 0){
            UA_LOG_SOCKET_ERRNO_WRAP(
                UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_NETWORK,
                             "PubSub Connection unregist failed. IP membership setup failed: "
                             "Cannot set socket option IP_DROP_MEMBERSHIP. Error: %s",
                             errno_str));
            return UA_STATUSCODE_BADINTERNALERROR;
        }
#if UA_IPV6
    } else if (connectionConfig->ai_family == PF_INET6) {//IPv6 handling
        struct ipv6_mreq groupV6 = { 0 };

        memcpy(&groupV6.ipv6mr_multiaddr,
               &((const struct sockaddr_in6 *) &connectionConfig->ai_addr)->sin6_addr,
               sizeof(struct in6_addr));

        if(UA_setsockopt(channel->sockfd, IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP,
                         (char *) &groupV6, sizeof(groupV6)) != 0){
            UA_LOG_SOCKET_ERRNO_WRAP(
                UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_NETWORK,
                             "PubSub Connection unregist failed. IP membership setup failed: "
                             "Cannot set socket option IPV6_DROP_MEMBERSHIP. Error: %s",
                             errno_str));
            return UA_STATUSCODE_BADINTERNALERROR;
        }
#endif
    } else {
        UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "PubSub Connection unregist failed.");
        return UA_STATUSCODE_BADINTERNALERROR;
    }
    return UA_STATUSCODE_GOOD;
}

And here is what I changed. Did I do this correctly?

Code:
static UA_StatusCode
UA_PubSubChannelUDPMC_unregist(UA_PubSubChannel *channel, UA_ExtensionObject *transportSettings) {
    if(!(channel->state == UA_PUBSUB_CHANNEL_PUB_SUB || channel->state == UA_PUBSUB_CHANNEL_SUB)){
        UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "PubSub Connection unregist failed.");
        return UA_STATUSCODE_BADINTERNALERROR;
    }
    UA_PubSubChannelDataUDPMC * connectionConfig = (UA_PubSubChannelDataUDPMC *) channel->handle;
    if(connectionConfig->ai_family == PF_INET){//IPv4 handling
        struct ip_mreq groupV4 = { 0 };

        memcpy(&groupV4.imr_multiaddr,
               &((const struct sockaddr_in *) &connectionConfig->ai_addr)->sin_addr,
               sizeof(struct in_addr));
        groupV4.imr_interface.s_addr = UA_htonl(INADDR_ANY);

        if(UA_setsockopt(channel->sockfd, IPPROTO_IP, IP_DROP_MEMBERSHIP,
                         (char *) &groupV4, sizeof(groupV4)) != 0){
            UA_LOG_SOCKET_ERRNO_WRAP(
                UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_NETWORK,
                             "PubSub Connection unregist failed. IP membership setup failed: "
                             "Cannot set socket option IP_DROP_MEMBERSHIP. Error: %s",
                             errno_str));
            return UA_STATUSCODE_BADINTERNALERROR;
        }

    }
#if UA_IPV6
    else if (connectionConfig->ai_family == PF_INET6) {//IPv6 handling
        struct ipv6_mreq groupV6 = { 0 };

        memcpy(&groupV6.ipv6mr_multiaddr,
               &((const struct sockaddr_in6 *) &connectionConfig->ai_addr)->sin6_addr,
               sizeof(struct in6_addr));

        if(UA_setsockopt(channel->sockfd, IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP,
                         (char *) &groupV6, sizeof(groupV6)) != 0){
            UA_LOG_SOCKET_ERRNO_WRAP(
                UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_NETWORK,
                             "PubSub Connection unregist failed. IP membership setup failed: "
                             "Cannot set socket option IPV6_DROP_MEMBERSHIP. Error: %s",
                             errno_str));
            return UA_STATUSCODE_BADINTERNALERROR;
        }

    }
#endif
     else {
        UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "PubSub Connection unregist failed.");
        return UA_STATUSCODE_BADINTERNALERROR;
    }
    return UA_STATUSCODE_GOOD;
}
If that compilation error went away after the correction in source code, that's how you know you did it correctly.
 
If that compilation error went away after the correction in source code, that's how you know you did it correctly.
No the error/s remained the same. Could you provide me with copy of your open6254.c as well as open62541.h
 
No the error/s remained the same. Could you provide me with copy of your open6254.c as well as open62541.h
I just downloaded them from the place that was pointed out earlier in this thread... 😲

For not knowing any better I downloaded these files from the following link https://github.com/open62541/open62541/releases/tag/v1.3.6
And I did not even edit the files, just tried to compile them as per directions, which were also pointed out earlier in this thread.
 
Back
Top