Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8511165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:54:46+00:00 2026-06-11T03:54:46+00:00

I want to send a array of data to kernel space , ( i

  • 0

I want to send a array of data to kernel space , ( i have used call back function in my kext)
problem is when i use send function i see something weird that i explain in 2 scenario:
1)
…
char f[]={‘1′,’2′,’3′,’4′,’5′,’6’};
send (sock,f,sizeof(f),0);
well, when i printf what i receive in kext:
123456

2)
…
// i replace f[2] with 0

char f[]={‘1′,’2’,0,’4′,’5′,’6′};
send (sock,f,sizeof(f),0);

but this time, when i printf what i receive in kext:
120000

it seems that send function make zero every byte after first 0 byte?
what is going on? is this a send function bug?
i used xcode 4.1 and i my os is lion
here is user space part:

int main(int argc, char* const*argv)
{
    struct ctl_info ctl_info;
    struct sockaddr_ctl sc;
    char str[MAX_STRING_LEN];
    int sock = socket(PF_SYSTEM, SOCK_DGRAM, SYSPROTO_CONTROL);
    if (sock < 0)
        return -1;
    bzero(&ctl_info, sizeof(struct ctl_info));
    strcpy(ctl_info.ctl_name, "pana.ifmonitor.nke.foo");
    if (ioctl(sock, CTLIOCGINFO, &ctl_info) == -1)
        return -1;
    bzero(&sc, sizeof(struct sockaddr_ctl));
    sc.sc_len = sizeof(struct sockaddr_ctl);
    sc.sc_family = AF_SYSTEM;
    sc.ss_sysaddr = SYSPROTO_CONTROL;
    sc.sc_id = ctl_info.ctl_id;
    sc.sc_unit = 0;
    if (connect(sock, (struct sockaddr *)&sc, sizeof(struct sockaddr_ctl)))
        return -1;


     unsigned char data_send[]={'a','l','i','0','1','2','4','l','i',0,'1','2','4','l','i','0','1'};


    size_t data_recive;
    int j=0;
    char data_rcv[8192];


        send( sock, data_send, 17*sizeof(char), 10 );


        printf("\n");
        sleep(1);


        close(sock);
        return 0;

    }

and this is some part of kernel space code that is responsible for getting user space data:

errno_t EPHandleWrite(kern_ctl_ref ctlref, unsigned int unit, void *userdata,mbuf_t m, int flags)
{

    printf("\n EPHandleWrite called---------------------- \n");
    //char data_rec[50];

    //unsigned char *ptr = (unsigned char*)mbuf_data(m);
    //char ch;
    //mbuf_copydata(m, 0, 50, data_rec);

    //strncpy(&ch, ptr, 1 );


    size_t data_lenght;
    data_lenght = mbuf_pkthdr_len(m);

    char data_receive[data_lenght];
    strncpy( data_receive, ( char * ) mbuf_data(m) , data_lenght );

    printf("data recied %lu\n",data_lenght);

    for(int i=0;i<data_lenght;++i)
    {
        printf("%X ",data_receive[i]);
    }
 return 0
}

well, it print in console:
61 6C 69 30 31 32 34 6C 69 0 0 0 0 0 0 0 0
and when i change send data to:
{'a','l','i','0','1','2','4','l','i',**'0'**,'1','2','4','l','i','0','1'};
i get correct, in fact i get all 0 after first zero byte in send data

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T03:54:47+00:00Added an answer on June 11, 2026 at 3:54 am

    The problem is the strncpy line – if you look at the documentation for strncpy, you’ll notice that it only copies until it reaches a 0 byte, so it’s only suitable for dealing with C strings. If you need to copy arbitrary binary data, use memcpy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an multi-dimensional array that I want to send to a PHP script
Hello Sir i want send list of data to php server i use following
I have the following array: var idParam = [1,2,3]; I want to send this
i have Devxpress GridControl on the form, and i want to send data on
this is the method I want to send data to it function get_lesson($reshte,$poodeman){ $this->load->model('dropdown_model');
I have an array of IP addresses, and I want to send the same
I have Tabview and I want do send data from one to another. Eatch
I have an array that I want to pass to a javascript onclick function.
When performing a getJSON function, and I want to send some data to the
I have a dictionary variable in C# (ASP.NET). I want to send this data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.