Mercurial > hg > Members > matac > cbc-ip
changeset 0:d7dfe167f8ee default tip
socket
author | matac <matac@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 10 Oct 2022 12:28:01 +0900 |
parents | |
children | |
files | .hgignore Dockerfile Makefile src/main.cbc |
diffstat | 4 files changed, 100 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Mon Oct 10 12:28:01 2022 +0900 @@ -0,0 +1,2 @@ +.git +a.out
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Dockerfile Mon Oct 10 12:28:01 2022 +0900 @@ -0,0 +1,38 @@ +FROM ubuntu:20.04 + +RUN apt-get update && apt-get upgrade -y +RUN DEBIAN_FRONTEND=noninteractive \ + apt-get install -y \ + mercurial \ + libmpc-dev \ + libgmp-dev \ + libmpfr-dev \ + build-essential \ + flex \ + gdb \ + lldb \ + zsh \ + cmake \ + iproute2 \ + iputils-ping \ + tcpdump \ + telnet \ + traceroute \ + netcat \ + curl \ + vim \ + arping \ + nmap \ + ncat \ + net-tools +RUN hg clone http://www.cr.ie.u-ryukyu.ac.jp/hg/CbC/CbC_gcc/ +RUN mkdir -p /usr/local/cbc_gcc +RUN cd /usr/local/cbc_gcc && \ + sh /CbC_gcc/configure CFLAGS="-g3 -O0" --prefix=/usr/local/cbc_gcc \ + --disable-nls --disable-bootstrap --enable-languages=c \ + --enable-checking=tree,rtl,assert,types --disable-multilib && \ + make -j16 && \ + make install + +ENV PATH=/usr/local/cbc_gcc/bin:$PATH +ENV CBC_COMPILER=/usr/local/cbc_gcc/bin/gcc
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile Mon Oct 10 12:28:01 2022 +0900 @@ -0,0 +1,20 @@ +.PHONY: run +run: + -@podman stop cbc-ip + -@podman rm cbc-ip + podman run --cap-add=all --name cbc-ip \ + -v $(PWD):/cbc-ip \ + -dit \ + localhost/cbc-ip + +.PHONY: exec +exec: + podman exec -it cbc-ip bash + +.PHONY: build +build: + podman build --rm -t localhost/cbc-ip . + +.PHONY: sync +sync: + rsync -avP $(PWD)/src ie-user@10.0.4.74:~/cbc-ip \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main.cbc Mon Oct 10 12:28:01 2022 +0900 @@ -0,0 +1,40 @@ +#include <stdio.h> +#include <stdlib.h> +#include <sys/socket.h> +#include <arpa/inet.h> +#include <linux/if_ether.h> +#include <stdint.h> + +__code raw_socket(int socket, uint8_t *buffer, int len){ + ssize_t n = recv(socket, buffer, len, 0); + + if(n == -1){ + perror("Failed to receive"); + exit(1); + } + if(n != 0){ + printf("Received %lu bytes: ", n); + for(int i = 0; i < n; ++i){ + printf("%02x", buffer[i]); + } + printf("\n"); + } + + goto raw_socket(socket, buffer, len); +} + + +__code raw_socket_init(){ + int sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); + if(sock == -1){ + perror("Failed to open socket"); + exit(1); + } + uint8_t buf[1550]; + + goto raw_socket(sock, buf, sizeof(buf)); +} + +int main(){ + goto raw_socket_init(); +} \ No newline at end of file