Home > OS >  Kernel netlink layer from the user to receive 24 ~ 27 character strings, unknown characters will be
Kernel netlink layer from the user to receive 24 ~ 27 character strings, unknown characters will be

Time:09-17

Function: it is through a simple netlink will send layer sends data to the user the kernel to receive
Problem phenomenon, such as title

Look at the code, and then look at my console output will be more understand
User layer of the core code is the following two sentences,
 
Memcpy (NLMSG_DATA (NLH), compelte_cmd, strlen (compelte_cmd));
Ret=sendto (SKFD, NLH, NLH - & gt; Nlmsg_len, 0, (struct sockaddr *) & amp; Daddr, sizeof (struct sockaddr_nl));

The kernel layer, from netlink receiving user layer sends data core code:
 
NLH=nlmsg_hdr (SKB);
Umsg=NLMSG_DATA (NLH);
If (umsg) {
Len=strlen (umsg);
Printk (KERN_EMERG "len=% d \ n", strlen (umsg));
Printk (KERN_EMERG "kernel recv the from user:] [% s \ n", umsg);

//here to find out the received what strange character, do the following processing (that is, from the end of the string in turn reducing characters)
Umsg] [len - 1=0;
Printk (KERN_EMERG "len=% d \ n", strlen (umsg));
Printk (KERN_EMERG "kernel recv the from user:] [% s \ n", umsg);

Umsg [len - 2]=0;
Printk (KERN_EMERG "len=% d \ n", strlen (umsg));
Printk (KERN_EMERG "kernel recv the from user:] [% s \ n", umsg);

Umsg [len - 3]=0;
Printk (KERN_EMERG "len=% d \ n", strlen (umsg));
Printk (KERN_EMERG "kernel recv the from user:] [% s \ n", umsg);

Umsg [len - 4]=0;
Printk (KERN_EMERG "len=% d \ n", strlen (umsg));
Printk (KERN_EMERG "kernel recv the from user:] [% s \ n", umsg);

Umsg [len - 5]=0;
Printk (KERN_EMERG "len=% d \ n", strlen (umsg));
Printk (KERN_EMERG "kernel recv the from user:] [% s \ n", umsg);

Umsg [len - 6]=0;
Printk (KERN_EMERG "len=% d \ n", strlen (umsg));
Printk (KERN_EMERG "kernel recv the from user:] [% s \ n", umsg);

Umsg [len - 7)=0;
Printk (KERN_EMERG "len=% d \ n", strlen (umsg));
Printk (KERN_EMERG "kernel recv the from user:] [% s \ n", umsg);

Umsg [len - 8]=0;
Printk (KERN_EMERG "len=% d \ n", strlen (umsg));
Printk (KERN_EMERG "kernel recv the from user:] [% s \ n", umsg);
}

So, under normal circumstances the user layer character input will be the kernel complete capture:
([swconfig dev switch0 get] is my user layer trigger command, this can need not care about, what is important is the number after the parameters, as well as the debugging information)
Transmission of 20 characters:
 
Root @ Ruijie: ~ # swconfig dev switch0 get 12345678901234567890
[52.130000] len=20
[52.130000] kernel recv the from user: [12345678901234567890]
[52.140000] len=19
[52.140000] kernel recv the from user: [1234567890123456789]
Len=18 [52.150000]
[52.150000] kernel recv the from user: [123456789012345678]
[52.150000] len=17
[52.160000] kernel recv the from user: [12345678901234567]
[52.160000] len=16
[52.160000] kernel recv the from user: [1234567890123456]
[52.170000] len=15
[52.170000] kernel recv the from user: [123456789012345]
[52.180000] len=
[52.180000] kernel recv the from user: [12345678901234]
[52.180000] len=13
[52.190000] kernel recv the from user: [1234567890123]
Len=12 [52.190000]
[52.190000] kernel recv the from user: [123456789012]
Recvfrom...
Recv len: 0

Root @ Ruijie: ~ #

More than 20 characters without exception,
Now look at the transmission of 24 characters:
 
Root @ Ruijie: ~ # swconfig dev switch0 get 123456789012345678901234
Len=28 [543.140000]//& lt; - note here!!!!! Clearly parameters only 24 characters to identify 28 characters here?? Output and the situation is very strange, don't know at the end of the string with something, did not even the right parenthesis'], isn't me typesetting messed up, but the output is such!
[543.140000] kernel recv the from user: [123456789012345678901234 

27 [543.150000] len=
[543.150000] kernel recv the from user: [123456789012345678901234 
[543.160000] len=
[543.160000] kernel recv the from user: [123456789012345678901234  [543.160000] len=25
[543.170000] kernel recv the from user: [123456789012345678901234 ]
[543.170000] len=24
[543.180000] kernel recv the from user: [123456789012345678901234]//& lt; - until removed by only 24 characters, the end of the string of unknown characters disappeared, the output is back to normal, really don't understand
[543.180000] len=
[543.180000] kernel recv the from user: [12345678901234567890123]
[543.190000] len=22
[543.190000] kernel recv the from user: [1234567890123456789012]
Len=21 [543.200000]
[543.200000] kernel recv the from user: [123456789012345678901]
[543.210000] len=20
[543.210000] kernel recv the from user: [12345678901234567890]
Recvfrom...
Recv len: 0

Root @ Ruijie: ~ #

Phenomenon above only in the string length is 24 ~ 27 (including 24, 27) will appear, when more than 27 characters are not have this kind of strange phenomenon when
Look at the transmission 28 characters:
 
Root @ Ruijie: ~ # swconfig dev switch0 get 1234567890123456789012345678
[1599.520000] len=
[1599.530000] kernel recv the from user: [1234567890123456789012345678]
27 [1599.530000] len=
[1599.540000] kernel recv the from user: [123456789012345678901234567]
[1599.540000] len=
[1599.540000] kernel recv the from user: [12345678901234567890123456]
[1599.550000] len=25
[1599.550000] kernel recv the from user: [1234567890123456789012345]
[1599.560000] len=24
[1599.560000] kernel recv the from user: [123456789012345678901234]
[1599.570000] len=
[1599.570000] kernel recv the from user: [12345678901234567890123]
[1599.580000] len=22
[1599.580000] kernel recv the from user: [1234567890123456789012]
Len=21 [1599.580000]
[1599.590000] kernel recv the from user: [123456789012345678901]
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related