Created
June 25, 2013 02:30
-
-
Save Amanieu/5855450 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "native_client/src/shared/imc/nacl_imc_c.h" | |
#include <stdio.h> | |
#include <string.h> | |
#include <errno.h> | |
#define SEL_LDR "tools/sel_ldr_x86_64" | |
#define IRT "tools/irt_core_x86_64.nexe" | |
#define APP "a.nexe" | |
#define NACL_HANDLE_TRANSFER_PROTOCOL 0xd3c0de01 | |
int main(int argc, char** argv) | |
{ | |
NaClHandle pair[2]; | |
printf("Creating sockets\n"); | |
if (NaClSocketPair(pair)) | |
return 1; | |
printf("Forking\n"); | |
if (fork() == 0) { | |
NaClClose(pair[0]); | |
char buffer[100]; | |
sprintf(buffer, "100:%d", pair[1]); | |
execl(SEL_LDR, SEL_LDR, "-B", IRT, "-i", buffer, "--", APP, NULL); | |
} | |
NaClClose(pair[1]); | |
NaClMessageHeader msg; | |
NaClIOVec iov[2]; | |
uint32_t header[4] = {NACL_HANDLE_TRANSFER_PROTOCOL, 0}; | |
char buffer[100] = "Testing!"; | |
memset(&msg, 0, sizeof(msg)); | |
iov[0].base = header; | |
iov[0].length = sizeof(header); | |
iov[1].base = buffer; | |
iov[1].length = sizeof(buffer); | |
msg.iov = iov; | |
msg.iov_length = 2; | |
printf("sent %d\n", NaClSendDatagram(pair[0], &msg, 0)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "native_client/src/shared/imc/nacl_imc_c.h" | |
#include <stdio.h> | |
#include <string.h> | |
int main(int argc, char** argv) | |
{ | |
NaClMessageHeader msg; | |
NaClIOVec iov; | |
char buffer[100] = "ASDF"; | |
memset(&msg, 0, sizeof(msg)); | |
iov.base = buffer; | |
iov.length = sizeof(buffer); | |
msg.iov = &iov; | |
msg.iov_length = 1; | |
int x = NaClReceiveDatagram(100, &msg, 0); | |
char buffer2[100]; | |
NaClGetLastErrorString(buffer2, sizeof(buffer2)); | |
printf("%s %d %s\n", buffer, x, buffer2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment