समस्या सी पुस्तकालय को अपग्रेड करके हल किया गया था।सी में getrandom syscall नहीं मिला
मैं (http://man7.org/linux/man-pages/man2/getrandom.2.html)
जीसीसी -5 -std = C11 test.c
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/fcntl.h>
#include <errno.h>
#include <string.h>
#include <signal.h>
#include <linux/random.h>
#include <sys/syscall.h>
int main(void)
{
void *buf = NULL;
size_t l = 5;
unsigned int o = 1;
int r = syscall(SYS_getrandom, buf, l, o);
return 0;
}
या
int main(void)
{
void *buf = NULL;
size_t l = 5;
unsigned int o = 1;
int r = getrandom(buf, l, o);
return 0;
}
वैसे भी जब syscall getrandom उपयोग करना चाहते हैं मैं इसे जीसीसी -5:
के साथ संकलित करने का प्रयास करता हूंtest.c: In function ‘main’:
test.c:14:17: warning: implicit declaration of function ‘getrandom’ [-Wimplicit-function-declaration]
int r = getrandom(buf, l, o);
^
/tmp/ccqFdJAJ.o: In function `main':
test.c:(.text+0x36): undefined reference to `getrandom'
collect2: error: ld returned 1 exit status
मैं उबंटू 14.04 का उपयोग कर रहा हूं, मैं गेट्रैंडम का उपयोग करने के लिए क्या कर सकता हूं? चूंकि यह एक "नया" syscall है, मैं इसका उपयोग कैसे कर सकता हूं?
संपादित करें:
uname -r
-> 4.0.3-040003-generiC#201505131441 SMP Wed May 13 13:43:16 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
जब मैं द्वारा आर की जगह int r = syscall(SYS_getrandom, buf, l, o);
या आर = getrandom (buf, एल, ओ) यह एक ही है ..
अपने संपादन का जिक्र करते हुए: इसका उपयोग करते समय प्रोटोटाइप को 'syscall()' में जोड़ें! यह ' '' SYS_getrandom' में भी उपलब्ध होना चाहिए। –
alk
आप [यादृच्छिक (4)] (http://man7.org/linux/man-pages/man4/random.4.html) का उपयोग क्यों नहीं करते हैं, यानी '/ dev/random' से कुछ बाइट्स पढ़ते हैं? –
नहीं, लेकिन आपको एक बहुत ही नए कर्नेल की आवश्यकता होगी .... –